ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/2] ignite git commit: ignite-2042 Added special queue/set key classes to make collocation work with BinaryMarshaller.
Date Thu, 03 Dec 2015 09:48:39 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1537 415aa5cd8 -> 72eb89414


ignite-2042 Added special queue/set key classes to make collocation work with BinaryMarshaller.


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

Branch: refs/heads/ignite-1537
Commit: 8444c9abb543ca4ab30555f4b663cdf289d779d1
Parents: 415aa5c
Author: sboikov <sboikov@gridgain.com>
Authored: Thu Dec 3 11:26:25 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Thu Dec 3 11:26:25 2015 +0300

----------------------------------------------------------------------
 .../cache/IgniteCacheInvokeAbstractTest.java    | 369 ++++++++++++++-----
 1 file changed, 270 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8444c9ab/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeAbstractTest.java
index b881d90..51a70b9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeAbstractTest.java
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Callable;
@@ -139,6 +140,31 @@ public abstract class IgniteCacheInvokeAbstractTest extends IgniteCacheAbstractT
 
             tx = startTx(txMode);
 
+            TestValue testVal = cache.invoke(key, new UserClassValueProcessor());
+
+            if (tx != null)
+                tx.commit();
+
+            assertEquals("63", testVal.value());
+
+            checkValue(key, 63);
+
+            tx = startTx(txMode);
+
+            Collection<TestValue> testValCol = cache.invoke(key, new CollectionReturnProcessor());
+
+            if (tx != null)
+                tx.commit();
+
+            assertEquals(10, testValCol.size());
+
+            for (TestValue val : testValCol)
+                assertEquals("64", val.value());
+
+            checkValue(key, 63);
+
+            tx = startTx(txMode);
+
             GridTestUtils.assertThrows(log, new Callable<Void>() {
                 @Override public Void call() throws Exception {
                     cache.invoke(key, new ExceptionProcessor(63));
@@ -237,166 +263,226 @@ public abstract class IgniteCacheInvokeAbstractTest extends IgniteCacheAbstractT
 
         IncrementProcessor incProcessor = new IncrementProcessor();
 
-        Transaction tx = startTx(txMode);
+        {
+            Transaction tx = startTx(txMode);
 
-        Map<Integer, EntryProcessorResult<Integer>> resMap = cache.invokeAll(keys,
incProcessor);
+            Map<Integer, EntryProcessorResult<Integer>> resMap = cache.invokeAll(keys,
incProcessor);
 
-        if (tx != null)
-            tx.commit();
+            if (tx != null)
+                tx.commit();
 
-        Map<Object, Object> exp = new HashMap<>();
+            Map<Object, Object> exp = new HashMap<>();
 
-        for (Integer key : keys)
-            exp.put(key, -1);
+            for (Integer key : keys)
+                exp.put(key, -1);
 
-        checkResult(resMap, exp);
+            checkResult(resMap, exp);
 
-        for (Integer key : keys)
-            checkValue(key, 1);
+            for (Integer key : keys)
+                checkValue(key, 1);
+        }
 
-        tx = startTx(txMode);
+        {
+            Transaction tx = startTx(txMode);
 
-        resMap = cache.invokeAll(keys, incProcessor);
+            Map<Integer, EntryProcessorResult<TestValue>> resMap = cache.invokeAll(keys,
new UserClassValueProcessor());
 
-        if (tx != null)
-            tx.commit();
+            if (tx != null)
+                tx.commit();
 
-        exp = new HashMap<>();
+            Map<Object, Object> exp = new HashMap<>();
 
-        for (Integer key : keys)
-            exp.put(key, 1);
+            for (Integer key : keys)
+                exp.put(key, new TestValue("1"));
 
-        checkResult(resMap, exp);
+            checkResult(resMap, exp);
 
-        for (Integer key : keys)
-            checkValue(key, 2);
+            for (Integer key : keys)
+                checkValue(key, 1);
+        }
 
-        tx = startTx(txMode);
+        {
+            Transaction tx = startTx(txMode);
 
-        resMap = cache.invokeAll(keys, new ArgumentsSumProcessor(), 10, 20, 30);
+            Map<Integer, EntryProcessorResult<Collection<TestValue>>> resMap
=
+                cache.invokeAll(keys, new CollectionReturnProcessor());
 
-        if (tx != null)
-            tx.commit();
+            if (tx != null)
+                tx.commit();
 
-        for (Integer key : keys)
-            exp.put(key, 3);
+            Map<Object, Object> exp = new HashMap<>();
 
-        checkResult(resMap, exp);
+            for (Integer key : keys) {
+                List<TestValue> expCol = new ArrayList<>();
 
-        for (Integer key : keys)
-            checkValue(key, 62);
+                for (int i = 0; i < 10; i++)
+                    expCol.add(new TestValue("2"));
 
-        tx = startTx(txMode);
+                exp.put(key, expCol);
+            }
 
-        resMap = cache.invokeAll(keys, new ExceptionProcessor(null));
+            checkResult(resMap, exp);
 
-        if (tx != null)
-            tx.commit();
+            for (Integer key : keys)
+                checkValue(key, 1);
+        }
 
-        for (Integer key : keys) {
-            final EntryProcessorResult<Integer> res = resMap.get(key);
+        {
+            Transaction tx = startTx(txMode);
 
-            assertNotNull("No result for " + key);
+            Map<Integer, EntryProcessorResult<Integer>> resMap = cache.invokeAll(keys,
incProcessor);
 
-            GridTestUtils.assertThrows(log, new Callable<Void>() {
-                @Override public Void call() throws Exception {
-                    res.get();
+            if (tx != null)
+                tx.commit();
 
-                    return null;
-                }
-            }, EntryProcessorException.class, "Test processor exception.");
+            Map<Object, Object> exp = new HashMap<>();
+
+            for (Integer key : keys)
+                exp.put(key, 1);
+
+            checkResult(resMap, exp);
+
+            for (Integer key : keys)
+                checkValue(key, 2);
         }
 
-        for (Integer key : keys)
-            checkValue(key, 62);
+        {
+            Transaction tx = startTx(txMode);
 
-        tx = startTx(txMode);
+            Map<Integer, EntryProcessorResult<Integer>> resMap =
+                cache.invokeAll(keys, new ArgumentsSumProcessor(), 10, 20, 30);
 
-        Map<Integer, EntryProcessor<Integer, Integer, Integer>> invokeMap = new
HashMap<>();
+            if (tx != null)
+                tx.commit();
+
+            Map<Object, Object> exp = new HashMap<>();
+
+            for (Integer key : keys)
+                exp.put(key, 3);
+
+            checkResult(resMap, exp);
+
+            for (Integer key : keys)
+                checkValue(key, 62);
+        }
+
+        {
+            Transaction tx = startTx(txMode);
 
-        for (Integer key : keys) {
-            switch (key % 4) {
-                case 0: invokeMap.put(key, new IncrementProcessor()); break;
+            Map<Integer, EntryProcessorResult<Integer>> resMap = cache.invokeAll(keys,
new ExceptionProcessor(null));
 
-                case 1: invokeMap.put(key, new RemoveProcessor(62)); break;
+            if (tx != null)
+                tx.commit();
 
-                case 2: invokeMap.put(key, new ArgumentsSumProcessor()); break;
+            for (Integer key : keys) {
+                final EntryProcessorResult<Integer> res = resMap.get(key);
 
-                case 3: invokeMap.put(key, new ExceptionProcessor(62)); break;
+                assertNotNull("No result for " + key);
 
-                default:
-                    fail();
+                GridTestUtils.assertThrows(log, new Callable<Void>() {
+                    @Override public Void call() throws Exception {
+                        res.get();
+
+                        return null;
+                    }
+                }, EntryProcessorException.class, "Test processor exception.");
             }
+
+            for (Integer key : keys)
+                checkValue(key, 62);
         }
 
-        resMap = cache.invokeAll(invokeMap, 10, 20, 30);
+        {
+            Transaction tx = startTx(txMode);
 
-        if (tx != null)
-            tx.commit();
+            Map<Integer, EntryProcessor<Integer, Integer, Integer>> invokeMap
= new HashMap<>();
 
-        for (Integer key : keys) {
-            final EntryProcessorResult<Integer> res = resMap.get(key);
+            for (Integer key : keys) {
+                switch (key % 4) {
+                    case 0: invokeMap.put(key, new IncrementProcessor()); break;
 
-            switch (key % 4) {
-                case 0: {
-                    assertNotNull("No result for " + key, res);
+                    case 1: invokeMap.put(key, new RemoveProcessor(62)); break;
 
-                    assertEquals(62, (int)res.get());
+                    case 2: invokeMap.put(key, new ArgumentsSumProcessor()); break;
 
-                    checkValue(key, 63);
+                    case 3: invokeMap.put(key, new ExceptionProcessor(62)); break;
 
-                    break;
+                    default:
+                        fail();
                 }
+            }
 
-                case 1: {
-                    assertNull(res);
+            Map<Integer, EntryProcessorResult<Integer>> resMap = cache.invokeAll(invokeMap,
10, 20, 30);
 
-                    checkValue(key, null);
+            if (tx != null)
+                tx.commit();
 
-                    break;
-                }
+            for (Integer key : keys) {
+                final EntryProcessorResult<Integer> res = resMap.get(key);
 
-                case 2: {
-                    assertNotNull("No result for " + key, res);
+                switch (key % 4) {
+                    case 0: {
+                        assertNotNull("No result for " + key, res);
 
-                    assertEquals(3, (int)res.get());
+                        assertEquals(62, (int)res.get());
 
-                    checkValue(key, 122);
+                        checkValue(key, 63);
 
-                    break;
-                }
+                        break;
+                    }
+
+                    case 1: {
+                        assertNull(res);
+
+                        checkValue(key, null);
+
+                        break;
+                    }
+
+                    case 2: {
+                        assertNotNull("No result for " + key, res);
+
+                        assertEquals(3, (int)res.get());
+
+                        checkValue(key, 122);
 
-                case 3: {
-                    assertNotNull("No result for " + key, res);
+                        break;
+                    }
 
-                    GridTestUtils.assertThrows(log, new Callable<Void>() {
-                        @Override public Void call() throws Exception {
-                            res.get();
+                    case 3: {
+                        assertNotNull("No result for " + key, res);
 
-                            return null;
-                        }
-                    }, EntryProcessorException.class, "Test processor exception.");
+                        GridTestUtils.assertThrows(log, new Callable<Void>() {
+                            @Override public Void call() throws Exception {
+                                res.get();
 
-                    checkValue(key, 62);
+                                return null;
+                            }
+                        }, EntryProcessorException.class, "Test processor exception.");
 
-                    break;
+                        checkValue(key, 62);
+
+                        break;
+                    }
                 }
             }
         }
 
         cache.invokeAll(keys, new IncrementProcessor());
 
-        tx = startTx(txMode);
+        {
+            Transaction tx = startTx(txMode);
 
-        resMap = cache.invokeAll(keys, new RemoveProcessor(null));
+            Map<Integer, EntryProcessorResult<Integer>> resMap = cache.invokeAll(keys,
new RemoveProcessor(null));
 
-        if (tx != null)
-            tx.commit();
+            if (tx != null)
+                tx.commit();
 
-        assertEquals("Unexpected results: " + resMap, 0, resMap.size());
+            assertEquals("Unexpected results: " + resMap, 0, resMap.size());
 
-        for (Integer key : keys)
-            checkValue(key, null);
+            for (Integer key : keys)
+                checkValue(key, null);
+        }
 
         IgniteCache<Integer, Integer> asyncCache = cache.withAsync();
 
@@ -406,9 +492,9 @@ public abstract class IgniteCacheInvokeAbstractTest extends IgniteCacheAbstractT
 
         IgniteFuture<Map<Integer, EntryProcessorResult<Integer>>> fut =
asyncCache.future();
 
-        resMap = fut.get();
+        Map<Integer, EntryProcessorResult<Integer>> resMap = fut.get();
 
-        exp = new HashMap<>();
+        Map<Object, Object> exp = new HashMap<>();
 
         for (Integer key : keys)
             exp.put(key, -1);
@@ -418,7 +504,7 @@ public abstract class IgniteCacheInvokeAbstractTest extends IgniteCacheAbstractT
         for (Integer key : keys)
             checkValue(key, 1);
 
-        invokeMap = new HashMap<>();
+        Map<Integer, EntryProcessor<Integer, Integer, Integer>> invokeMap = new
HashMap<>();
 
         for (Integer key : keys)
             invokeMap.put(key, incProcessor);
@@ -442,15 +528,16 @@ public abstract class IgniteCacheInvokeAbstractTest extends IgniteCacheAbstractT
      * @param resMap Result map.
      * @param exp Expected results.
      */
-    private void checkResult(Map<Integer, EntryProcessorResult<Integer>> resMap,
Map<Object, Object> exp) {
+    @SuppressWarnings("unchecked")
+    private void checkResult(Map resMap, Map<Object, Object> exp) {
         assertNotNull(resMap);
 
         assertEquals(exp.size(), resMap.size());
 
         for (Map.Entry<Object, Object> expVal : exp.entrySet()) {
-            EntryProcessorResult<Integer> res = resMap.get(expVal.getKey());
+            EntryProcessorResult<?> res = (EntryProcessorResult)resMap.get(expVal.getKey());
 
-            assertNotNull("No result for " + expVal.getKey());
+            assertNotNull("No result for " + expVal.getKey(), res);
 
             assertEquals("Unexpected result for " + expVal.getKey(), res.get(), expVal.getValue());
         }
@@ -557,6 +644,44 @@ public abstract class IgniteCacheInvokeAbstractTest extends IgniteCacheAbstractT
     /**
      *
      */
+    protected static class UserClassValueProcessor implements EntryProcessor<Integer,
Integer, TestValue> {
+        /** {@inheritDoc} */
+        @Override public TestValue process(MutableEntry<Integer, Integer> e, Object...
arguments)
+            throws EntryProcessorException {
+            return new TestValue(String.valueOf(e.getValue()));
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(UserClassValueProcessor.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    protected static class CollectionReturnProcessor implements
+        EntryProcessor<Integer, Integer, Collection<TestValue>> {
+        /** {@inheritDoc} */
+        @Override public Collection<TestValue> process(MutableEntry<Integer, Integer>
e, Object... arguments)
+            throws EntryProcessorException {
+            List<TestValue> vals = new ArrayList<>();
+
+            for (int i = 0; i < 10; i++)
+                vals.add(new TestValue(String.valueOf(e.getValue() + 1)));
+
+            return vals;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(CollectionReturnProcessor.class, this);
+        }
+    }
+
+    /**
+     *
+     */
     protected static class IncrementProcessor implements EntryProcessor<Integer, Integer,
Integer> {
         /** {@inheritDoc} */
         @Override public Integer process(MutableEntry<Integer, Integer> e,
@@ -656,4 +781,50 @@ public abstract class IgniteCacheInvokeAbstractTest extends IgniteCacheAbstractT
             return S.toString(ExceptionProcessor.class, this);
         }
     }
+
+    /**
+     *
+     */
+    static class TestValue {
+        /** */
+        private String val;
+
+        /**
+         * @param val Value.
+         */
+        public TestValue(String val) {
+            this.val = val;
+        }
+
+        /**
+         * @return Value.
+         */
+        public String value() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            TestValue testVal = (TestValue) o;
+
+            return val.equals(testVal.val);
+
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val.hashCode();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(TestValue.class, this);
+        }
+    }
 }
\ No newline at end of file


Mime
View raw message