ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [19/19] ignite git commit: IGNITE-2450 - Added test
Date Wed, 03 Feb 2016 03:25:00 GMT
IGNITE-2450 - Added test


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

Branch: refs/heads/ignite-2450
Commit: 7e936135bdc1c4fca13e0ad70ca8781ec3e0037d
Parents: d66e541
Author: Valentin Kulichenko <valentin.kulichenko@gmail.com>
Authored: Tue Feb 2 19:22:58 2016 -0800
Committer: Valentin Kulichenko <valentin.kulichenko@gmail.com>
Committed: Tue Feb 2 19:22:58 2016 -0800

----------------------------------------------------------------------
 ...namicProxySerializationMultiJvmSelfTest.java | 122 +++++++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   3 +
 2 files changed, 125 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7e936135/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
new file mode 100644
index 0000000..c5bd892
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/DynamicProxySerializationMultiJvmSelfTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.marshaller;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Multi-JVM test for dynamic proxy serialization.
+ */
+public class DynamicProxySerializationMultiJvmSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static boolean optMarsh;
+
+    /** {@inheritDoc} */
+    @Override protected boolean isMultiJvm() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (optMarsh)
+            cfg.setMarshaller(new OptimizedMarshaller(false));
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOptimized() throws Exception {
+        optMarsh = true;
+
+        doTest();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBinary() throws Exception {
+        optMarsh = false;
+
+        doTest();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void doTest() throws Exception {
+        try {
+            Ignite ignite = startGrids(2);
+
+            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;
+
+                        throw new IllegalStateException();
+                    }
+                });
+
+            int val = ignite.compute(ignite.cluster().forRemotes()).call(new MyCallable(p));
+
+            assertEquals(42, val);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
+     */
+    private static class MyCallable implements IgniteCallable<Integer> {
+        /** */
+        private final MyProxy p;
+
+        /**
+         * @param p Proxy.
+         */
+        public MyCallable(MyProxy p) {
+            this.p = p;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer call() throws Exception {
+            return p.value();
+        }
+    }
+
+    /**
+     */
+    private static interface MyProxy {
+        /**
+         * @return Value.
+         */
+        public int value();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/7e936135/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index dece258..e26c5dd 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -44,6 +44,7 @@ import org.apache.ignite.internal.processors.service.ClosureServiceClientsNodesT
 import org.apache.ignite.internal.product.GridProductVersionSelfTest;
 import org.apache.ignite.internal.util.nio.IgniteExceptionInNioWorkerSelfTest;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.DynamicProxySerializationMultiJvmSelfTest;
 import org.apache.ignite.messaging.GridMessagingNoPeerClassLoadingSelfTest;
 import org.apache.ignite.messaging.GridMessagingSelfTest;
 import org.apache.ignite.messaging.IgniteMessagingWithClientTest;
@@ -116,6 +117,8 @@ public class IgniteBasicTestSuite extends TestSuite {
 
         suite.addTestSuite(IgniteExceptionInNioWorkerSelfTest.class);
 
+        suite.addTestSuite(DynamicProxySerializationMultiJvmSelfTest.class);
+
         return suite;
     }
 }


Mime
View raw message