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/02/26 14:16:48 UTC
[30/35] ignite git commit: IGNITE-2450 - More fixes for Proxy
serialization
IGNITE-2450 - More fixes for Proxy serialization
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e1176fda
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e1176fda
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e1176fda
Branch: refs/heads/ignite-2407
Commit: e1176fda8c07e0839952f2b740c2327c125ec37d
Parents: 53fe993
Author: Valentin Kulichenko <va...@gmail.com>
Authored: Thu Feb 25 16:34:03 2016 -0800
Committer: Valentin Kulichenko <va...@gmail.com>
Committed: Thu Feb 25 16:34:03 2016 -0800
----------------------------------------------------------------------
.../ignite/internal/binary/BinaryUtils.java | 7 +-
...namicProxySerializationMultiJvmSelfTest.java | 106 +++++++++++++++----
2 files changed, 89 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e1176fda/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
index d5b0854..4a79f22 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -584,7 +584,9 @@ public class BinaryUtils {
public static boolean isBinaryType(Class<?> cls) {
assert cls != null;
- return BinaryObject.class.isAssignableFrom(cls) || BINARY_CLS.contains(cls);
+ return BinaryObject.class.isAssignableFrom(cls) ||
+ Proxy.class.isAssignableFrom(cls) ||
+ BINARY_CLS.contains(cls);
}
/**
@@ -1758,6 +1760,9 @@ public class BinaryUtils {
case GridBinaryMarshaller.CLASS:
return doReadClass(in, ctx, ldr);
+ case GridBinaryMarshaller.PROXY:
+ return doReadProxy(in, ctx, ldr, handles);
+
case GridBinaryMarshaller.OPTM_MARSH:
return doReadOptimized(in, ctx, ldr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/e1176fda/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
index d22aeac..0400de4 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
@@ -22,6 +22,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.Callable;
import org.apache.ignite.Ignite;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.lang.IgniteCallable;
@@ -49,68 +50,111 @@ public class DynamicProxySerializationMultiJvmSelfTest extends GridCommonAbstrac
return cfg;
}
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+ }
+
/**
* @throws Exception If failed.
*/
- public void testOptimized() throws Exception {
+ public void testOptimizedMarshaller() throws Exception {
marshFactory = new Callable<Marshaller>() {
@Override public Marshaller call() throws Exception {
return new OptimizedMarshaller(false);
}
};
- doTest();
+ doTestMarshaller();
}
/**
* @throws Exception If failed.
*/
- public void testBinary() throws Exception {
+ public void testBinaryMarshaller() throws Exception {
marshFactory = new Callable<Marshaller>() {
@Override public Marshaller call() throws Exception {
return new BinaryMarshaller();
}
};
- doTest();
+ doTestMarshaller();
}
/**
* @throws Exception If failed.
*/
- private void doTest() throws Exception {
- try {
- Ignite ignite = startGrids(2);
+ public void testToBinary() throws Exception {
+ marshFactory = new Callable<Marshaller>() {
+ @Override public Marshaller call() throws Exception {
+ return new BinaryMarshaller();
+ }
+ };
- MyProxy p = (MyProxy)Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class[] { MyProxy.class }, new InvocationHandler() {
- @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if ("value".equals(method.getName()))
- return 42;
+ Ignite ignite = startGrid(0);
- throw new IllegalStateException();
- }
- });
+ MyProxy p = create();
- int val = ignite.compute(ignite.cluster().forRemotes()).call(new MyCallable(p));
+ MyProxy p0 = ignite.binary().toBinary(p);
- assertEquals(42, val);
- }
- finally {
- stopAllGrids();
- }
+ assertSame(p, p0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBinaryField() throws Exception {
+ marshFactory = new Callable<Marshaller>() {
+ @Override public Marshaller call() throws Exception {
+ return new BinaryMarshaller();
+ }
+ };
+
+ Ignite ignite = startGrids(2);
+
+ BinaryObject bo = ignite.binary().builder("ProxyWrapper").setField("proxy", create()).build();
+
+ int val = ignite.compute(ignite.cluster().forRemotes()).call(new FieldTestCallable(bo));
+
+ assertEquals(42, val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ private void doTestMarshaller() throws Exception {
+ Ignite ignite = startGrids(2);
+
+ int val = ignite.compute(ignite.cluster().forRemotes()).call(new MarshallerTestCallable(create()));
+
+ assertEquals(42, val);
+ }
+
+ /**
+ * @return New proxy.
+ */
+ private static MyProxy create() {
+ return (MyProxy)Proxy.newProxyInstance(DynamicProxySerializationMultiJvmSelfTest.class.getClassLoader(),
+ new Class[] { MyProxy.class }, new InvocationHandler() {
+ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ("value".equals(method.getName()))
+ return 42;
+
+ throw new IllegalStateException();
+ }
+ });
}
/**
*/
- private static class MyCallable implements IgniteCallable<Integer> {
+ private static class MarshallerTestCallable implements IgniteCallable<Integer> {
/** */
private final MyProxy p;
/**
* @param p Proxy.
*/
- public MyCallable(MyProxy p) {
+ public MarshallerTestCallable(MyProxy p) {
this.p = p;
}
@@ -122,6 +166,22 @@ public class DynamicProxySerializationMultiJvmSelfTest extends GridCommonAbstrac
/**
*/
+ private static class FieldTestCallable implements IgniteCallable<Integer> {
+ /** */
+ private final BinaryObject bo;
+
+ public FieldTestCallable(BinaryObject bo) {
+ this.bo = bo;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Integer call() throws Exception {
+ return bo.<MyProxy>field("proxy").value();
+ }
+ }
+
+ /**
+ */
private static interface MyProxy {
/**
* @return Value.