This is an automated email from the ASF dual-hosted git repository. chaokunyang pushed a commit to branch releases-0.10 in repository https://gitbox.apache.org/repos/asf/fury.git
commit 901501ac81db68551517da4c02f65fe39419548c Author: hn <[email protected]> AuthorDate: Wed Jan 29 11:33:56 2025 +0800 feat(java): Add basicMultiConfigFury dataprovider and add basic map unit test use the dataProvider (#2032) #2031 <!-- **Thanks #1938 contributing to Fury.** **If this is your first time opening a PR on fury, you can refer to [CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).** Contribution Checklist - The **Apache Fury (incubating)** community has restrictions on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md). - Fury has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here. --> ## What does this PR do? <!-- Describe the purpose of this PR. --> ## Related issues <!-- Is there any related issue? Please attach here. - #xxxx0 - #xxxx1 - #xxxx2 --> ## Does this PR introduce any user-facing change? <!-- If any user-facing interface changes, please [open an issue](https://github.com/apache/fury/issues/new/choose) describing the need to do so and update the document if necessary. --> - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark <!-- When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here. --> --------- Co-authored-by: hening <[email protected]> Co-authored-by: Shawn Yang <[email protected]> --- .../test/java/org/apache/fury/FuryTestBase.java | 15 +++ .../serializer/collection/MapSerializersTest.java | 129 +++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/java/fury-core/src/test/java/org/apache/fury/FuryTestBase.java b/java/fury-core/src/test/java/org/apache/fury/FuryTestBase.java index f19038f1..57b2e691 100644 --- a/java/fury-core/src/test/java/org/apache/fury/FuryTestBase.java +++ b/java/fury-core/src/test/java/org/apache/fury/FuryTestBase.java @@ -19,6 +19,8 @@ package org.apache.fury; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -245,6 +247,19 @@ public abstract class FuryTestBase { }; } + @DataProvider + public static Object[][] basicMultiConfigFury() { + return Sets.cartesianProduct( + ImmutableSet.of(true, false), // trackingRef + ImmutableSet.of(true, false), // codeGen + ImmutableSet.of(true, false), // scoped meta share + ImmutableSet.of( + CompatibleMode.COMPATIBLE, CompatibleMode.SCHEMA_CONSISTENT)) // CompatibleMode + .stream() + .map(List::toArray) + .toArray(Object[][]::new); + } + public static void serDeCheckSerializerAndEqual(Fury fury, Object obj, String classRegex) { Assert.assertEquals(serDeCheckSerializer(fury, obj, classRegex), obj); } diff --git a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java index 2a291707..a7cd8965 100644 --- a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java +++ b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java @@ -49,6 +49,7 @@ import org.apache.fury.Fury; import org.apache.fury.FuryTestBase; import org.apache.fury.collection.LazyMap; import org.apache.fury.collection.MapEntry; +import org.apache.fury.config.CompatibleMode; import org.apache.fury.config.Language; import org.apache.fury.reflect.TypeRef; import org.apache.fury.serializer.Serializer; @@ -62,6 +63,134 @@ import org.testng.annotations.Test; public class MapSerializersTest extends FuryTestBase { + @Test(dataProvider = "basicMultiConfigFury") + public void basicTestCaseWithMultiConfig( + boolean trackingRef, + boolean codeGen, + boolean scopedMetaShare, + CompatibleMode compatibleMode) { + Fury fury = + Fury.builder() + .withLanguage(Language.JAVA) + .withRefTracking(trackingRef) + .requireClassRegistration(false) + .withCodegen(codeGen) + .withCompatibleMode(compatibleMode) + .withScopedMetaShare(scopedMetaShare) + .build(); + + // testBasicMap + Map<String, Integer> data = new HashMap<>(ImmutableMap.of("a", 1, "b", 2)); + serDeCheckSerializer(fury, data, "HashMap"); + serDeCheckSerializer(fury, new LinkedHashMap<>(data), "LinkedHashMap"); + + // testBasicMapNested + Map<String, Integer> data0 = new HashMap<>(ImmutableMap.of("a", 1, "b", 2)); + Map<String, Map<String, Integer>> nestedMap = ofHashMap("k1", data0, "k2", data0); + serDeCheckSerializer(fury, nestedMap, "HashMap"); + serDeCheckSerializer(fury, new LinkedHashMap<>(nestedMap), "LinkedHashMap"); + + // testMapGenerics + byte[] bytes1 = fury.serialize(data); + fury.getGenerics().pushGenericType(GenericType.build(new TypeRef<Map<String, Integer>>() {})); + byte[] bytes2 = fury.serialize(data); + Assert.assertTrue(bytes1.length > bytes2.length); + fury.getGenerics().popGenericType(); + Assert.assertThrows(RuntimeException.class, () -> fury.deserialize(bytes2)); + + // testSortedMap + Map<String, Integer> treeMap = new TreeMap<>(ImmutableMap.of("a", 1, "b", 2)); + serDeCheckSerializer(fury, treeMap, "SortedMap"); + byte[] sortMapBytes1 = fury.serialize(treeMap); + fury.getGenerics().pushGenericType(GenericType.build(new TypeRef<Map<String, Integer>>() {})); + byte[] sortMapBytes2 = fury.serialize(treeMap); + Assert.assertTrue(sortMapBytes1.length > sortMapBytes2.length); + fury.getGenerics().popGenericType(); + Assert.assertThrows(RuntimeException.class, () -> fury.deserialize(sortMapBytes2)); + + // testTreeMap + TreeMap<String, String> map = + new TreeMap<>( + (Comparator<? super String> & Serializable) + (s1, s2) -> { + int delta = s1.length() - s2.length(); + if (delta == 0) { + return s1.compareTo(s2); + } else { + return delta; + } + }); + map.put("str1", "1"); + map.put("str2", "1"); + assertEquals(map, serDe(fury, map)); + BeanForMap beanForMap = new BeanForMap(); + assertEquals(beanForMap, serDe(fury, beanForMap)); + + // testEmptyMap + serDeCheckSerializer(fury, Collections.EMPTY_MAP, "EmptyMapSerializer"); + serDeCheckSerializer(fury, Collections.emptySortedMap(), "EmptySortedMap"); + + // testSingletonMap + serDeCheckSerializer(fury, Collections.singletonMap("k", 1), "SingletonMap"); + + // testConcurrentMap + serDeCheckSerializer(fury, new ConcurrentHashMap<>(data), "ConcurrentHashMap"); + serDeCheckSerializer(fury, new ConcurrentSkipListMap<>(data), "ConcurrentSkipListMap"); + + // testEnumMap + EnumMap<TestEnum, Object> enumMap = new EnumMap<>(TestEnum.class); + enumMap.put(TestEnum.A, 1); + enumMap.put(TestEnum.B, "str"); + serDe(fury, enumMap); + Assert.assertEquals( + fury.getClassResolver().getSerializerClass(enumMap.getClass()), + MapSerializers.EnumMapSerializer.class); + + // testNoArgConstructor + Map<String, Integer> map1 = newInnerMap(); + Assert.assertEquals(jdkDeserialize(jdkSerialize(map1)), map1); + serDeCheck(fury, map1); + + // testMapFieldSerializers + MapFields obj = createMapFieldsObject(); + Assert.assertEquals(serDe(fury, obj), obj); + + // testBigMapFieldSerializers + final MapFields mapFieldsObject = createBigMapFieldsObject(); + serDeCheck(fury, mapFieldsObject); + + // testObjectKeyValueChunk + final Map<Object, Object> differentKeyAndValueTypeMap = createDifferentKeyAndValueTypeMap(); + final Serializer<? extends Map> serializer = + fury.getSerializer(differentKeyAndValueTypeMap.getClass()); + MapSerializers.HashMapSerializer mapSerializer = (MapSerializers.HashMapSerializer) serializer; + serDeCheck(fury, differentKeyAndValueTypeMap); + + // testObjectKeyValueBigChunk + for (int i = 0; i < 3000; i++) { + differentKeyAndValueTypeMap.put("k" + i, i); + } + serDeCheck(fury, differentKeyAndValueTypeMap); + + // testMapChunkRefTracking + Map<String, Integer> map2 = new HashMap<>(); + for (int i = 0; i < 1; i++) { + map2.put("k" + i, i); + } + Object v = ofArrayList(map2, ofHashMap("k1", map2, "k2", new HashMap<>(map2), "k3", map2)); + serDeCheck(fury, v); + + // testMapChunkRefTrackingGenerics + MapFields obj1 = new MapFields(); + Map<String, Integer> map3 = new HashMap<>(); + for (int i = 0; i < 1; i++) { + map3.put("k" + i, i); + } + obj.map = map3; + obj.mapKeyFinal = ofHashMap("k1", map3); + serDeCheck(fury, obj1); + } + @Test(dataProvider = "referenceTrackingConfig") public void testBasicMap(boolean referenceTrackingConfig) { Fury fury = --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
