ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amashen...@apache.org
Subject [ignite] 01/02: WIP. Add FieldAccessor tests. Add Mokito dependency.
Date Fri, 13 Nov 2020 15:25:58 GMT
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 417b81d5f0640b2d2bb7b7db44b403634d2e7730
Author: Andrew Mashenkov <andrey.mashenkov@gmail.com>
AuthorDate: Fri Nov 13 15:59:09 2020 +0300

    WIP. Add FieldAccessor tests.
    Add Mokito dependency.
---
 modules/commons/pom.xml                            |  12 +-
 .../internal/schema/marshaller/FieldAccessor.java  |  75 +++---
 .../internal/schema/marshaller/JavaSerializer.java |  25 +-
 .../internal/schema/marshaller/Marshaller.java     |   4 +-
 .../java/org/apache/ignite/internal/util/Pair.java |  57 +++++
 .../ignite/internal/schema/SchemaTestUtils.java    |  83 +++---
 .../schema/marshaller/FieldAccessorTest.java       | 285 +++++++++++++++++++++
 .../schema/marshaller/JavaSerializerTest.java      |   3 +
 8 files changed, 462 insertions(+), 82 deletions(-)

diff --git a/modules/commons/pom.xml b/modules/commons/pom.xml
index ad7636f..9308376 100644
--- a/modules/commons/pom.xml
+++ b/modules/commons/pom.xml
@@ -32,10 +32,13 @@
     <properties> <!-- TODO: Move section to some parent module. -->
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
+        <!-- Dependencies versions -->
         <jetbrains.annotations.version>20.1.0</jetbrains.annotations.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>
 
+        <!-- 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>
@@ -149,6 +152,7 @@
             <version>${jetbrains.annotations.version}</version>
         </dependency>
 
+        <!-- Test dependencies. -->
         <!--JUnit 5-->
         <dependency>
             <groupId>org.junit.jupiter</groupId>
@@ -156,13 +160,19 @@
             <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>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>${mockito.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build> <!-- TODO: Move section to some parent module. -->
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/FieldAccessor.java
b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/FieldAccessor.java
index 174fe86..6e5603d 100644
--- a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/FieldAccessor.java
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/FieldAccessor.java
@@ -56,54 +56,61 @@ public abstract class FieldAccessor {
     /**
      * Create accessor for the field.
      *
-     * @param field Field.
+     * @param type Object class.
      * @param col Mapped column.
      * @param colIdx Column index in schema.
      * @return Accessor.
      */
     //TODO: Extract a provider for this factory-method.
-    public static FieldAccessor create(Field field, Column col, int colIdx) {
-        if (field.getType().isPrimitive() && col.nullable()) //TODO: convert to assert?
-            throw new IllegalArgumentException("Failed to map non-nullable field to nullable
column [name=" + field.getName() + ']');
+    public static FieldAccessor create(Class<?> type, Column col, int colIdx) {
+        try {
+            final Field field = type.getDeclaredField(col.name());
 
-        BinaryMode mode = JavaSerializer.mode(field.getType());
+            if (field.getType().isPrimitive() && col.nullable()) //TODO: convert
to assert?
+                throw new IllegalArgumentException("Failed to map non-nullable field to nullable
column [name=" + field.getName() + ']');
 
-        switch (mode) {
-            case P_BYTE:
-                return new BytePrimitiveAccessor(field, colIdx);
+            BinaryMode mode = JavaSerializer.mode(field.getType());
 
-            case P_SHORT:
-                return new ShortPrimitiveAccessor(field, colIdx);
+            switch (mode) {
+                case P_BYTE:
+                    return new BytePrimitiveAccessor(field, colIdx);
 
-            case P_INT:
-                return new IntPrimitiveAccessor(field, colIdx);
+                case P_SHORT:
+                    return new ShortPrimitiveAccessor(field, colIdx);
 
-            case P_LONG:
-                return new LongPrimitiveAccessor(field, colIdx);
+                case P_INT:
+                    return new IntPrimitiveAccessor(field, colIdx);
 
-            case P_FLOAT:
-                return new FloatPrimitiveAccessor(field, colIdx);
+                case P_LONG:
+                    return new LongPrimitiveAccessor(field, colIdx);
 
-            case P_DOUBLE:
-                return new DoublePrimitiveAccessor(field, colIdx);
+                case P_FLOAT:
+                    return new FloatPrimitiveAccessor(field, colIdx);
 
-            case BYTE:
-            case SHORT:
-            case INT:
-            case LONG:
-            case FLOAT:
-            case DOUBLE:
-            case STRING:
-            case UUID:
-            case BYTE_ARR:
-            case BITSET:
-                return new ReferenceFieldAccessor(field, colIdx, mode);
+                case P_DOUBLE:
+                    return new DoublePrimitiveAccessor(field, colIdx);
 
-            default:
-                assert false : "Invalid mode " + mode;
-        }
+                case BYTE:
+                case SHORT:
+                case INT:
+                case LONG:
+                case FLOAT:
+                case DOUBLE:
+                case STRING:
+                case UUID:
+                case BYTE_ARR:
+                case BITSET:
+                    return new ReferenceFieldAccessor(field, colIdx, mode);
+
+                default:
+                    assert false : "Invalid mode " + mode;
+            }
 
-        throw new IllegalArgumentException("Failed to create accessor for field [name=" +
field.getName() + ']');
+            throw new IllegalArgumentException("Failed to create accessor for field [name="
+ field.getName() + ']');
+        }
+        catch (NoSuchFieldException | SecurityException ex) {
+            throw new IllegalArgumentException(ex);
+        }
     }
 
     /**
@@ -184,7 +191,7 @@ public abstract class FieldAccessor {
             write0(Objects.requireNonNull(obj), writer);
         }
         catch (Exception ex) {
-            if (includeSensitive())
+            if (includeSensitive() && field != null)
                 throw new SerializationException("Failed to write field [name=" + field.getName()
+ ']', ex);
             else
                 throw new SerializationException("Failed to write field [id=" + colIdx +
']', ex);
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/JavaSerializer.java
b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/JavaSerializer.java
index 33c3868..c9ce71e 100644
--- a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/JavaSerializer.java
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/JavaSerializer.java
@@ -281,23 +281,17 @@ public class JavaSerializer {
             return new Marshaller(FieldAccessor.createIdentityAccessor(col, firstColId, mode));
         }
 
-        try {
-            FieldAccessor[] fieldAccessors = new FieldAccessor[cols.length()];
+        FieldAccessor[] fieldAccessors = new FieldAccessor[cols.length()];
 
-            // Build accessors
-            for (int i = 0; i < cols.length(); i++) {
-                final Column col = cols.column(i);
-                final Field field = aClass.getDeclaredField(col.name());
+        // Build accessors
+        for (int i = 0; i < cols.length(); i++) {
+            final Column col = cols.column(i);
 
-                final int colIdx = firstColId + i; /* Absolute column idx in schema. */
-                fieldAccessors[i] = FieldAccessor.create(field, col, colIdx);
-            }
-
-            return new Marshaller(ObjectFactory.classFactory(aClass), fieldAccessors);
-        }
-        catch (NoSuchFieldException | SecurityException ex) {
-            throw new IllegalStateException(ex);
+            final int colIdx = firstColId + i; /* Absolute column idx in schema. */
+            fieldAccessors[i] = FieldAccessor.create(aClass, col, colIdx);
         }
+
+        return new Marshaller(ObjectFactory.classFactory(aClass), fieldAccessors);
     }
 
     /**
@@ -368,7 +362,8 @@ public class JavaSerializer {
      * @return Object statistic.
      * @throws SerializationException If failed.
      */
-    private ObjectStatistic collectObjectStats(Columns cols, Marshaller marsh, Object obj)
throws SerializationException {
+    private ObjectStatistic collectObjectStats(Columns cols, Marshaller marsh, Object obj)
+        throws SerializationException {
         if (obj == null || cols.firstVarlengthColumn() < 0 /* No varlen columns */)
             return new ObjectStatistic(0, 0);
 
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/Marshaller.java
b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/Marshaller.java
index eb886c2..9085700 100644
--- a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/Marshaller.java
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/Marshaller.java
@@ -97,7 +97,7 @@ public class Marshaller {
      * @throws SerializationException If failed.
      */
     public Object readObject(Tuple reader) throws SerializationException {
-        if (isBasicMarshaller())
+        if (isBasicTypeMarshaller())
             return fieldAccessors[0].read(reader);
 
         final Object obj = factory.newInstance();
@@ -123,7 +123,7 @@ public class Marshaller {
     /**
      * @return {@code true} if it is marshaller for basic type, {@code false} otherwise.
      */
-    private boolean isBasicMarshaller() {
+    private boolean isBasicTypeMarshaller() {
         return factory == null;
     }
 }
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/util/Pair.java b/modules/commons/src/main/java/org/apache/ignite/internal/util/Pair.java
new file mode 100644
index 0000000..a88fc7d
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/util/Pair.java
@@ -0,0 +1,57 @@
+/*
+ * 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.util;
+
+/**
+ * Pair of objects.
+ *
+ * @param <T> First object.
+ * @param <V> Second object.
+ */
+public class Pair<T, V> {
+    /** Fisrt obj. */
+    private final T first;
+
+    /** Second obj. */
+    private final V second;
+
+    /**
+     * Constructor.
+     *
+     * @param first First object.
+     * @param second Second object.
+     */
+    public Pair(T first, V second) {
+        this.first = first;
+        this.second = second;
+    }
+
+    /**
+     * @return First object.
+     */
+    public T getFirst() {
+        return first;
+    }
+
+    /**
+     * @return Second object.
+     */
+    public V getSecond() {
+        return second;
+    }
+}
diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestUtils.java
b/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestUtils.java
index ca97749..fb62517 100644
--- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestUtils.java
+++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestUtils.java
@@ -21,7 +21,7 @@ import java.util.BitSet;
 import java.util.Random;
 
 /**
- *  Test utility class.
+ * Test utility class.
  */
 public class SchemaTestUtils {
     /**
@@ -29,6 +29,7 @@ public class SchemaTestUtils {
      *
      * @param rnd Random generator.
      * @param type Type.
+     * @return Random object of asked type.
      */
     public static Object generateRandomValue(Random rnd, NativeType type) {
         switch (type.spec()) {
@@ -53,46 +54,68 @@ public class SchemaTestUtils {
             case UUID:
                 return new java.util.UUID(rnd.nextLong(), rnd.nextLong());
 
-            case STRING: {
-                int size = rnd.nextInt(255);
+            case STRING:
+                return randomString(rnd, rnd.nextInt(255));
 
-                StringBuilder sb = new StringBuilder();
+            case BYTES:
+                return randomBytes(rnd, rnd.nextInt(255));
 
-                while (sb.length() < size) {
-                    char pt = (char)rnd.nextInt(Character.MAX_VALUE + 1);
-
-                    if (Character.isDefined(pt) &&
-                        Character.getType(pt) != Character.PRIVATE_USE &&
-                        !Character.isSurrogate(pt))
-                        sb.append(pt);
-                }
+            case BITMASK: {
+                Bitmask maskType = (Bitmask)type;
 
-                return sb.toString();
+                return randomBitSet(rnd, maskType.bits());
             }
 
-            case BYTES: {
-                int size = rnd.nextInt(255);
-                byte[] data = new byte[size];
-                rnd.nextBytes(data);
+            default:
+                throw new IllegalStateException("Unsupported type: " + type);
+        }
+    }
 
-                return data;
-            }
+    /**
+     * @param rnd Random generator.
+     * @param bits Amount of bits in bitset.
+     * @return Random BitSet.
+     */
+    public static BitSet randomBitSet(Random rnd, int bits) {
+        BitSet set = new BitSet();
 
-            case BITMASK: {
-                Bitmask maskType = (Bitmask)type;
+        for (int i = 0; i < bits; i++) {
+            if (rnd.nextBoolean())
+                set.set(i);
+        }
 
-                BitSet set = new BitSet();
+        return set;
+    }
 
-                for (int i = 0; i < maskType.bits(); i++) {
-                    if (rnd.nextBoolean())
-                        set.set(i);
-                }
+    /**
+     * @param rnd Random generator.
+     * @param len Byte array length.
+     * @return Radmon byte array.
+     */
+    public static byte[] randomBytes(Random rnd, int len) {
+        byte[] data = new byte[len];
+        rnd.nextBytes(data);
 
-                return set;
-            }
+        return data;
+    }
 
-            default:
-                throw new IllegalStateException("Unsupported type: " + type);
+    /**
+     * @param rnd Random generator.
+     * @param len String length.
+     * @return Randon string.
+     */
+    public static String randomString(Random rnd, int len) {
+        StringBuilder sb = new StringBuilder();
+
+        while (sb.length() < len) {
+            char pt = (char)rnd.nextInt(Character.MAX_VALUE + 1);
+
+            if (Character.isDefined(pt) &&
+                Character.getType(pt) != Character.PRIVATE_USE &&
+                !Character.isSurrogate(pt))
+                sb.append(pt);
         }
+
+        return sb.toString();
     }
 }
diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/marshaller/FieldAccessorTest.java
b/modules/commons/src/test/java/org/apache/ignite/internal/schema/marshaller/FieldAccessorTest.java
new file mode 100644
index 0000000..396c6ca
--- /dev/null
+++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/marshaller/FieldAccessorTest.java
@@ -0,0 +1,285 @@
+/*
+ * 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.marshaller;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Random;
+import java.util.UUID;
+import org.apache.ignite.internal.schema.Bitmask;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.SchemaTestUtils;
+import org.apache.ignite.internal.schema.Tuple;
+import org.apache.ignite.internal.schema.TupleAssembler;
+import org.apache.ignite.internal.util.Pair;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import static org.apache.ignite.internal.schema.NativeType.BYTE;
+import static org.apache.ignite.internal.schema.NativeType.BYTES;
+import static org.apache.ignite.internal.schema.NativeType.DOUBLE;
+import static org.apache.ignite.internal.schema.NativeType.FLOAT;
+import static org.apache.ignite.internal.schema.NativeType.INTEGER;
+import static org.apache.ignite.internal.schema.NativeType.LONG;
+import static org.apache.ignite.internal.schema.NativeType.SHORT;
+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;
+
+/**
+ * Check field accessor correctness.
+ */
+public class FieldAccessorTest {
+    /** Random. */
+    private Random rnd;
+
+    /**
+     *
+     */
+    @BeforeEach
+    public void initRandom() {
+        long seed = System.currentTimeMillis();
+
+        System.out.println("Using seed: " + seed + "L; //");
+
+        rnd = new Random(seed);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testFieldAccessor() throws Exception {
+        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(9), true),
+            new Column("stringCol", STRING, true),
+            new Column("bytesCol", BYTES, true),
+        };
+
+        final Pair<TupleAssembler, Tuple> mocks = createMocks();
+
+        final TupleAssembler tupleAssembler = mocks.getFirst();
+        final Tuple tuple = mocks.getSecond();
+
+        final TestObject obj = generateRandomObject();
+
+        for (int i = 0; i < cols.length; i++) {
+            FieldAccessor accessor = FieldAccessor.create(TestObject.class, cols[i], i);
+
+            accessor.write(obj, tupleAssembler);
+        }
+
+        final TestObject restoredObj = new TestObject();
+
+        for (int i = 0; i < cols.length; i++) {
+            FieldAccessor accessor = FieldAccessor.create(TestObject.class, cols[i], i);
+
+            accessor.read(restoredObj, tuple);
+        }
+
+        assertEquals(obj.pByteCol, restoredObj.pByteCol);
+        assertEquals(obj.pShortCol, restoredObj.pShortCol);
+        assertEquals(obj.pIntCol, restoredObj.pIntCol);
+        assertEquals(obj.pLongCol, restoredObj.pLongCol);
+        assertEquals(obj.pFloatCol, restoredObj.pFloatCol);
+        assertEquals(obj.pDoubleCol, restoredObj.pDoubleCol);
+
+        assertEquals(obj.byteCol, restoredObj.byteCol);
+        assertEquals(obj.shortCol, restoredObj.shortCol);
+        assertEquals(obj.intCol, restoredObj.intCol);
+        assertEquals(obj.longCol, restoredObj.longCol);
+        assertEquals(obj.floatCol, restoredObj.floatCol);
+        assertEquals(obj.doubleCol, restoredObj.doubleCol);
+
+        assertEquals(obj.uuidCol, restoredObj.uuidCol);
+        assertEquals(obj.bitmaskCol, restoredObj.bitmaskCol);
+        assertEquals(obj.stringCol, restoredObj.stringCol);
+        assertArrayEquals(obj.bytesCol, restoredObj.bytesCol);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testIdentityAccessor() throws Exception {
+        final FieldAccessor accessor = FieldAccessor.createIdentityAccessor(
+            new Column("col0", STRING, true),
+            0,
+            BinaryMode.STRING);
+
+        assertEquals("Some string", accessor.value("Some string"));
+
+        final Pair<TupleAssembler, Tuple> mocks = createMocks();
+
+        accessor.write("Other string", mocks.getFirst());
+        assertEquals("Other string", accessor.read(mocks.getSecond()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testWrongIdentityAccessor() throws Exception {
+        final FieldAccessor accessor = FieldAccessor.createIdentityAccessor(
+            new Column("col0", STRING, true),
+            42,
+            BinaryMode.UUID);
+
+        assertEquals("Some string", accessor.value("Some string"));
+
+        final Pair<TupleAssembler, Tuple> mocks = createMocks();
+
+        assertThrows(
+            SerializationException.class,
+            () -> accessor.write("Other string", mocks.getFirst()),
+            "Failed to write field [id=42]");
+    }
+
+    /**
+     * Creates mock pair for {@link Tuple} and {@link TupleAssembler).
+     *
+     * @return Pair of mocks.
+     */
+    private Pair<TupleAssembler, Tuple> createMocks() {
+        final ArrayList<Object> vals = new ArrayList<>();
+
+        final TupleAssembler mockedAsm = Mockito.mock(TupleAssembler.class);
+        final Tuple mockedTuple = Mockito.mock(Tuple.class);
+
+        final Answer<Void> asmAnswer = new Answer<Void>() {
+            @Override public Void answer(InvocationOnMock invocation) throws Throwable {
+                vals.add(invocation.getArguments()[0]);
+
+                return null;
+            }
+        };
+
+        final Answer<Object> tupleAnswer = new Answer<Object>() {
+            @Override public Object answer(InvocationOnMock invocation) throws Throwable
{
+                final int idx = invocation.getArgumentAt(0, Integer.class);
+
+                return vals.get(idx);
+            }
+        };
+
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendNull();
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendByte(Mockito.anyByte());
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendShort(Mockito.anyShort());
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendInt(Mockito.anyInt());
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendLong(Mockito.anyLong());
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendFloat(Mockito.anyFloat());
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendDouble(Mockito.anyDouble());
+
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendUuid(Mockito.any(java.util.UUID.class));
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendBitmask(Mockito.any(BitSet.class));
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendString(Mockito.anyString());
+        Mockito.doAnswer(asmAnswer).when(mockedAsm).appendBytes(Mockito.any(byte[].class));
+
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).byteValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).byteValueBoxed(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).shortValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).shortValueBoxed(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).intValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).intValueBoxed(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).longValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).longValueBoxed(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).floatValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).floatValueBoxed(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).doubleValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).doubleValueBoxed(Mockito.anyInt());
+
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).uuidValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).bitmaskValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).stringValue(Mockito.anyInt());
+        Mockito.doAnswer(tupleAnswer).when(mockedTuple).bytesValue(Mockito.anyInt());
+
+        return new Pair<>(mockedAsm, mockedTuple);
+    }
+
+    /**
+     * @return Random TestObject.
+     */
+    private TestObject generateRandomObject() {
+        final TestObject obj = new TestObject();
+
+        obj.pByteCol = (byte)rnd.nextInt(255);
+        obj.pShortCol = (short)rnd.nextInt(65535);
+        obj.pIntCol = rnd.nextInt();
+        obj.pLongCol = rnd.nextLong();
+        obj.pFloatCol = rnd.nextFloat();
+        obj.pDoubleCol = rnd.nextDouble();
+
+        obj.byteCol = (byte)rnd.nextInt(255);
+        obj.shortCol = (short)rnd.nextInt(65535);
+        obj.intCol = rnd.nextInt();
+        obj.longCol = rnd.nextLong();
+        obj.floatCol = rnd.nextFloat();
+        obj.doubleCol = rnd.nextDouble();
+
+        obj.uuidCol = new UUID(rnd.nextLong(), rnd.nextLong());
+        obj.bitmaskCol = SchemaTestUtils.randomBitSet(rnd, rnd.nextInt(42));
+        obj.stringCol = SchemaTestUtils.randomString(rnd, rnd.nextInt(255));
+        obj.bytesCol = SchemaTestUtils.randomBytes(rnd, rnd.nextInt(255));
+
+        return obj;
+    }
+
+    /**
+     * Test object.
+     */
+    private static class TestObject {
+        private byte pByteCol;
+        private short pShortCol;
+        private int pIntCol;
+        private long pLongCol;
+        private float pFloatCol;
+        private double pDoubleCol;
+
+        private Byte byteCol;
+        private Short shortCol;
+        private Integer intCol;
+        private Long longCol;
+        private Float floatCol;
+        private Double doubleCol;
+
+        private UUID uuidCol;
+        private BitSet bitmaskCol;
+        private String stringCol;
+        private byte[] bytesCol;
+    }
+}
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 58a44dc..5eddf24 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
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.schema.marshaller;
 
 import java.util.Random;
+import org.apache.ignite.internal.schema.Bitmask;
 import org.apache.ignite.internal.schema.Column;
 import org.apache.ignite.internal.schema.Columns;
 import org.apache.ignite.internal.schema.NativeType;
@@ -81,6 +82,7 @@ public class JavaSerializerTest {
         checkBasicType(FLOAT, FLOAT);
         checkBasicType(DOUBLE, DOUBLE);
         checkBasicType(UUID, UUID);
+        checkBasicType(Bitmask.of(4), Bitmask.of(5));
 
         // Varlen types:
         checkBasicType(BYTES, BYTES);
@@ -90,6 +92,7 @@ public class JavaSerializerTest {
         checkBasicType(LONG, INTEGER);
         checkBasicType(INTEGER, BYTES);
         checkBasicType(STRING, LONG);
+        checkBasicType(Bitmask.of(9), BYTES);
     }
 
     /**


Mime
View raw message