You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/11/03 15:36:04 UTC

[1/3] ignite git commit: IGNITE-1838: WIP on array tests.

Repository: ignite
Updated Branches:
  refs/heads/ignite-1838 6ddbd5b70 -> 26ab6001c


IGNITE-1838: WIP on array tests.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/aa8b0692
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/aa8b0692
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/aa8b0692

Branch: refs/heads/ignite-1838
Commit: aa8b0692c0c2f80b5e15ddbba84f39a0415522ed
Parents: 6ddbd5b
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Nov 3 16:57:16 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Nov 3 16:57:16 2015 +0300

----------------------------------------------------------------------
 .../PortableFieldsAbstractSelfTest.java         | 119 ++++++++++++++++++-
 1 file changed, 117 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/aa8b0692/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
index 07b2745..4af5332 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
@@ -33,6 +33,9 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.UUID;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertTrue;
+
 /**
  * Contains tests for portable object fields.
  */
@@ -83,6 +86,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test byte array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testByteArray() throws Exception {
+        check("fByteArr");
+    }
+
+    /**
      * Test boolean field.
      *
      * @throws Exception If failed.
@@ -92,6 +104,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test boolean array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testBooleanArray() throws Exception {
+        check("fBoolArr");
+    }
+
+    /**
      * Test short field.
      *
      * @throws Exception If failed.
@@ -101,6 +122,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test short array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testShortArray() throws Exception {
+        check("fShortArr");
+    }
+
+    /**
      * Test char field.
      *
      * @throws Exception If failed.
@@ -108,6 +138,16 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     public void testChar() throws Exception {
         check("fChar");
     }
+
+    /**
+     * Test char array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCharArray() throws Exception {
+        check("fCharArr");
+    }
+
     /**
      * Test int field.
      *
@@ -118,6 +158,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test int array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testIntArray() throws Exception {
+        check("fIntArr");
+    }
+
+    /**
      * Test long field.
      *
      * @throws Exception If failed.
@@ -127,6 +176,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test long array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testLongArray() throws Exception {
+        check("fLongArr");
+    }
+
+    /**
      * Test float field.
      *
      * @throws Exception If failed.
@@ -136,6 +194,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test float array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testFloatArray() throws Exception {
+        check("fFloatArr");
+    }
+
+    /**
      * Test double field.
      *
      * @throws Exception If failed.
@@ -145,6 +212,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test double array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDoubleArray() throws Exception {
+        check("fDoubleArr");
+    }
+
+    /**
      * Test string field.
      *
      * @throws Exception If failed.
@@ -275,7 +351,28 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
             if (val instanceof PortableObject)
                 val = ((PortableObject) val).deserialize();
 
-            assertEquals(expVal, val);
+            if (val != null && val.getClass().isArray()) {
+                if (val instanceof byte[])
+                    assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val));
+                else if (val instanceof boolean[])
+                    assertTrue(Arrays.equals((boolean[]) expVal, (boolean[]) val));
+                else if (val instanceof short[])
+                    assertTrue(Arrays.equals((short[]) expVal, (short[]) val));
+                else if (val instanceof char[])
+                    assertTrue(Arrays.equals((char[]) expVal, (char[]) val));
+                else if (val instanceof int[])
+                    assertTrue(Arrays.equals((int[]) expVal, (int[]) val));
+                else if (val instanceof long[])
+                    assertTrue(Arrays.equals((long[]) expVal, (long[]) val));
+                else if (val instanceof float[])
+                    assertTrue(Arrays.equals((float[]) expVal, (float[]) val));
+                else if (val instanceof double[])
+                    assertTrue(Arrays.equals((double[]) expVal, (double[]) val));
+                else
+                    assertTrue(Arrays.equals((Object[]) expVal, (Object[]) val));
+            }
+            else
+                assertEquals(expVal, val);
         }
         else {
             assertFalse(ctx.field.exists(ctx.portObj));
@@ -381,6 +478,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
         public float fFloat;
         public double fDouble;
 
+//        public byte[] fByteArr;
+//        public boolean[] fBoolArr;
+//        public short[] fShortArr;
+//        public char[] fCharArr;
+//        public int[] fIntArr;
+//        public long[] fLongArr;
+//        public float[] fFloatArr;
+//        public double[] fDoubleArr;
+
         /** Special fields. */
         public String fString;
         public Date fDate;
@@ -416,9 +522,18 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
             fFloat = 6.6f;
             fDouble = 7.7;
 
+//            fByteArr = new byte[] { 1, 2 };
+//            fBoolArr = new boolean[] { true, false };
+//            fShortArr = new short[] { 2, 3 };
+//            fCharArr = new char[] { 3, 4 };
+//            fIntArr = new int[] { 4, 5 };
+//            fLongArr = new long[] { 5, 6 };
+//            fFloatArr = new float[] { 6.6f, 7.7f };
+//            fDoubleArr = new double[] { 7.7, 8.8 };
+
             fString = "8";
             fDate = new Date();
-            fTimestamp = new Timestamp(new Date().getTime());
+            fTimestamp = new Timestamp(new Date().getTime() + 100);
             fUuid = UUID.randomUUID();
             fDecimal = new BigDecimal(9);
 


[2/3] ignite git commit: IGNITE-1838: Finished tests.

Posted by vo...@apache.org.
IGNITE-1838: Finished tests.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5db7b067
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5db7b067
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5db7b067

Branch: refs/heads/ignite-1838
Commit: 5db7b067e74cbe31e82479684381a0a77c01969b
Parents: aa8b069
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Nov 3 17:17:57 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Nov 3 17:17:57 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableObjectImpl.java   |   4 +-
 .../portable/PortableObjectOffheapImpl.java     |   4 +-
 .../PortableFieldsAbstractSelfTest.java         | 127 +++++++++++++++----
 3 files changed, 109 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5db7b067/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
index bc75b6d..cf4b8d9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
@@ -276,9 +276,9 @@ public final class PortableObjectImpl extends PortableObjectEx implements Extern
         int fieldPos;
 
         if (fieldOffsetSize == PortableUtils.OFFSET_1)
-            fieldPos = start + (int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF;
+            fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
         else if (fieldOffsetSize == PortableUtils.OFFSET_2)
-            fieldPos = start + (int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF;
+            fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
         else
             fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/5db7b067/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
index bb79b74..f12c4fd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
@@ -218,9 +218,9 @@ public class PortableObjectOffheapImpl extends PortableObjectEx implements Exter
         int fieldPos;
 
         if (fieldOffsetSize == PortableUtils.OFFSET_1)
-            fieldPos = start + (int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF;
+            fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
         else if (fieldOffsetSize == PortableUtils.OFFSET_2)
-            fieldPos = start + (int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF;
+            fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
         else
             fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/5db7b067/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
index 4af5332..2acc1f5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
@@ -33,9 +33,6 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.UUID;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
-
 /**
  * Contains tests for portable object fields.
  */
@@ -230,6 +227,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test string array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testStringArray() throws Exception {
+        check("fStringArr");
+    }
+
+    /**
      * Test date field.
      *
      * @throws Exception If failed.
@@ -239,6 +245,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test date array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDateArray() throws Exception {
+        check("fDateArr");
+    }
+
+    /**
      * Test timestamp field.
      *
      * @throws Exception If failed.
@@ -248,6 +263,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test timestamp array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testTimestampArray() throws Exception {
+        check("fTimestampArr");
+    }
+
+    /**
      * Test UUID field.
      *
      * @throws Exception If failed.
@@ -257,6 +281,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test UUID array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testUuidArray() throws Exception {
+        check("fUuidArr");
+    }
+
+    /**
      * Test decimal field.
      *
      * @throws Exception If failed.
@@ -266,6 +299,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test decimal array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDecimalArray() throws Exception {
+        check("fDecimalArr");
+    }
+
+    /**
      * Test object field.
      *
      * @throws Exception If failed.
@@ -275,6 +317,15 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test object array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testObjectArray() throws Exception {
+        check("fObjArr");
+    }
+
+    /**
      * Test null field.
      *
      * @throws Exception If failed.
@@ -352,6 +403,8 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
                 val = ((PortableObject) val).deserialize();
 
             if (val != null && val.getClass().isArray()) {
+                assertNotNull(expVal);
+
                 if (val instanceof byte[])
                     assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val));
                 else if (val instanceof boolean[])
@@ -368,8 +421,22 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
                     assertTrue(Arrays.equals((float[]) expVal, (float[]) val));
                 else if (val instanceof double[])
                     assertTrue(Arrays.equals((double[]) expVal, (double[]) val));
-                else
-                    assertTrue(Arrays.equals((Object[]) expVal, (Object[]) val));
+                else {
+                    Object[] expVal0 = (Object[])expVal;
+                    Object[] val0 = (Object[])val;
+
+                    assertEquals(expVal0.length, val0.length);
+
+                    for (int i = 0; i < expVal0.length; i++) {
+                        Object expItem = expVal0[i];
+                        Object item = val0[i];
+
+                        if (item instanceof PortableObject)
+                            item = ((PortableObject)item).deserialize();
+
+                        assertEquals(expItem, item);
+                    }
+                }
             }
             else
                 assertEquals(expVal, val);
@@ -478,14 +545,14 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
         public float fFloat;
         public double fDouble;
 
-//        public byte[] fByteArr;
-//        public boolean[] fBoolArr;
-//        public short[] fShortArr;
-//        public char[] fCharArr;
-//        public int[] fIntArr;
-//        public long[] fLongArr;
-//        public float[] fFloatArr;
-//        public double[] fDoubleArr;
+        public byte[] fByteArr;
+        public boolean[] fBoolArr;
+        public short[] fShortArr;
+        public char[] fCharArr;
+        public int[] fIntArr;
+        public long[] fLongArr;
+        public float[] fFloatArr;
+        public double[] fDoubleArr;
 
         /** Special fields. */
         public String fString;
@@ -494,9 +561,17 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
         public UUID fUuid;
         public BigDecimal fDecimal;
 
+        public String[] fStringArr;
+        public Date[] fDateArr;
+        public Timestamp[] fTimestampArr;
+        public UUID[] fUuidArr;
+        public BigDecimal[] fDecimalArr;
+
         /** Nested object. */
         public TestInnerObject fObj;
 
+        public TestInnerObject[] fObjArr;
+
         /** Field which is always set to null. */
         public Object fNull;
 
@@ -522,22 +597,30 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
             fFloat = 6.6f;
             fDouble = 7.7;
 
-//            fByteArr = new byte[] { 1, 2 };
-//            fBoolArr = new boolean[] { true, false };
-//            fShortArr = new short[] { 2, 3 };
-//            fCharArr = new char[] { 3, 4 };
-//            fIntArr = new int[] { 4, 5 };
-//            fLongArr = new long[] { 5, 6 };
-//            fFloatArr = new float[] { 6.6f, 7.7f };
-//            fDoubleArr = new double[] { 7.7, 8.8 };
+            fByteArr = new byte[] { 1, 2 };
+            fBoolArr = new boolean[] { true, false };
+            fShortArr = new short[] { 2, 3 };
+            fCharArr = new char[] { 3, 4 };
+            fIntArr = new int[] { 4, 5 };
+            fLongArr = new long[] { 5, 6 };
+            fFloatArr = new float[] { 6.6f, 7.7f };
+            fDoubleArr = new double[] { 7.7, 8.8 };
 
             fString = "8";
             fDate = new Date();
-            fTimestamp = new Timestamp(new Date().getTime() + 100);
+            fTimestamp = new Timestamp(new Date().getTime() + 1);
             fUuid = UUID.randomUUID();
             fDecimal = new BigDecimal(9);
 
+            fStringArr = new String[] { "8", "9" };
+            fDateArr = new Date[] { new Date(), new Date(new Date().getTime() + 1) };
+            fTimestampArr =
+                new Timestamp[] { new Timestamp(new Date().getTime() + 1), new Timestamp(new Date().getTime() + 2) };
+            fUuidArr = new UUID[] { UUID.randomUUID(), UUID.randomUUID() };
+            fDecimalArr = new BigDecimal[] { new BigDecimal(9), new BigDecimal(10) };
+
             fObj = new TestInnerObject(10);
+            fObjArr = new TestInnerObject[] { new TestInnerObject(10), new TestInnerObject(11) };
         }
     }
 


[3/3] ignite git commit: IGNITE-1838: Added tests for compact offsets.

Posted by vo...@apache.org.
IGNITE-1838: Added tests for compact offsets.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/26ab6001
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/26ab6001
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/26ab6001

Branch: refs/heads/ignite-1838
Commit: 26ab6001cb5ed984446c4e640b256a72d35afca5
Parents: 5db7b06
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Nov 3 17:36:46 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Nov 3 17:36:46 2015 +0300

----------------------------------------------------------------------
 .../PortableCompactOffsetsAbstractSelfTest.java | 201 +++++++++++++++++++
 .../PortableCompactOffsetsHeapSelfTest.java     |  32 +++
 .../PortableCompactOffsetsOffheapSelfTest.java  |  61 ++++++
 .../IgnitePortableObjectsTestSuite.java         |   5 +
 4 files changed, 299 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/26ab6001/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java
new file mode 100644
index 0000000..28058de
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java
@@ -0,0 +1,201 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableField;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Arrays;
+
+/**
+ * Contains tests for compact offsets.
+ */
+public abstract class PortableCompactOffsetsAbstractSelfTest extends GridCommonAbstractTest {
+    /** 2 pow 8. */
+    private static int POW_8 = 1 << 8;
+
+    /** 2 pow 16. */
+    private static int POW_16 = 1 << 16;
+
+    /** Dummy metadata handler. */
+    protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
+        @Override public void addMeta(int typeId, PortableMetadata meta) {
+            // No-op.
+        }
+
+        @Override public PortableMetadata metadata(int typeId) {
+            return null;
+        }
+    };
+
+    /** Marshaller. */
+    protected PortableMarshaller marsh;
+
+    /** Portable context. */
+    protected PortableContext ctx;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        ctx = new PortableContext(META_HND, null);
+
+        marsh = new PortableMarshaller();
+
+        marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(TestObject.class.getName())));
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", ctx);
+    }
+
+    /**
+     * Test 1 byte.
+     *
+     * @throws Exception If failed.
+     */
+    public void test1Byte() throws Exception {
+        check(POW_8 >> 2);
+    }
+
+    /**
+     * Test 1 byte with sign altering.
+     *
+     * @throws Exception If failed.
+     */
+    public void test1ByteSign() throws Exception {
+        check(POW_8 >> 1);
+    }
+
+    /**
+     * Test 2 bytes.
+     *
+     * @throws Exception If failed.
+     */
+    public void test2Bytes() throws Exception {
+        check(POW_16 >> 2);
+    }
+
+    /**
+     * Test 2 bytes with sign altering.
+     *
+     * @throws Exception If failed.
+     */
+    public void test2BytesSign() throws Exception {
+        check(POW_16 >> 1);
+    }
+
+    /**
+     * Test 4 bytes.
+     *
+     * @throws Exception If failed.
+     */
+    public void test4Bytes() throws Exception {
+        check(POW_16 << 2);
+    }
+
+    /**
+     * Main check routine.
+     *
+     * @param len Length of the first field.
+     *
+     * @throws Exception If failed.
+     */
+    private void check(int len) throws Exception {
+        TestObject obj = new TestObject(len);
+
+        PortableObjectEx portObj = toPortable(marsh, obj);
+
+        // 1. Test portable object content.
+        assert portObj.hasField("field1");
+        assert portObj.hasField("field2");
+
+        byte[] field1 = portObj.field("field1");
+        Integer field2 = portObj.field("field2");
+
+        assert field1 != null;
+        assert field2 != null;
+
+        assert Arrays.equals(obj.field1, field1);
+        assert obj.field2 == field2;
+
+        // 2. Test fields API.
+        PortableField field1Desc = portObj.fieldDescriptor("field1");
+        PortableField field2Desc = portObj.fieldDescriptor("field2");
+
+        assert field1Desc.exists(portObj);
+        assert field2Desc.exists(portObj);
+
+        assert Arrays.equals(obj.field1, (byte[])field1Desc.value(portObj));
+        assert obj.field2 == (Integer)field2Desc.value(portObj);
+
+        // 3. Test deserialize.
+        TestObject objRestored = portObj.deserialize();
+
+        assert objRestored != null;
+
+        assert Arrays.equals(obj.field1, objRestored.field1);
+        assert obj.field2 == objRestored.field2;
+    }
+
+    /**
+     * Convert object to portable object.
+     *
+     * @param marsh Marshaller.
+     * @param obj Object.
+     * @return Portable object.
+     * @throws Exception If failed.
+     */
+    protected abstract PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception;
+
+    /**
+     * Test object.
+     */
+    public static class TestObject {
+        /** First field with variable length. */
+        public byte[] field1;
+
+        /** Second field. */
+        public int field2;
+
+        /**
+         * Default constructor.
+         */
+        public TestObject() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param len Array length.
+         */
+        public TestObject(int len) {
+            field1 = new byte[len];
+
+            field1[0] = 1;
+            field1[len - 1] = 2;
+
+            field2 = len;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/26ab6001/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java
new file mode 100644
index 0000000..826f972
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Compact offsets tests for heap portable objects.
+ */
+public class PortableCompactOffsetsHeapSelfTest extends PortableCompactOffsetsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
+        byte[] bytes = marsh.marshal(obj);
+
+        return new PortableObjectImpl(ctx, bytes, 0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/26ab6001/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java
new file mode 100644
index 0000000..9ad1c67
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.eclipse.jetty.util.ConcurrentHashSet;
+import sun.misc.Unsafe;
+
+/**
+ * Compact offsets tests for offheap portable objects.
+ */
+public class PortableCompactOffsetsOffheapSelfTest extends PortableCompactOffsetsAbstractSelfTest {
+    /** Unsafe instance. */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** Byte array offset for unsafe mechanics. */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** Allocated unsafe pointer. */
+    private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        // Cleanup allocated objects.
+        for (Long ptr : ptrs)
+            UNSAFE.freeMemory(ptr);
+
+        ptrs.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
+        byte[] arr = marsh.marshal(obj);
+
+        long ptr = UNSAFE.allocateMemory(arr.length);
+
+        ptrs.add(ptr);
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+
+        return new PortableObjectOffheapImpl(ctx, ptr, 0, arr.length);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/26ab6001/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
index c7391a6..3cfd530 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
@@ -28,6 +28,9 @@ import org.apache.ignite.internal.portable.GridPortableMarshallerSelfTest;
 import org.apache.ignite.internal.portable.GridPortableMetaDataDisabledSelfTest;
 import org.apache.ignite.internal.portable.GridPortableMetaDataSelfTest;
 import org.apache.ignite.internal.portable.GridPortableWildcardsSelfTest;
+import org.apache.ignite.internal.portable.PortableCompactOffsetsAbstractSelfTest;
+import org.apache.ignite.internal.portable.PortableCompactOffsetsHeapSelfTest;
+import org.apache.ignite.internal.portable.PortableCompactOffsetsOffheapSelfTest;
 import org.apache.ignite.internal.portable.PortableFieldsHeapSelfTest;
 import org.apache.ignite.internal.portable.PortableFieldsOffheapSelfTest;
 import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodePortableMetadataMultinodeTest;
@@ -64,6 +67,8 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
         suite.addTestSuite(GridPortableBuilderStringAsCharsSelfTest.class);
         suite.addTestSuite(PortableFieldsHeapSelfTest.class);
         suite.addTestSuite(PortableFieldsOffheapSelfTest.class);
+        suite.addTestSuite(PortableCompactOffsetsHeapSelfTest.class);
+        suite.addTestSuite(PortableCompactOffsetsOffheapSelfTest.class);
         suite.addTestSuite(GridPortableMetaDataSelfTest.class);
         suite.addTestSuite(GridPortableMetaDataDisabledSelfTest.class);
         suite.addTestSuite(GridPortableAffinityKeySelfTest.class);