ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [2/2] ignite git commit: IGNITE-1838: WIP on tests.
Date Tue, 03 Nov 2015 13:42:12 GMT
IGNITE-1838: WIP on tests.


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

Branch: refs/heads/ignite-1838
Commit: 12e86e71aad7d2eed60843a10cf05141293fc299
Parents: 4fc3b86
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Tue Nov 3 16:42:53 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Tue Nov 3 16:42:53 2015 +0300

----------------------------------------------------------------------
 .../portable/PortableFIeldsHeapSelfTest.java    |  32 ++++
 .../PortableFieldsAbstractSelfTest.java         | 179 +++++++++++++++++--
 .../IgnitePortableObjectsTestSuite.java         |   4 +-
 3 files changed, 200 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/12e86e71/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
new file mode 100644
index 0000000..aa88ecc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFIeldsHeapSelfTest.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;
+
+/**
+ * Field tests for heap-based portables.
+ */
+public class PortableFIeldsHeapSelfTest extends PortableFieldsAbstractSelfTest {
+    /** {@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/12e86e71/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 bc0919b..07b2745 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
@@ -23,10 +23,15 @@ 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.PortableObject;
 import org.apache.ignite.portable.PortableTypeConfiguration;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 
+import java.math.BigDecimal;
+import java.sql.Timestamp;
 import java.util.Arrays;
+import java.util.Date;
+import java.util.UUID;
 
 /**
  * Contains tests for portable object fields.
@@ -59,7 +64,8 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
 
         marsh.setTypeConfigurations(Arrays.asList(
             new PortableTypeConfiguration(TestObject.class.getName()),
-            new PortableTypeConfiguration(TestOuterObject.class.getName())
+            new PortableTypeConfiguration(TestOuterObject.class.getName()),
+            new PortableTypeConfiguration(TestInnerObject.class.getName())
         ));
 
         marsh.setContext(new MarshallerContextTestImpl(null));
@@ -121,15 +127,16 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
-     * Test int field.
+     * Test float field.
      *
      * @throws Exception If failed.
      */
     public void testFloat() throws Exception {
         check("fFloat");
     }
+
     /**
-     * Test int field.
+     * Test double field.
      *
      * @throws Exception If failed.
      */
@@ -138,38 +145,115 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
     }
 
     /**
+     * Test string field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testString() throws Exception {
+        check("fString");
+    }
+
+    /**
+     * Test date field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDate() throws Exception {
+        check("fDate");
+    }
+
+    /**
+     * Test timestamp field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testTimestamp() throws Exception {
+        check("fTimestamp");
+    }
+
+    /**
+     * Test UUID field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testUuid() throws Exception {
+        check("fUuid");
+    }
+
+    /**
+     * Test decimal field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDecimal() throws Exception {
+        check("fDecimal");
+    }
+
+    /**
+     * Test object field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testObject() throws Exception {
+        check("fObj");
+    }
+
+    /**
+     * Test null field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNull() throws Exception {
+        check("fNull");
+    }
+
+    /**
+     * Test missing field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMissing() throws Exception {
+        String fieldName = "fMissing";
+
+        checkNormal(fieldName, false);
+        checkNested(fieldName, false);
+    }
+
+    /**
      * Check field resolution in both normal and nested modes.
      *
      * @param fieldName Field name.
      * @throws Exception If failed.
      */
     public void check(String fieldName) throws Exception {
-        checkNormal(fieldName);
-        checkNested(fieldName);
+        checkNormal(fieldName, true);
+        checkNested(fieldName, true);
     }
 
     /**
      * Check field.
      *
      * @param fieldName Field name.
+     * @param exists Whether field should exist.
      * @throws Exception If failed.
      */
-    private void checkNormal(String fieldName) throws Exception {
+    private void checkNormal(String fieldName, boolean exists) throws Exception {
         TestContext ctx = context(fieldName);
 
-        check0(fieldName, ctx);
+        check0(fieldName, ctx, exists);
     }
 
     /**
      * Check nested field.
      *
      * @param fieldName Field name.
+     * @param exists Whether field should exist.
      * @throws Exception If failed.
      */
-    private void checkNested(String fieldName) throws Exception {
+    private void checkNested(String fieldName, boolean exists) throws Exception {
         TestContext ctx = nestedContext(fieldName);
 
-        check0(fieldName, ctx);
+        check0(fieldName, ctx, exists);
     }
 
     /**
@@ -177,14 +261,27 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
      *
      * @param fieldName Field name.
      * @param ctx Context.
+     * @param exists Whether field should exist.
      * @throws Exception If failed.
      */
-    private void check0(String fieldName, TestContext ctx) throws Exception {
-        Object expVal = U.field(ctx.obj, fieldName);
+    private void check0(String fieldName, TestContext ctx, boolean exists) throws Exception
{
+        Object val = ctx.field.value(ctx.portObj);
+
+        if (exists) {
+            assertTrue(ctx.field.exists(ctx.portObj));
 
-        assertTrue(ctx.field.exists(ctx.portObj));
+            Object expVal = U.field(ctx.obj, fieldName);
 
-        assertEquals(expVal, ctx.field.value(ctx.portObj));
+            if (val instanceof PortableObject)
+                val = ((PortableObject) val).deserialize();
+
+            assertEquals(expVal, val);
+        }
+        else {
+            assertFalse(ctx.field.exists(ctx.portObj));
+
+            assert val == null;
+        }
     }
 
     /**
@@ -284,6 +381,19 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
         public float fFloat;
         public double fDouble;
 
+        /** Special fields. */
+        public String fString;
+        public Date fDate;
+        public Timestamp fTimestamp;
+        public UUID fUuid;
+        public BigDecimal fDecimal;
+
+        /** Nested object. */
+        public TestInnerObject fObj;
+
+        /** Field which is always set to null. */
+        public Object fNull;
+
         /**
          * Default constructor.
          */
@@ -305,6 +415,49 @@ public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractT
             fLong = 5;
             fFloat = 6.6f;
             fDouble = 7.7;
+
+            fString = "8";
+            fDate = new Date();
+            fTimestamp = new Timestamp(new Date().getTime());
+            fUuid = UUID.randomUUID();
+            fDecimal = new BigDecimal(9);
+
+            fObj = new TestInnerObject(10);
+        }
+    }
+
+    /**
+     * Inner test object.
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    public static class TestInnerObject {
+        /** Value. */
+        private int val;
+
+        /**
+         * Default constructor.
+         */
+        public TestInnerObject() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param val Value.
+         */
+        public TestInnerObject(int val) {
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object other) {
+            return other != null && other instanceof TestInnerObject && val
== ((TestInnerObject)(other)).val;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/12e86e71/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..22f8b1e 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,7 +28,7 @@ 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.PortableFieldsHeapSelfTest;
+import org.apache.ignite.internal.portable.PortableFIeldsHeapSelfTest;
 import org.apache.ignite.internal.portable.PortableFieldsOffheapSelfTest;
 import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodePortableMetadataMultinodeTest;
 import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodePortableMetadataTest;
@@ -62,7 +62,7 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
         suite.addTestSuite(GridPortableMarshallerCtxDisabledSelfTest.class);
         suite.addTestSuite(GridPortableBuilderSelfTest.class);
         suite.addTestSuite(GridPortableBuilderStringAsCharsSelfTest.class);
-        suite.addTestSuite(PortableFieldsHeapSelfTest.class);
+        suite.addTestSuite(PortableFIeldsHeapSelfTest.class);
         suite.addTestSuite(PortableFieldsOffheapSelfTest.class);
         suite.addTestSuite(GridPortableMetaDataSelfTest.class);
         suite.addTestSuite(GridPortableMetaDataDisabledSelfTest.class);


Mime
View raw message