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/24 15:48:57 UTC

[1/4] ignite git commit: IGNITE-1956: Implementing enums as CacheObject ...

Repository: ignite
Updated Branches:
  refs/heads/ignite-1956 0eef2053c -> 0dec2b9ed


IGNITE-1956: Implementing enums as CacheObject ...


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

Branch: refs/heads/ignite-1956
Commit: ed3bd2b463ae327a8e5d279e2607f3e3b3e15df0
Parents: 0eef205
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Nov 24 16:33:34 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Nov 24 16:33:34 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryEnumObjectImpl.java |  68 +++++++-
 .../internal/portable/BinaryObjectImpl.java     |   3 -
 .../internal/portable/PortableContext.java      |  12 ++
 .../internal/processors/cache/CacheObject.java  |   3 +
 .../internal/portable/BinaryEnumsSelfTest.java  | 170 +++++++++++++++++++
 5 files changed, 252 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3bd2b4/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
index e97ef93..66b080a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
@@ -17,21 +17,28 @@
 
 package org.apache.ignite.internal.portable;
 
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
 import org.jetbrains.annotations.Nullable;
 
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.nio.ByteBuffer;
 
 /**
  * Binary enum object.
  */
-public class BinaryEnumObjectImpl implements BinaryObject, Externalizable {
+public class BinaryEnumObjectImpl implements BinaryObject, Externalizable, CacheObject {
     /** Context. */
     private PortableContext ctx;
 
@@ -179,4 +186,63 @@ public class BinaryEnumObjectImpl implements BinaryObject, Externalizable {
         clsName = (String)in.readObject();
         ord = in.readInt();
     }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        return deserialize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] valueBytes(CacheObjectContext cacheCtx) throws IgniteCheckedException {
+        return ctx.marshaller().marshal(this);
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte cacheObjectType() {
+        return TYPE_BINARY;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isPlatformType() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        // TODO
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        // TODO
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        // TODO
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        // TODO
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3bd2b4/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
index 7db4b4a..346ee5a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
@@ -66,9 +66,6 @@ import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
 @IgniteCodeGeneratingFail // Fields arr and start should not be generated by MessageCodeGenerator.
 public final class BinaryObjectImpl extends BinaryObjectEx implements Externalizable, KeyCacheObject {
     /** */
-    public static final byte TYPE_BINARY = 100;
-
-    /** */
     private static final long serialVersionUID = 0L;
 
     /** */

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3bd2b4/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index 1b9680e..d66666e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -115,6 +115,9 @@ public class PortableContext implements Externalizable {
     /** */
     private BinaryMetadataHandler metaHnd;
 
+    /** Actual marshaller. */
+    private BinaryMarshaller marsh;
+
     /** */
     private MarshallerContext marshCtx;
 
@@ -219,6 +222,13 @@ public class PortableContext implements Externalizable {
     }
 
     /**
+     * @return Marshaller.
+     */
+    public BinaryMarshaller marshaller() {
+        return marsh;
+    }
+
+    /**
      * @param marsh Portable marshaller.
      * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
      */
@@ -226,6 +236,8 @@ public class PortableContext implements Externalizable {
         if (marsh == null)
             return;
 
+        this.marsh = marsh;
+
         marshCtx = marsh.getContext();
 
         BinaryConfiguration binaryCfg = cfg.getBinaryConfiguration();

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3bd2b4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
index 81129bd..2385335 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
@@ -31,6 +31,9 @@ public interface CacheObject extends Message {
     /** */
     public static final byte TYPE_BYTE_ARR = 2;
 
+    /** */
+    public static final byte TYPE_BINARY = 100;
+
     /**
      * @param ctx Context.
      * @param cpy If {@code true} need to copy value.

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3bd2b4/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
new file mode 100644
index 0000000..3abf436
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
@@ -0,0 +1,170 @@
+/*
+ * 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.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.marshaller.portable.BinaryMarshaller;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Arrays;
+
+/**
+ * Contains tests for binary enums.
+ */
+@SuppressWarnings("unchecked")
+public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static String CACHE_NAME = "cache";
+
+    /** Whether to register types or not. */
+    private boolean register;
+
+    /** Node 1. */
+    private Ignite node1;
+
+    /** Node 2. */
+    private Ignite node2;
+
+    /** Cache 1. */
+    private IgniteCache cache1;
+
+    /** Cache 2. */
+    private IgniteCache cache2;
+
+    /** Binary cache 1. */
+    private IgniteCache<Integer, BinaryObject> cacheBinary1;
+
+    /** Binary cache 2. */
+    private IgniteCache<Integer, BinaryObject> cacheBinary2;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        register = false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (register) {
+            BinaryConfiguration bCfg = new BinaryConfiguration();
+
+            BinaryTypeConfiguration enumCfg = new BinaryTypeConfiguration(EnumType.class.getName());
+            enumCfg.setEnum(true);
+
+            bCfg.setTypeConfigurations(Arrays.asList(enumCfg, new BinaryTypeConfiguration(EnumHolder.class.getName())));
+
+            cfg.setBinaryConfiguration(bCfg);
+        }
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+        ccfg.setName(CACHE_NAME);
+        ccfg.setCacheMode(CacheMode.PARTITIONED);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /**
+     * Start up routine.
+     *
+     * @throws Exception If failed.
+     */
+    private void startUp(boolean register) throws Exception {
+        this.register = register;
+
+        node1 = startGrid(0);
+        cache1 = node1.cache(CACHE_NAME);
+        cacheBinary1 = cache1.withKeepBinary();
+
+        node2 = startGrid(1);
+        cache2 = node2.cache(CACHE_NAME);
+        cacheBinary2 = cache2.withKeepBinary();
+    }
+
+    /**
+     * Test operations on simple type which is registered in advance.
+     *
+     * @throws Exception
+     */
+    public void testSimpleRegistered() throws Exception{
+        startUp(true);
+
+        cache1.put(0, new EnumHolder(EnumType.ONE));
+
+        Object res = cache1.get(0);
+
+        cache1.put(1, EnumType.ONE);
+
+        assertEquals(EnumType.ONE, cache1.get(1));
+        assertEquals(EnumType.ONE, cache2.get(1));
+
+        BinaryObject obj = cacheBinary1.get(1);
+
+        assertTrue(obj.type().isEnum());
+        assertEquals(node1.binary().typeId(EnumType.class.getName()), obj.typeId());
+        assertEquals(EnumType.ONE.ordinal(), obj.enumOrdinal());
+    }
+
+    /**
+     * Enumeration holder.
+     */
+    public static class EnumHolder {
+        /** Value. */
+        public EnumType val;
+
+        /**
+         * Default constructor.
+         */
+        public EnumHolder() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param val Value.
+         */
+        public EnumHolder(EnumType val) {
+            this.val = val;
+        }
+    }
+
+    /**
+     * Enumeration for tests.
+     */
+    public static enum EnumType {
+        ONE,
+        TWO
+    }
+}


[3/4] ignite git commit: IGNITE-1956: Further WIP on tests.

Posted by vo...@apache.org.
IGNITE-1956: Further 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/b5fe3456
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b5fe3456
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b5fe3456

Branch: refs/heads/ignite-1956
Commit: b5fe34560fab9f6805c4109e667d5ee39cf8f73e
Parents: 642218d
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Nov 24 17:16:58 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Nov 24 17:16:58 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryEnumsSelfTest.java  | 68 +++++++++++++++++++-
 .../IgnitePortableObjectsTestSuite.java         |  2 +
 2 files changed, 67 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b5fe3456/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
index 9b2cb84..c5a4c90 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
@@ -115,13 +115,75 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
     /**
      * Test operations on simple type which is registered in advance.
      *
-     * @throws Exception
+     * @throws Exception If failed.
+     */
+    public void testSimpleRegistered() throws Exception {
+        checkSimple(true);
+    }
+
+    /**
+     * Test operations on simple type which is not registered in advance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleNotRegistered() throws Exception {
+        checkSimple(false);
+    }
+
+    /**
+     * Test builder operations on simple type which is registered in advance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testBuilderSimpleRegistered() throws Exception {
+        checkBuilderSimple(true);
+    }
+
+    /**
+     * Test builder operations on simple type which is not registered in advance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testBuilderSimpleNotRegistered() throws Exception {
+        checkBuilderSimple(false);
+    }
+
+    /**
+     * Check simple serialization - deserialization.
+     *
+     * @param registered If type should be registered in advance.
+     * @throws Exception If failed.
      */
-    public void testSimpleRegistered() throws Exception{
-        startUp(true);
+    public void checkSimple(boolean registered) throws Exception {
+        startUp(registered);
 
         cache1.put(1, EnumType.ONE);
 
+        validateSimple();
+    }
+
+    /**
+     * Check simple serialization - deserialization using builder.
+     *
+     * @param registered If type should be registered in advance.
+     * @throws Exception If failed.
+     */
+    public void checkBuilderSimple(boolean registered) throws Exception {
+        startUp(registered);
+
+        BinaryObject binary = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.ONE.ordinal());
+
+        cacheBinary1.put(1, binary);
+
+        validateSimple();
+    }
+
+    /**
+     * Internal check routine for simple scenario.
+     *
+     * @throws Exception If failed.
+     */
+    private void validateSimple() throws Exception {
         assertEquals(EnumType.ONE, cache1.get(1));
         assertEquals(EnumType.ONE, cache2.get(1));
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/b5fe3456/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 16eeb2b..629835b 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
@@ -18,6 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
+import org.apache.ignite.internal.portable.BinaryEnumsSelfTest;
 import org.apache.ignite.internal.portable.GridPortableAffinityKeySelfTest;
 import org.apache.ignite.internal.portable.BinaryObjectBuilderAdditionalSelfTest;
 import org.apache.ignite.internal.portable.BinaryObjectBuilderSelfTest;
@@ -72,6 +73,7 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
         suite.addTestSuite(BinaryFieldsOffheapSelfTest.class);
         suite.addTestSuite(BinaryFooterOffsetsHeapSelfTest.class);
         suite.addTestSuite(BinaryFooterOffsetsOffheapSelfTest.class);
+        suite.addTestSuite(BinaryEnumsSelfTest.class);
         suite.addTestSuite(GridPortableMetaDataSelfTest.class);
         suite.addTestSuite(GridPortableAffinityKeySelfTest.class);
         suite.addTestSuite(GridPortableWildcardsSelfTest.class);


[2/4] ignite git commit: IGNITE-1956: Tests start passing.

Posted by vo...@apache.org.
IGNITE-1956: Tests start passing.


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

Branch: refs/heads/ignite-1956
Commit: 642218dccbd5aff7a2cb1a4489d80cb2cf3bc113
Parents: ed3bd2b
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Nov 24 16:50:39 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Nov 24 16:50:39 2015 +0300

----------------------------------------------------------------------
 .../communication/GridIoMessageFactory.java     |  8 ++-
 .../internal/portable/BinaryEnumObjectImpl.java | 76 +++++++++++++++++---
 .../internal/portable/BinaryEnumsSelfTest.java  | 10 +--
 3 files changed, 81 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/642218dc/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index 02bd5ec..c9b8e27 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -31,6 +31,7 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
 import org.apache.ignite.internal.managers.deployment.GridDeploymentRequest;
 import org.apache.ignite.internal.managers.deployment.GridDeploymentResponse;
 import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage;
+import org.apache.ignite.internal.portable.BinaryEnumObjectImpl;
 import org.apache.ignite.internal.portable.BinaryObjectImpl;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection;
@@ -714,7 +715,12 @@ public class GridIoMessageFactory implements MessageFactory {
 
                 break;
 
-            // [-3..118] - this
+            case 119:
+                msg = new BinaryEnumObjectImpl();
+
+                break;
+
+            // [-3..119] - this
             // [120..123] - DR
             // [-4..-22] - SQL
             default:

http://git-wip-us.apache.org/repos/asf/ignite/blob/642218dc/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
index 66b080a..fe2dea7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
@@ -21,6 +21,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridDirectTransient;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
@@ -40,6 +41,7 @@ import java.nio.ByteBuffer;
  */
 public class BinaryEnumObjectImpl implements BinaryObject, Externalizable, CacheObject {
     /** Context. */
+    @GridDirectTransient
     private PortableContext ctx;
 
     /** Type ID. */
@@ -224,25 +226,83 @@ public class BinaryEnumObjectImpl implements BinaryObject, Externalizable, Cache
 
     /** {@inheritDoc} */
     @Override public byte directType() {
-        // TODO
-        return 0;
+        return 119;
     }
 
     /** {@inheritDoc} */
     @Override public byte fieldsCount() {
-        // TODO
-        return 0;
+        return 3;
     }
 
     /** {@inheritDoc} */
     @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
-        // TODO
-        return false;
+        writer.setBuffer(buf);
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeString("clsName", clsName))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeInt("ord", ord))
+                    return false;
+
+                writer.incrementState();
+
+            case 2:
+                if (!writer.writeInt("typeId", typeId))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
     }
 
     /** {@inheritDoc} */
     @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
-        // TODO
-        return false;
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                clsName = reader.readString("clsName");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                ord = reader.readInt("ord");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 2:
+                typeId = reader.readInt("typeId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return reader.afterMessageRead(BinaryEnumObjectImpl.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/642218dc/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
index 3abf436..9b2cb84 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
@@ -120,10 +120,6 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
     public void testSimpleRegistered() throws Exception{
         startUp(true);
 
-        cache1.put(0, new EnumHolder(EnumType.ONE));
-
-        Object res = cache1.get(0);
-
         cache1.put(1, EnumType.ONE);
 
         assertEquals(EnumType.ONE, cache1.get(1));
@@ -134,6 +130,12 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
         assertTrue(obj.type().isEnum());
         assertEquals(node1.binary().typeId(EnumType.class.getName()), obj.typeId());
         assertEquals(EnumType.ONE.ordinal(), obj.enumOrdinal());
+
+        obj = cacheBinary2.get(1);
+
+        assertTrue(obj.type().isEnum());
+        assertEquals(node1.binary().typeId(EnumType.class.getName()), obj.typeId());
+        assertEquals(EnumType.ONE.ordinal(), obj.enumOrdinal());
     }
 
     /**


[4/4] ignite git commit: IGNITE-1956: Fixed bug in portables unwrapping + additional test.

Posted by vo...@apache.org.
IGNITE-1956: Fixed bug in portables unwrapping + additional test.


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

Branch: refs/heads/ignite-1956
Commit: 0dec2b9ed2fe31a435ceb42a2e2eee454401281d
Parents: b5fe345
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Tue Nov 24 17:49:44 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Nov 24 17:49:44 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryWriterExImpl.java   |  2 +
 .../portable/PortableClassDescriptor.java       |  1 +
 .../processors/cache/CacheObjectContext.java    | 19 +++++
 .../internal/portable/BinaryEnumsSelfTest.java  | 82 +++++++++++++++++---
 4 files changed, 95 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0dec2b9e/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index be10849..9d1d037 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -817,6 +817,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
         if (typeId == UNREGISTERED_TYPE_ID)
             doWriteString(val.className());
+
+        out.writeInt(val.enumOrdinal());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/0dec2b9e/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
index 2e9c57e..910b6f6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
@@ -209,6 +209,7 @@ public class PortableClassDescriptor {
             case MAP_ENTRY:
             case PORTABLE_OBJ:
             case ENUM:
+            case PORTABLE_ENUM:
             case ENUM_ARR:
             case CLASS:
             case EXCLUSION:

http://git-wip-us.apache.org/repos/asf/ignite/blob/0dec2b9e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index b3d2d4e..61a20fb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -176,6 +176,23 @@ import org.apache.ignite.internal.util.typedef.F;
     }
 
     /**
+     * Unwrap array of portables if needed.
+     *
+     * @param arr Array.
+     * @param keepPortable Keep portable flag.
+     * @param cpy Copy.
+     * @return Result.
+     */
+    public Object[] unwrapPortablesInArrayIfNeeded(Object[] arr, boolean keepPortable, boolean cpy) {
+        Object[] res = new Object[arr.length];
+
+        for (int i = 0; i < arr.length; i++)
+            res[i] = unwrapPortable(arr[i], keepPortable, cpy);
+
+        return res;
+    }
+
+    /**
      * Unwraps map.
      *
      * @param map Map to unwrap.
@@ -252,6 +269,8 @@ import org.apache.ignite.internal.util.typedef.F;
             return unwrapPortablesIfNeeded((Collection<Object>)o, keepPortable, cpy);
         else if (o instanceof Map)
             return unwrapPortablesIfNeeded((Map<Object, Object>)o, keepPortable, cpy);
+        else if (o instanceof Object[])
+            return unwrapPortablesInArrayIfNeeded((Object[])o, keepPortable, cpy);
         else if (o instanceof CacheObject) {
             CacheObject co = (CacheObject)o;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/0dec2b9e/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
index c5a4c90..79f4dec 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
@@ -54,10 +54,10 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
     private IgniteCache cache2;
 
     /** Binary cache 1. */
-    private IgniteCache<Integer, BinaryObject> cacheBinary1;
+    private IgniteCache cacheBinary1;
 
     /** Binary cache 2. */
-    private IgniteCache<Integer, BinaryObject> cacheBinary2;
+    private IgniteCache cacheBinary2;
 
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
@@ -178,6 +178,64 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
         validateSimple();
     }
 
+
+    /**
+     * Test enum array created using builder (registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testBuilderArrayRegistered() throws Exception {
+        checkBuilderArray(true);
+    }
+
+    /**
+     * Test enum array created using builder (not registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testBuilderArrayNotRegistered() throws Exception {
+        checkBuilderArray(false);
+    }
+
+    /**
+     * Check arrays with builder.
+     *
+     * @param registered Registered flag.
+     * @throws Exception If failed.
+     */
+    public void checkBuilderArray(boolean registered) throws Exception {
+        startUp(registered);
+
+        BinaryObject binaryOne = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.ONE.ordinal());
+        BinaryObject binaryTwo = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.TWO.ordinal());
+
+        cacheBinary1.put(1, new BinaryObject[] { binaryOne, binaryTwo });
+
+        Object[] arr1 = (Object[])cache1.get(1);
+        Object[] arr2 = (Object[])cache2.get(1);
+
+        assertEquals(2, arr1.length);
+        assertEquals(2, arr2.length);
+
+        assertEquals(EnumType.ONE, arr1[0]);
+        assertEquals(EnumType.TWO, arr1[1]);
+
+        assertEquals(EnumType.ONE, arr2[0]);
+        assertEquals(EnumType.TWO, arr2[1]);
+
+        Object[] arrBinary1 = (Object[])cacheBinary1.get(1);
+        Object[] arrBinary2 = (Object[])cacheBinary2.get(1);
+
+        assertEquals(2, arr1.length);
+        assertEquals(2, arr2.length);
+
+        validateValue((BinaryObject)arrBinary1[0], EnumType.ONE);
+        validateValue((BinaryObject)arrBinary1[1], EnumType.TWO);
+
+        validateValue((BinaryObject)arrBinary2[0], EnumType.ONE);
+        validateValue((BinaryObject)arrBinary2[1], EnumType.TWO);
+    }
+
     /**
      * Internal check routine for simple scenario.
      *
@@ -187,17 +245,23 @@ public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
         assertEquals(EnumType.ONE, cache1.get(1));
         assertEquals(EnumType.ONE, cache2.get(1));
 
-        BinaryObject obj = cacheBinary1.get(1);
+        validateValue((BinaryObject)cacheBinary1.get(1), EnumType.ONE);
+        validateValue((BinaryObject)cacheBinary2.get(1), EnumType.ONE);
+    }
 
+    /**
+     * Validate single value.
+     *
+     * @param obj Binary value.
+     * @param val Expected value.
+     */
+    private void validateValue(BinaryObject obj, EnumType val) {
         assertTrue(obj.type().isEnum());
-        assertEquals(node1.binary().typeId(EnumType.class.getName()), obj.typeId());
-        assertEquals(EnumType.ONE.ordinal(), obj.enumOrdinal());
-
-        obj = cacheBinary2.get(1);
 
-        assertTrue(obj.type().isEnum());
         assertEquals(node1.binary().typeId(EnumType.class.getName()), obj.typeId());
-        assertEquals(EnumType.ONE.ordinal(), obj.enumOrdinal());
+        assertEquals(node2.binary().typeId(EnumType.class.getName()), obj.typeId());
+
+        assertEquals(val.ordinal(), obj.enumOrdinal());
     }
 
     /**