You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/09/23 16:05:51 UTC
[17/27] ignite git commit: IGNITE-3892 - Fixed bug in
BinaryWriterExImpl.doWriteClass() method
IGNITE-3892 - Fixed bug in BinaryWriterExImpl.doWriteClass() method
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e3827a40
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e3827a40
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e3827a40
Branch: refs/heads/ignite-comm-balance
Commit: e3827a40bcbd54664cc0688e8e6ec57e4e328172
Parents: 4ee52f0
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Wed Sep 21 16:07:02 2016 -0700
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Wed Sep 21 16:07:02 2016 -0700
----------------------------------------------------------------------
.../internal/binary/BinaryWriterExImpl.java | 21 ++++----
.../binary/BinaryMarshallerSelfTest.java | 53 ++++++++++++++++----
.../marshaller/MarshallerContextTestImpl.java | 28 +++++++++--
3 files changed, 77 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3827a40/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index 21fb2bf..1a81819 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -17,16 +17,6 @@
package org.apache.ignite.internal.binary;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream;
-import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.jetbrains.annotations.Nullable;
-
import java.io.IOException;
import java.io.ObjectOutput;
import java.lang.reflect.InvocationHandler;
@@ -38,6 +28,15 @@ import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.jetbrains.annotations.Nullable;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -823,7 +822,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
else {
out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
- doWriteString(val.getClass().getName());
+ doWriteString(val.getName());
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3827a40/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index b347ec0..f415472 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -2648,7 +2648,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
*/
public void testDuplicateNameSimpleNameMapper() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true),
- new BinaryBasicIdMapper(true), null, null);
+ new BinaryBasicIdMapper(true), null, null, null);
Test1.Job job1 = new Test1().new Job();
Test2.Job job2 = new Test2().new Job();
@@ -2672,7 +2672,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
*/
public void testDuplicateNameFullNameMapper() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false),
- new BinaryBasicIdMapper(false), null, null);
+ new BinaryBasicIdMapper(false), null, null, null);
Test1.Job job1 = new Test1().new Job();
Test2.Job job2 = new Test2().new Job();
@@ -2911,6 +2911,17 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
}
/**
+ * @throws Exception If failed.
+ */
+ public void testUnregisteredClass() throws Exception {
+ BinaryMarshaller m = binaryMarshaller(null, Collections.singletonList(Value.class.getName()));
+
+ ClassFieldObject res = m.unmarshal(m.marshal(new ClassFieldObject(Value.class)), null);
+
+ assertEquals(Value.class, res.cls);
+ }
+
+ /**
*
*/
private static interface SomeItf {
@@ -3227,9 +3238,8 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
/**
*
*/
- protected BinaryMarshaller binaryMarshaller()
- throws IgniteCheckedException {
- return binaryMarshaller(null, null, null, null);
+ protected BinaryMarshaller binaryMarshaller() throws IgniteCheckedException {
+ return binaryMarshaller(null, null, null, null, null);
}
/**
@@ -3237,7 +3247,15 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
*/
protected BinaryMarshaller binaryMarshaller(Collection<BinaryTypeConfiguration> cfgs)
throws IgniteCheckedException {
- return binaryMarshaller(null, null, null, cfgs);
+ return binaryMarshaller(null, null, null, cfgs, null);
+ }
+
+ /**
+ *
+ */
+ protected BinaryMarshaller binaryMarshaller(Collection<BinaryTypeConfiguration> cfgs,
+ Collection<String> excludedClasses) throws IgniteCheckedException {
+ return binaryMarshaller(null, null, null, cfgs, excludedClasses);
}
/**
@@ -3246,7 +3264,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
protected BinaryMarshaller binaryMarshaller(BinaryNameMapper nameMapper, BinaryIdMapper mapper,
Collection<BinaryTypeConfiguration> cfgs)
throws IgniteCheckedException {
- return binaryMarshaller(nameMapper, mapper, null, cfgs);
+ return binaryMarshaller(nameMapper, mapper, null, cfgs, null);
}
/**
@@ -3254,7 +3272,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
*/
protected BinaryMarshaller binaryMarshaller(BinarySerializer serializer, Collection<BinaryTypeConfiguration> cfgs)
throws IgniteCheckedException {
- return binaryMarshaller(null, null, serializer, cfgs);
+ return binaryMarshaller(null, null, serializer, cfgs, null);
}
/**
@@ -3264,7 +3282,8 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
BinaryNameMapper nameMapper,
BinaryIdMapper mapper,
BinarySerializer serializer,
- Collection<BinaryTypeConfiguration> cfgs
+ Collection<BinaryTypeConfiguration> cfgs,
+ Collection<String> excludedClasses
) throws IgniteCheckedException {
IgniteConfiguration iCfg = new IgniteConfiguration();
@@ -3283,7 +3302,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
BinaryMarshaller marsh = new BinaryMarshaller();
- marsh.setContext(new MarshallerContextTestImpl(null));
+ marsh.setContext(new MarshallerContextTestImpl(null, excludedClasses));
IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
@@ -4885,4 +4904,18 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
/**
*/
private static class SingleHandleB {}
+
+ /**
+ */
+ private static class ClassFieldObject {
+ /** */
+ private Class<?> cls;
+
+ /**
+ * @param cls Class field.
+ */
+ public ClassFieldObject(Class<?> cls) {
+ this.cls = cls;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e3827a40/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
index c600ca4..9ff127d 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
@@ -17,11 +17,13 @@
package org.apache.ignite.marshaller;
+import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.MarshallerContextAdapter;
import org.apache.ignite.plugin.PluginProvider;
+import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
/**
@@ -29,26 +31,44 @@ import org.jsr166.ConcurrentHashMap8;
*/
public class MarshallerContextTestImpl extends MarshallerContextAdapter {
/** */
- private final static ConcurrentMap<Integer, String> map = new ConcurrentHashMap8<>();
+ private static final ConcurrentMap<Integer, String> map = new ConcurrentHashMap8<>();
+
+ /** */
+ private final Collection<String> excluded;
/**
* Initializes context.
*
* @param plugins Plugins.
+ * @param excluded Excluded classes.
*/
- public MarshallerContextTestImpl(List<PluginProvider> plugins) {
+ public MarshallerContextTestImpl(@Nullable List<PluginProvider> plugins, Collection<String> excluded) {
super(plugins);
+
+ this.excluded = excluded;
+ }
+
+ /**
+ * Initializes context.
+ *
+ * @param plugins Plugins.
+ */
+ public MarshallerContextTestImpl(List<PluginProvider> plugins) {
+ this(plugins, null);
}
/**
* Initializes context.
*/
public MarshallerContextTestImpl() {
- super(null);
+ this(null);
}
/** {@inheritDoc} */
@Override protected boolean registerClassName(int id, String clsName) throws IgniteCheckedException {
+ if (excluded != null && excluded.contains(clsName))
+ return false;
+
String oldClsName = map.putIfAbsent(id, clsName);
if (oldClsName != null && !oldClsName.equals(clsName))
@@ -69,4 +89,4 @@ public class MarshallerContextTestImpl extends MarshallerContextAdapter {
public ConcurrentMap<Integer, String> internalMap() {
return map;
}
-}
\ No newline at end of file
+}