This is an automated email from the ASF dual-hosted git repository. amashenkov pushed a commit to branch ignite-13618 in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 143fcc227c3532c704fe2295c7ad75bced93daa1 Author: Andrew Mashenkov <andrey.mashen...@gmail.com> AuthorDate: Thu Nov 19 13:51:54 2020 +0300 WIP. Drop junit4 dependency. --- modules/commons/pom.xml | 25 +- .../ignite/internal/schema/SchemaTestSuite.java | 41 --- .../schema/marshaller/JavaSerializerTest.java | 344 +++++++++++---------- 3 files changed, 207 insertions(+), 203 deletions(-) diff --git a/modules/commons/pom.xml b/modules/commons/pom.xml index 9308376..472e960 100644 --- a/modules/commons/pom.xml +++ b/modules/commons/pom.xml @@ -34,6 +34,8 @@ <!-- Dependencies versions --> <jetbrains.annotations.version>20.1.0</jetbrains.annotations.version> + <jetbrains.annotations.version>20.1.0</jetbrains.annotations.version> + <janino.version>3.0.11</janino.version> <junit.jupiter.version>5.7.0</junit.jupiter.version> <junit.platform.version>1.7.0</junit.platform.version> <mockito.version>1.10.19</mockito.version> @@ -41,7 +43,7 @@ <!-- Maven plugins versions. --> <apache.rat.plugin.version>0.13</apache.rat.plugin.version> <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version> - <maven.surefire.plugin.version>3.0.0-M4</maven.surefire.plugin.version> + <maven.surefire.plugin.version>3.0.0-M5</maven.surefire.plugin.version> <maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version> <checkstyle.puppycrawl.version>8.37</checkstyle.puppycrawl.version> </properties> @@ -152,18 +154,24 @@ <version>${jetbrains.annotations.version}</version> </dependency> + <dependency> + <groupId>org.codehaus.janino</groupId> + <artifactId>janino</artifactId> + <version>${janino.version}</version> + </dependency> + <!-- Test dependencies. --> <!--JUnit 5--> <dependency> <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-engine</artifactId> + <artifactId>junit-jupiter-api</artifactId> <version>${junit.jupiter.version}</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.junit.platform</groupId> - <artifactId>junit-platform-runner</artifactId> - <version>${junit.platform.version}</version> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <version>${junit.jupiter.version}</version> <scope>test</scope> </dependency> @@ -191,6 +199,13 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${maven.surefire.plugin.version}</version> + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>${junit.jupiter.version}</version> + </dependency> + </dependencies> </plugin> </plugins> </build> diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestSuite.java b/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestSuite.java deleted file mode 100644 index 0b64ff2..0000000 --- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestSuite.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.schema; - -import org.apache.ignite.internal.schema.marshaller.FieldAccessorTest; -import org.apache.ignite.internal.schema.marshaller.JavaSerializerTest; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.platform.suite.api.SelectClasses; -import org.junit.runner.RunWith; - -/** - * - */ -@SuppressWarnings("JUnit5Platform") -@RunWith(JUnitPlatform.class) -@SelectClasses({ - JavaSerializerTest.class, - FieldAccessorTest.class, - ExpandableByteBufTest.class, - NativeTypeTest.class, - ColumnTest.class, - ColumnsTest.class, - TupleTest.class -}) -public class SchemaTestSuite { -} diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/marshaller/JavaSerializerTest.java b/modules/commons/src/test/java/org/apache/ignite/internal/schema/marshaller/JavaSerializerTest.java index 53550b5..d20651c 100644 --- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/marshaller/JavaSerializerTest.java +++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/marshaller/JavaSerializerTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Objects; import java.util.Random; import java.util.UUID; +import java.util.stream.Stream; import org.apache.ignite.internal.schema.Bitmask; import org.apache.ignite.internal.schema.Column; import org.apache.ignite.internal.schema.Columns; @@ -31,6 +32,8 @@ import org.apache.ignite.internal.schema.NativeTypeSpec; import org.apache.ignite.internal.schema.SchemaDescriptor; import org.apache.ignite.internal.schema.TestUtils; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DynamicNode; +import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -45,7 +48,10 @@ import static org.apache.ignite.internal.schema.NativeType.STRING; import static org.apache.ignite.internal.schema.NativeType.UUID; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.DynamicContainer.dynamicContainer; +import static org.junit.jupiter.api.DynamicTest.dynamicTest; /** * Serializer test. @@ -77,6 +83,33 @@ public class JavaSerializerTest { /** * */ + @TestFactory + public Stream<DynamicNode> testBasicTypes() { + NativeType[] types = new NativeType[] {BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, UUID, STRING, BYTES, Bitmask.of(5)}; + + return serializerFactoryProvider().stream().map(factory -> + dynamicContainer(factory.getClass().getSimpleName(), + Stream.concat( + // Test pure types. + Stream.of(types).map(type -> + dynamicTest("testBasicTypes(" + type.spec().name() + ')', () -> checkBasicType(factory, type, type)) + ), + + // Test pairs of mixed types. + Stream.of( + dynamicTest("testMixTypes 1", () -> checkBasicType(factory, LONG, INTEGER)), + dynamicTest("testMixTypes 1", () -> checkBasicType(factory, FLOAT, DOUBLE)), + dynamicTest("testMixTypes 1", () -> checkBasicType(factory, INTEGER, BYTES)), + dynamicTest("testMixTypes 1", () -> checkBasicType(factory, STRING, LONG)), + dynamicTest("testMixTypes 1", () -> checkBasicType(factory, Bitmask.of(9), BYTES)) + ) + ) + )); + } + + /** + * + */ @ParameterizedTest @MethodSource("serializerFactoryProvider") public void testBasicTypes(SerializerFactory factory) throws SerializationException { @@ -102,163 +135,160 @@ public class JavaSerializerTest { checkBasicType(factory, Bitmask.of(9), BYTES); } -// /** -// * @throws SerializationException If serialization failed. -// */ -// @ParameterizedTest -// @DisplayName("testComplexType") -// @MethodSource("serializerFactoryProvider") -// public void testComplexType(SerializerFactory factory) throws SerializationException { -// Column[] cols = new Column[] { -// new Column("pByteCol", BYTE, false), -// new Column("pShortCol", SHORT, false), -// new Column("pIntCol", INTEGER, false), -// new Column("pLongCol", LONG, false), -// new Column("pFloatCol", FLOAT, false), -// new Column("pDoubleCol", DOUBLE, false), -// -// new Column("byteCol", BYTE, true), -// new Column("shortCol", SHORT, true), -// new Column("intCol", INTEGER, true), -// new Column("longCol", LONG, true), -// new Column("floatCol", FLOAT, true), -// new Column("doubleCol", DOUBLE, true), -// -// new Column("uuidCol", UUID, true), -// new Column("bitmaskCol", Bitmask.of(42), true), -// new Column("stringCol", STRING, true), -// new Column("bytesCol", BYTES, true), -// }; -// -// SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); -// -// final Object key = TestObject.randomObject(rnd); -// final Object val = TestObject.randomObject(rnd); -// -// Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); -// -// byte[] bytes = serializer.serialize(key, val); -// -// // Try different order. -// Object restoredVal = serializer.deserializeValue(bytes); -// Object restoredKey = serializer.deserializeKey(bytes); -// -// assertTrue(key.getClass().isInstance(restoredKey)); -// assertTrue(val.getClass().isInstance(restoredVal)); -// -// assertEquals(key, restoredKey); -// assertEquals(val, restoredVal); -// } -// -// /** -// * -// */ -// @ParameterizedTest -// @MethodSource("serializerFactoryProvider") -// public void testClassWithIncorrectBitmaskSize(SerializerFactory factory) { -// Column[] cols = new Column[] { -// new Column("pLongCol", LONG, false), -// new Column("bitmaskCol", Bitmask.of(9), true), -// }; -// -// SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); -// -// final Object key = TestObject.randomObject(rnd); -// final Object val = TestObject.randomObject(rnd); -// -// Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); -// -// assertThrows( -// SerializationException.class, -// () -> serializer.serialize(key, val), -// "Failed to write field [name=bitmaskCol]" -// ); -// } -// -// /** -// * -// */ -// @ParameterizedTest -// @DisplayName("testClassWithWrongFieldType") -// @MethodSource("serializerFactoryProvider") -// public void testClassWithWrongFieldType(SerializerFactory factory) throws Exception { -// Column[] cols = new Column[] { -// new Column("bitmaskCol", Bitmask.of(42), true), -// new Column("shortCol", UUID, true) -// }; -// -// SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); -// -// final Object key = TestObject.randomObject(rnd); -// final Object val = TestObject.randomObject(rnd); -// -// Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); -// -// assertThrows( -// SerializationException.class, -// () -> serializer.serialize(key, val), -// "Failed to write field [name=shortCol]" -// ); -// } -// -// /** -// * -// */ -// @ParameterizedTest -// @MethodSource("serializerFactoryProvider") -// public void testClassWithPrivateConstructor(SerializerFactory factory) throws SerializationException { -// Column[] cols = new Column[] { -// new Column("pLongCol", LONG, false), -// }; -// -// SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); -// -// final Object key = PrivateTestObject.randomObject(rnd); -// final Object val = PrivateTestObject.randomObject(rnd); -// -// Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); -// -// byte[] bytes = serializer.serialize(key, val); -// -// Object key1 = serializer.deserializeKey(bytes); -// Object val1 = serializer.deserializeValue(bytes); -// -// assertTrue(key.getClass().isInstance(key1)); -// assertTrue(val.getClass().isInstance(val1)); -// -// assertEquals(key, key); -// assertEquals(val, val1); -// } -// -// /** -// * -// */ -// @ParameterizedTest -// @DisplayName("testClassWithNoDefaultConstructor") -// @MethodSource("serializerFactoryProvider") -// public void testClassWithNoDefaultConstructor(SerializerFactory factory) throws SerializationException { -// Column[] cols = new Column[] { -// new Column("pLongCol", LONG, false), -// }; -// -// SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); -// -// final Object key = WrongTestObject.randomObject(rnd); -// final Object val = WrongTestObject.randomObject(rnd); -// -// Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); -// -// byte[] bytes = serializer.serialize(key, val); -// -// Object key1 = serializer.deserializeKey(bytes); -// Object val1 = serializer.deserializeValue(bytes); -// -// assertTrue(key.getClass().isInstance(key1)); -// assertTrue(val.getClass().isInstance(val1)); -// -// assertEquals(key, key); -// assertEquals(val, val1); -// } + /** + * @throws SerializationException If serialization failed. + */ + @ParameterizedTest + @MethodSource("serializerFactoryProvider") + public void testComplexType(SerializerFactory factory) throws SerializationException { + Column[] cols = new Column[] { + new Column("pByteCol", BYTE, false), + new Column("pShortCol", SHORT, false), + new Column("pIntCol", INTEGER, false), + new Column("pLongCol", LONG, false), + new Column("pFloatCol", FLOAT, false), + new Column("pDoubleCol", DOUBLE, false), + + new Column("byteCol", BYTE, true), + new Column("shortCol", SHORT, true), + new Column("intCol", INTEGER, true), + new Column("longCol", LONG, true), + new Column("floatCol", FLOAT, true), + new Column("doubleCol", DOUBLE, true), + + new Column("uuidCol", UUID, true), + new Column("bitmaskCol", Bitmask.of(42), true), + new Column("stringCol", STRING, true), + new Column("bytesCol", BYTES, true), + }; + + SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); + + final Object key = TestObject.randomObject(rnd); + final Object val = TestObject.randomObject(rnd); + + Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); + + byte[] bytes = serializer.serialize(key, val); + + // Try different order. + Object restoredVal = serializer.deserializeValue(bytes); + Object restoredKey = serializer.deserializeKey(bytes); + + assertTrue(key.getClass().isInstance(restoredKey)); + assertTrue(val.getClass().isInstance(restoredVal)); + + assertEquals(key, restoredKey); + assertEquals(val, restoredVal); + } + + /** + * + */ + @ParameterizedTest + @MethodSource("serializerFactoryProvider") + public void testClassWithIncorrectBitmaskSize(SerializerFactory factory) { + Column[] cols = new Column[] { + new Column("pLongCol", LONG, false), + new Column("bitmaskCol", Bitmask.of(9), true), + }; + + SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); + + final Object key = TestObject.randomObject(rnd); + final Object val = TestObject.randomObject(rnd); + + Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); + + assertThrows( + SerializationException.class, + () -> serializer.serialize(key, val), + "Failed to write field [name=bitmaskCol]" + ); + } + + /** + * + */ + @ParameterizedTest + @MethodSource("serializerFactoryProvider") + public void testClassWithWrongFieldType(SerializerFactory factory) { + Column[] cols = new Column[] { + new Column("bitmaskCol", Bitmask.of(42), true), + new Column("shortCol", UUID, true) + }; + + SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); + + final Object key = TestObject.randomObject(rnd); + final Object val = TestObject.randomObject(rnd); + + Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); + + assertThrows( + SerializationException.class, + () -> serializer.serialize(key, val), + "Failed to write field [name=shortCol]" + ); + } + + /** + * + */ + @ParameterizedTest + @MethodSource("serializerFactoryProvider") + public void testClassWithPrivateConstructor(SerializerFactory factory) throws SerializationException { + Column[] cols = new Column[] { + new Column("pLongCol", LONG, false), + }; + + SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); + + final Object key = PrivateTestObject.randomObject(rnd); + final Object val = PrivateTestObject.randomObject(rnd); + + Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); + + byte[] bytes = serializer.serialize(key, val); + + Object key1 = serializer.deserializeKey(bytes); + Object val1 = serializer.deserializeValue(bytes); + + assertTrue(key.getClass().isInstance(key1)); + assertTrue(val.getClass().isInstance(val1)); + + assertEquals(key, key); + assertEquals(val, val1); + } + + /** + * + */ + @ParameterizedTest + @MethodSource("serializerFactoryProvider") + public void testClassWithNoDefaultConstructor(SerializerFactory factory) throws SerializationException { + Column[] cols = new Column[] { + new Column("pLongCol", LONG, false), + }; + + SchemaDescriptor schema = new SchemaDescriptor(1, new Columns(cols), new Columns(cols.clone())); + + final Object key = WrongTestObject.randomObject(rnd); + final Object val = WrongTestObject.randomObject(rnd); + + Serializer serializer = factory.create(schema, key.getClass(), val.getClass()); + + byte[] bytes = serializer.serialize(key, val); + + Object key1 = serializer.deserializeKey(bytes); + Object val1 = serializer.deserializeValue(bytes); + + assertTrue(key.getClass().isInstance(key1)); + assertTrue(val.getClass().isInstance(val1)); + + assertEquals(key, key); + assertEquals(val, val1); + } /** * Generate random key-value pair of given types and