You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2016/02/09 09:28:59 UTC

ignite git commit: IGNITE-2468

Repository: ignite
Updated Branches:
  refs/heads/ignite-2468 e2e216d7f -> d600150d0


IGNITE-2468


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

Branch: refs/heads/ignite-2468
Commit: d600150d07ad1edc51f4fd93e5b083b7ecdf7492
Parents: e2e216d
Author: Anton Vinogradov <av...@apache.org>
Authored: Tue Feb 9 11:28:06 2016 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Tue Feb 9 11:28:06 2016 +0300

----------------------------------------------------------------------
 .../continuous/GridContinuousProcessor.java     |   5 +
 ...IgniteCacheContinuousQueryReconnectTest.java | 190 +++++++++++++++++++
 2 files changed, 195 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d600150d/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
index 7c7e3e3..379be57 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/continuous/GridContinuousProcessor.java
@@ -990,6 +990,11 @@ public class GridContinuousProcessor extends GridProcessorAdapter {
         }
 
         if (doRegister) {
+            if (!autoUnsubscribe)
+                // Register routine locally.
+                locInfos.put(routineId, new LocalRoutineInfo(
+                    F.<ClusterNode>alwaysTrue(), hnd, bufSize, interval, autoUnsubscribe));
+
             if (interval > 0) {
                 IgniteThread checker = new IgniteThread(new GridWorker(ctx.gridName(), "continuous-buffer-checker", log) {
                     @SuppressWarnings("ConstantConditions")

http://git-wip-us.apache.org/repos/asf/ignite/blob/d600150d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryReconnectTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryReconnectTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryReconnectTest.java
new file mode 100644
index 0000000..9705409
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryReconnectTest.java
@@ -0,0 +1,190 @@
+/*
+ * 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.internal.processors.cache.query.continuous;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.Cache;
+import javax.cache.CacheException;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteClientDisconnectedException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.PA;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class IgniteCacheContinuousQueryReconnectTest extends GridCommonAbstractTest implements Serializable {
+    /** */
+    final private static AtomicInteger cnt = new AtomicInteger();
+
+    /** */
+    private volatile boolean isClient = false;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setCacheMode(PARTITIONED);
+        ccfg.setAtomicityMode(atomicMode());
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+        ccfg.setBackups(1);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        if (isClient)
+            cfg.setClientMode(true);
+
+        return cfg;
+    }
+
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * @return Atomic mode.
+     */
+    protected CacheAtomicityMode atomicMode() {
+        return ATOMIC;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReconnectServer() throws Exception {
+        testReconnect(false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReconnectClient() throws Exception {
+        testReconnect(true);
+    }
+
+    /**
+     *
+     */
+    private void putAndCheck(IgniteCache<Object, Object> cache, int diff) {
+        cnt.set(0);
+
+        cache.put(1, "1");
+
+        assertEquals(diff, cnt.get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testReconnect(boolean clientQuery) throws Exception {
+        Ignite srv1 = startGrid(0);
+
+        ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
+
+        qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
+            @Override public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
+                // No-op.
+            }
+        });
+
+        qry.setAutoUnsubscribe(false);
+
+        qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {
+            @Override public boolean evaluate(CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
+                cnt.incrementAndGet();
+
+                return true;
+            }
+        });
+
+        isClient = true;
+
+        Ignite client = startGrid(1);
+
+        isClient = false;
+
+        IgniteCache<Object, Object> cache1 = srv1.cache(null);
+        IgniteCache<Object, Object> clCache = client.cache(null);
+
+        putAndCheck(clCache, 0); // 0 remote listeners.
+
+        QueryCursor<Cache.Entry<Object, Object>> cur = (clientQuery ? clCache : cache1).query(qry);
+
+        putAndCheck(clCache, 1); // 1 remote listener.
+
+        final Ignite srv2 = startGrid(2);
+
+        putAndCheck(clCache, 2); // 2 remote listeners.
+
+        stopGrid(0);
+
+        while (true) {
+            try {
+                clCache.get(1);
+
+                break;
+            }
+            catch (IgniteClientDisconnectedException e) {
+                e.reconnectFuture().get(); // Wait for reconnect.
+
+            }
+            catch (CacheException e) {
+                if (e.getCause() instanceof IgniteClientDisconnectedException)
+                    ((IgniteClientDisconnectedException)e.getCause()).reconnectFuture().get(); // Wait for reconnect.
+            }
+        }
+
+        putAndCheck(clCache, 1); // 1 remote listener.
+
+        Ignite srv3 = startGrid(3);
+
+        putAndCheck(clCache, 2); // 2 remote listeners.
+
+        stopGrid(1);
+
+        isClient = true;
+
+        client = startGrid(4);
+
+        isClient = false;
+
+        clCache = client.cache(null);
+
+        putAndCheck(clCache, 2); // 2 remote listeners.
+    }
+}
\ No newline at end of file