This is an automated email from the ASF dual-hosted git repository.

yihua pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new feb82e61a06 [HUDI-7686] Add tests on the util methods for type cast of 
configuration instances (#11121)
feb82e61a06 is described below

commit feb82e61a06024ddf1efdcad184f2da6e705062a
Author: Y Ethan Guo <ethan.guoyi...@gmail.com>
AuthorDate: Thu May 2 20:55:00 2024 -0700

    [HUDI-7686] Add tests on the util methods for type cast of configuration 
instances (#11121)
---
 .../io/storage/BaseTestStorageConfiguration.java   | 29 ++++++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git 
a/hudi-io/src/test/java/org/apache/hudi/io/storage/BaseTestStorageConfiguration.java
 
b/hudi-io/src/test/java/org/apache/hudi/io/storage/BaseTestStorageConfiguration.java
index 1d6a3d338e4..3bc575e3dff 100644
--- 
a/hudi-io/src/test/java/org/apache/hudi/io/storage/BaseTestStorageConfiguration.java
+++ 
b/hudi-io/src/test/java/org/apache/hudi/io/storage/BaseTestStorageConfiguration.java
@@ -37,6 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNotSame;
 import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
@@ -71,13 +72,31 @@ public abstract class BaseTestStorageConfiguration<T> {
 
   @Test
   public void testConstructorNewInstanceUnwrapCopy() {
-    T conf = getConf(EMPTY_MAP);
+    T conf = getConf(prepareConfigs());
     StorageConfiguration<T> storageConf = getStorageConfiguration(conf);
     StorageConfiguration<T> newStorageConf = storageConf.newInstance();
-    assertNotSame(storageConf, newStorageConf);
-    assertNotSame(storageConf.unwrap(), newStorageConf.unwrap());
-    assertSame(storageConf.unwrap(), storageConf.unwrap());
-    assertNotSame(storageConf.unwrap(), storageConf.unwrapCopy());
+    Class unwrapperConfClass = storageConf.unwrap().getClass();
+    assertNotSame(storageConf, newStorageConf,
+        "storageConf.newInstance() should return a different 
StorageConfiguration instance.");
+    validateConfigs(newStorageConf);
+    assertNotSame(storageConf.unwrap(), newStorageConf.unwrap(),
+        "storageConf.newInstance() should contain a new copy of the underlying 
configuration instance.");
+    assertSame(storageConf.unwrap(), storageConf.unwrap(),
+        "storageConf.unwrap() should return the same underlying configuration 
instance.");
+    assertSame(storageConf.unwrap(), storageConf.unwrapAs(unwrapperConfClass),
+        "storageConf.unwrapAs(unwrapperConfClass) should return the same 
underlying configuration instance.");
+    assertNotSame(storageConf.unwrap(), storageConf.unwrapCopy(),
+        "storageConf.unwrapCopy() should return a new copy of the underlying 
configuration instance.");
+    validateConfigs(getStorageConfiguration(storageConf.unwrapCopy()));
+    assertNotSame(storageConf.unwrap(), 
storageConf.unwrapCopyAs(unwrapperConfClass),
+        "storageConf.unwrapCopyAs(unwrapperConfClass) should return a new copy 
of the underlying configuration instance.");
+    validateConfigs(getStorageConfiguration((T) 
storageConf.unwrapCopyAs(unwrapperConfClass)));
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> storageConf.unwrapAs(Integer.class));
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> storageConf.unwrapCopyAs(Integer.class));
   }
 
   @Test

Reply via email to