ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-1282: Added missing unit tests for fast-path PortableField string deserialization when string is written as char array.
Date Wed, 04 Nov 2015 08:35:13 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1282 6eb314e75 -> d59a5f02a


IGNITE-1282: Added missing unit tests for fast-path PortableField string deserialization when
string is written as char array.


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

Branch: refs/heads/ignite-1282
Commit: d59a5f02a74dd1015691d60ecfd61426cf25e319
Parents: 6eb314e
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Nov 4 11:35:57 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Nov 4 11:35:57 2015 +0300

----------------------------------------------------------------------
 .../PortableFieldsAbstractSelfTest.java         | 83 +++++++++++++++-----
 .../portable/PortableFieldsHeapSelfTest.java    |  2 +-
 .../portable/PortableFieldsOffheapSelfTest.java |  2 +-
 3 files changed, 64 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d59a5f02/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 2acc1f5..0d712dc 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
@@ -49,18 +49,21 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     };
 
     /** Marshaller. */
-    protected PortableMarshaller marsh;
+    protected PortableMarshaller dfltMarsh;
 
-    /** Portable context. */
-    protected PortableContext ctx;
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        super.beforeTest();
+    /**
+     * Create marshaller.
+     *
+     * @param stringAsBytes Whether to marshal strings as bytes (UTF8).
+     * @return Portable marshaller.
+     * @throws Exception If failed.
+     */
+    protected static PortableMarshaller createMarshaller(boolean stringAsBytes) throws Exception
{
+        PortableContext ctx = new PortableContext(META_HND, null);
 
-        ctx = new PortableContext(META_HND, null);
+        PortableMarshaller marsh = new PortableMarshaller();
 
-        marsh = new PortableMarshaller();
+        marsh.setConvertStringToBytes(stringAsBytes);
 
         marsh.setTypeConfigurations(Arrays.asList(
             new PortableTypeConfiguration(TestObject.class.getName()),
@@ -71,6 +74,27 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
         marsh.setContext(new MarshallerContextTestImpl(null));
 
         IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", ctx);
+
+        return marsh;
+    }
+
+    /**
+     * Get portable context for the current marshaller.
+     *
+     * @param marsh Marshaller.
+     * @return Portable context.
+     */
+    protected static PortableContext portableContext(PortableMarshaller marsh) {
+        GridPortableMarshaller impl = U.field(marsh, "impl");
+
+        return impl.context();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        dfltMarsh = createMarshaller(true);
     }
 
     /**
@@ -227,6 +251,18 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test string field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testStringAsChars() throws Exception {
+        PortableMarshaller marsh = createMarshaller(false);
+
+        checkNormal(marsh, "fString", true);
+        checkNested(marsh, "fString", true);
+    }
+
+    /**
      * Test string array field.
      *
      * @throws Exception If failed.
@@ -342,8 +378,8 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     public void testMissing() throws Exception {
         String fieldName = "fMissing";
 
-        checkNormal(fieldName, false);
-        checkNested(fieldName, false);
+        checkNormal(dfltMarsh, fieldName, false);
+        checkNested(dfltMarsh, fieldName, false);
     }
 
     /**
@@ -353,34 +389,36 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
      * @throws Exception If failed.
      */
     public void check(String fieldName) throws Exception {
-        checkNormal(fieldName, true);
-        checkNested(fieldName, true);
+        checkNormal(dfltMarsh, fieldName, true);
+        checkNested(dfltMarsh, fieldName, true);
     }
 
     /**
      * Check field.
      *
+     * @param marsh Marshaller.
      * @param fieldName Field name.
      * @param exists Whether field should exist.
      * @throws Exception If failed.
      */
-    private void checkNormal(String fieldName, boolean exists) throws Exception {
-        TestContext ctx = context(fieldName);
+    private void checkNormal(PortableMarshaller marsh, String fieldName, boolean exists)
throws Exception {
+        TestContext testCtx = context(marsh, fieldName);
 
-        check0(fieldName, ctx, exists);
+        check0(fieldName, testCtx, exists);
     }
 
     /**
      * Check nested field.
      *
+     * @param marsh Marshaller.
      * @param fieldName Field name.
      * @param exists Whether field should exist.
      * @throws Exception If failed.
      */
-    private void checkNested(String fieldName, boolean exists) throws Exception {
-        TestContext ctx = nestedContext(fieldName);
+    private void checkNested(PortableMarshaller marsh, String fieldName, boolean exists)
throws Exception {
+        TestContext testCtx = nestedContext(marsh, fieldName);
 
-        check0(fieldName, ctx, exists);
+        check0(fieldName, testCtx, exists);
     }
 
     /**
@@ -451,11 +489,12 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     /**
      * Get test context.
      *
+     * @param marsh Portable marshaller.
      * @param fieldName Field name.
      * @return Test context.
      * @throws Exception If failed.
      */
-    private TestContext context(String fieldName) throws Exception {
+    private TestContext context(PortableMarshaller marsh, String fieldName) throws Exception
{
         TestObject obj = createObject();
 
         PortableObjectEx portObj = toPortable(marsh, obj);
@@ -468,11 +507,13 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     /**
      * Get test context with nested test object.
      *
+     * @param marsh Portable marshaller.
      * @param fieldName Field name.
      * @return Test context.
      * @throws Exception If failed.
      */
-    private TestContext nestedContext(String fieldName) throws Exception {
+    private TestContext nestedContext(PortableMarshaller marsh, String fieldName)
+        throws Exception {
         TestObject obj = createObject();
         TestOuterObject outObj = new TestOuterObject(obj);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d59a5f02/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
index f7ccd1d..c7feeab 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
@@ -27,6 +27,6 @@ public class PortableFieldsHeapSelfTest extends PortableFieldsAbstractSelfTest
{
     @Override protected PortableObjectEx toPortable(PortableMarshaller marsh, Object obj)
throws Exception {
         byte[] bytes = marsh.marshal(obj);
 
-        return new PortableObjectImpl(ctx, bytes, 0);
+        return new PortableObjectImpl(portableContext(marsh), bytes, 0);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d59a5f02/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
index e421375..44bb8a1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
@@ -56,6 +56,6 @@ public class PortableFieldsOffheapSelfTest extends PortableFieldsAbstractSelfTes
 
         UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
 
-        return new PortableObjectOffheapImpl(ctx, ptr, 0, arr.length);
+        return new PortableObjectOffheapImpl(portableContext(marsh), ptr, 0, arr.length);
     }
 }


Mime
View raw message