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:49:00 UTC
[4/4] ignite git commit: IGNITE-1956: Fixed bug in portables
unwrapping + additional test.
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());
}
/**