You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2017/06/08 16:11:20 UTC
[02/11] ignite git commit: IGNITE-5267 - Moved WAL system properties
to WAL configuration
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java
deleted file mode 100644
index 20ddd82..0000000
--- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStreamerTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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.cache.database.standbycluster;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteDataStreamer;
-
-/**
- *
- */
-public class GridChangeGlobalStateDataStreamerTest extends GridChangeGlobalStateAbstractTest {
- /** {@inheritDoc} */
- @Override protected int backUpNodes() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override protected int backUpClientNodes() {
- return 0;
- }
-
- /**
- *
- */
- public void testDeActivateAndActivateDataStreamer() throws InterruptedException {
-
- Ignite ig1 = primary(0);
- Ignite ig2 = primary(1);
- Ignite ig3 = primary(2);
-
- Ignite ig1C = primaryClient(0);
- Ignite ig2C = primaryClient(1);
- Ignite ig3C = primaryClient(2);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- assertTrue(ig1C.active());
- assertTrue(ig2C.active());
- assertTrue(ig3C.active());
-
- String cacheName = "myStreamCache";
-
- ig2C.getOrCreateCache(cacheName);
-
- try (IgniteDataStreamer<Integer, String> stmr = ig1.dataStreamer(cacheName)) {
- for (int i = 0; i < 100; i++)
- stmr.addData(i, Integer.toString(i));
- }
-
- ig2C.active(false);
-
- assertTrue(!ig1.active());
- assertTrue(!ig2.active());
- assertTrue(!ig3.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
-
- boolean fail = false;
-
- try {
- IgniteDataStreamer<String, String> strm2 = ig2.dataStreamer(cacheName);
- }
- catch (Exception e) {
- fail = true;
-
- assertTrue(e.getMessage().contains("can not perform operation, because cluster inactive"));
- }
-
- if (!fail)
- fail("exception was not throw");
-
- ig3C.active(true);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- assertTrue(ig1C.active());
- assertTrue(ig2C.active());
- assertTrue(ig3C.active());
-
- try (IgniteDataStreamer<Integer, String> stmr2 = ig2.dataStreamer(cacheName)) {
- for (int i = 100; i < 200; i++)
- stmr2.addData(i, Integer.toString(i));
- }
-
- IgniteCache<Integer, String> cache = ig3.cache(cacheName);
-
- for (int i = 0; i < 200; i++)
- assertEquals(String.valueOf(i), cache.get(i));
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java
deleted file mode 100644
index a33a02e..0000000
--- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateDataStructureTest.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * 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.cache.database.standbycluster;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteAtomicLong;
-import org.apache.ignite.IgniteAtomicSequence;
-import org.apache.ignite.IgniteCountDownLatch;
-import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.testframework.GridTestUtils.runAsync;
-
-/**
- *
- */
-public class GridChangeGlobalStateDataStructureTest extends GridChangeGlobalStateAbstractTest {
- /**
- *
- */
- public void testDeActivateAndActivateAtomicLong() throws Exception{
- String lName = "myLong";
-
- Ignite ig1 = primary(0);
- Ignite ig2 = primary(1);
- Ignite ig3 = primary(2);
-
- IgniteAtomicLong lexp = ig1.atomicLong(lName, 100, true);
-
- lexp.incrementAndGet();
- lexp.incrementAndGet();
- lexp.incrementAndGet();
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- ig2.active(false);
-
- IgniteEx ex1 = (IgniteEx)ig1;
- IgniteEx ex2 = (IgniteEx)ig2;
- IgniteEx ex3 = (IgniteEx)ig3;
-
- GridCacheProcessor cache1 = ex1.context().cache();
- GridCacheProcessor cache2 = ex2.context().cache();
- GridCacheProcessor cache3 = ex3.context().cache();
-
- assertTrue(F.isEmpty(cache1.jcaches()));
- assertTrue(F.isEmpty(cache2.jcaches()));
- assertTrue(F.isEmpty(cache3.jcaches()));
-
- assertTrue(!ig1.active());
- assertTrue(!ig2.active());
- assertTrue(!ig3.active());
-
- ig3.active(true);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- IgniteAtomicLong lact1 = ig1.atomicLong(lName, 0, false);
- IgniteAtomicLong lact2 = ig2.atomicLong(lName, 0, false);
- IgniteAtomicLong lact3 = ig3.atomicLong(lName, 0, false);
-
- assertEquals(103, lact1.get());
- assertEquals(103, lact2.get());
- assertEquals(103, lact3.get());
-
- lact1.incrementAndGet();
-
- assertEquals(104, lact1.get());
- assertEquals(104, lact2.get());
- assertEquals(104, lact3.get());
-
- lact2.incrementAndGet();
-
- assertEquals(105, lact1.get());
- assertEquals(105, lact2.get());
- assertEquals(105, lact3.get());
-
- lact3.incrementAndGet();
-
- assertEquals(106, lact3.get());
- assertEquals(106, lact3.get());
- assertEquals(106, lact3.get());
- }
-
- /**
- *
- */
- public void testDeActivateAndActivateCountDownLatch() throws Exception {
- final AtomicInteger cnt = new AtomicInteger();
-
- String latchName = "myLatch";
-
- Ignite ig1 = primary(0);
- Ignite ig2 = primary(1);
- Ignite ig3 = primary(2);
-
- IgniteCountDownLatch latchExp1 = ig1.countDownLatch(latchName, 5, false, true);
-
- latchExp1.countDown();
-
- assertEquals(4, latchExp1.count());
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- ig2.active(false);
-
- IgniteEx ex1 = (IgniteEx)ig1;
- IgniteEx ex2 = (IgniteEx)ig2;
- IgniteEx ex3 = (IgniteEx)ig3;
-
- GridCacheProcessor cache1 = ex1.context().cache();
- GridCacheProcessor cache2 = ex2.context().cache();
- GridCacheProcessor cache3 = ex3.context().cache();
-
- assertTrue(F.isEmpty(cache1.jcaches()));
- assertTrue(F.isEmpty(cache2.jcaches()));
- assertTrue(F.isEmpty(cache3.jcaches()));
-
- assertTrue(!ig1.active());
- assertTrue(!ig2.active());
- assertTrue(!ig3.active());
-
- ig3.active(true);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- final IgniteCountDownLatch latchAct1 = ig1.countDownLatch(latchName, 0, false, false);
- final IgniteCountDownLatch latchAct2 = ig2.countDownLatch(latchName, 0, false, false);
- final IgniteCountDownLatch latchAct3 = ig3.countDownLatch(latchName, 0, false, false);
-
- runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- latchAct1.await();
- cnt.incrementAndGet();
- return null;
- }
- });
-
- runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- latchAct2.await();
- cnt.incrementAndGet();
- return null;
- }
- });
-
- runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- latchAct3.await();
- cnt.incrementAndGet();
- return null;
- }
- });
-
-
- assertEquals(4, latchAct1.count());
- assertEquals(4, latchAct2.count());
- assertEquals(4, latchAct3.count());
-
- latchAct1.countDown();
- latchAct2.countDown();
- latchAct3.countDown();
-
- assertEquals(1, latchAct1.count());
- assertEquals(1, latchAct2.count());
- assertEquals(1, latchAct3.count());
-
- latchAct1.countDown();
-
- U.sleep(3000);
-
- assertEquals(3, cnt.get());
- }
-
- /**
- *
- */
- public void testDeActivateAndActivateAtomicSequence(){
- String seqName = "mySeq";
-
- Ignite ig1 = primary(0);
- Ignite ig2 = primary(1);
- Ignite ig3 = primary(2);
-
- IgniteAtomicSequence seqExp1 = ig1.atomicSequence(seqName, 0, true);
- IgniteAtomicSequence seqExp2 = ig2.atomicSequence(seqName, 0, false);
- IgniteAtomicSequence seqExp3 = ig3.atomicSequence(seqName, 0, false);
-
- assertEquals(0, seqExp1.get());
- assertEquals(1000, seqExp2.get());
- assertEquals(2000, seqExp3.get());
-
- seqExp1.incrementAndGet();
- seqExp2.incrementAndGet();
- seqExp3.incrementAndGet();
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- ig2.active(false);
-
- IgniteEx ex1 = (IgniteEx)ig1;
- IgniteEx ex2 = (IgniteEx)ig2;
- IgniteEx ex3 = (IgniteEx)ig3;
-
- GridCacheProcessor cache1 = ex1.context().cache();
- GridCacheProcessor cache2 = ex2.context().cache();
- GridCacheProcessor cache3 = ex3.context().cache();
-
- assertTrue(F.isEmpty(cache1.jcaches()));
- assertTrue(F.isEmpty(cache2.jcaches()));
- assertTrue(F.isEmpty(cache3.jcaches()));
-
- assertTrue(!ig1.active());
- assertTrue(!ig2.active());
- assertTrue(!ig3.active());
-
- ig3.active(true);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- IgniteAtomicSequence seqAct1 = ig1.atomicSequence(seqName, 0, false);
- IgniteAtomicSequence seqAct2 = ig2.atomicSequence(seqName, 0, false);
- IgniteAtomicSequence seqAct3 = ig3.atomicSequence(seqName, 0, false);
-
- assertEquals(1, seqAct1.get());
- assertEquals(1001, seqAct2.get());
- assertEquals(2001, seqAct3.get());
-
- seqAct1.incrementAndGet();
-
- assertEquals(2, seqAct1.get());
- assertEquals(1001, seqAct2.get());
- assertEquals(2001, seqAct3.get());
-
- seqAct2.incrementAndGet();
-
- assertEquals(2, seqAct1.get());
- assertEquals(1002, seqAct2.get());
- assertEquals(2001, seqAct3.get());
-
- seqAct3.incrementAndGet();
-
- assertEquals(2, seqAct1.get());
- assertEquals(1002, seqAct2.get());
- assertEquals(2002, seqAct3.get());
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java
deleted file mode 100644
index 2fb5137..0000000
--- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateFailOverTest.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * 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.cache.database.standbycluster;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-
-import static java.lang.Thread.sleep;
-import static org.apache.ignite.testframework.GridTestUtils.runAsync;
-
-/**
- *
- */
-public class GridChangeGlobalStateFailOverTest extends GridChangeGlobalStateAbstractTest {
- /** {@inheritDoc} */
- @Override protected int primaryNodes() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override protected int primaryClientNodes() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override protected int backUpClientNodes() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override protected int backUpNodes() {
- return 4;
- }
-
- /**
- *
- */
- public void testActivateDeActivateOnFixTopology() throws Exception {
- final Ignite igB1 = backUp(0);
- final Ignite igB2 = backUp(1);
- final Ignite igB3 = backUp(2);
-
- assertTrue(!igB1.active());
- assertTrue(!igB2.active());
- assertTrue(!igB3.active());
-
- final AtomicInteger cntA = new AtomicInteger();
- final AtomicInteger cntD = new AtomicInteger();
-
- final AtomicLong timeA = new AtomicLong();
- final AtomicLong timeD = new AtomicLong();
-
- final AtomicBoolean stop = new AtomicBoolean();
-
- final AtomicBoolean canAct = new AtomicBoolean(true);
-
- try {
- final IgniteInternalFuture<Void> af = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get()) {
- Ignite ig = randomBackUp(false);
-
- if (canAct.get()) {
- long start = System.currentTimeMillis();
-
- ig.active(true);
-
- timeA.addAndGet((System.currentTimeMillis() - start));
-
- cntA.incrementAndGet();
-
- for (Ignite ign : allBackUpNodes())
- assertTrue(ign.active());
-
- canAct.set(false);
- }
-
- }
- return null;
- }
- });
-
- final IgniteInternalFuture<Void> df = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get()) {
- Ignite ig = randomBackUp(false);
-
- if (!canAct.get()) {
- long start = System.currentTimeMillis();
-
- ig.active(false);
-
- timeD.addAndGet((System.currentTimeMillis() - start));
-
- cntD.incrementAndGet();
-
- for (Ignite ign : allBackUpNodes())
- assertTrue(!ign.active());
-
- canAct.set(true);
- }
-
- }
- return null;
- }
- });
-
- sleep(60_000);
-
- stop.set(true);
-
- af.get();
- df.get();
- }
- finally {
- log.info("total activate/deactivate:" + cntA.get() + "/" + cntD.get() + " aTime/dTime:"
- + (timeA.get() / cntA.get() + "/" + (timeD.get() / cntD.get()) + " nodes: " + backUpNodes()));
- }
- }
-
- /**
- *
- */
- public void testActivateDeActivateOnJoiningNode() throws Exception {
- final Ignite igB1 = backUp(0);
- final Ignite igB2 = backUp(1);
- final Ignite igB3 = backUp(2);
-
- assertTrue(!igB1.active());
- assertTrue(!igB2.active());
- assertTrue(!igB3.active());
-
- final AtomicInteger cntA = new AtomicInteger();
- final AtomicInteger cntD = new AtomicInteger();
-
- final AtomicLong timeA = new AtomicLong();
- final AtomicLong timeD = new AtomicLong();
-
- final AtomicBoolean stop = new AtomicBoolean();
-
- final AtomicBoolean canAct = new AtomicBoolean(true);
- final AtomicInteger seqIdx = new AtomicInteger(backUpNodes());
-
- try {
- final IgniteInternalFuture<Void> af = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get()) {
- Ignite ig = randomBackUp(false);
-
- if (canAct.get()) {
- long start = System.currentTimeMillis();
-
- ig.active(true);
-
- timeA.addAndGet((System.currentTimeMillis() - start));
-
- cntA.incrementAndGet();
-
- for (Ignite ign : allBackUpNodes())
- assertTrue(ign.active());
-
- canAct.set(false);
- }
-
- }
- return null;
- }
- });
-
- final IgniteInternalFuture<Void> df = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get()) {
- Ignite ig = randomBackUp(false);
-
- if (!canAct.get()) {
- long start = System.currentTimeMillis();
-
- ig.active(false);
-
- timeD.addAndGet((System.currentTimeMillis() - start));
-
- cntD.incrementAndGet();
-
- for (Ignite ign : allBackUpNodes())
- assertTrue(!ign.active());
-
- canAct.set(true);
- }
-
- }
- return null;
- }
- });
-
- IgniteInternalFuture<Void> jf1 = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get())
- startBackUp(seqIdx.incrementAndGet());
-
- return null;
- }
- });
-
- IgniteInternalFuture<Void> jf2 = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get())
- startBackUp(seqIdx.incrementAndGet());
-
- return null;
- }
- });
-
- sleep(60_000);
-
- stop.set(true);
-
- af.get();
- df.get();
- jf1.get();
- jf2.get();
- }
- finally {
- log.info("total started nodes: " + (seqIdx.get() - backUpNodes()));
-
- log.info("total activate/deactivate:" + cntA.get() + "/" + cntD.get() + " aTime/dTime: "
- + (timeA.get() / cntA.get() + "/" + (timeD.get() / cntD.get()))
- );
- }
- }
-
- /**
- *
- */
- public void testActivateDeActivateOnFixTopologyWithPutValues() throws Exception {
- final Ignite igB1 = backUp(0);
- final Ignite igB2 = backUp(1);
- final Ignite igB3 = backUp(2);
-
- assertTrue(!igB1.active());
- assertTrue(!igB2.active());
- assertTrue(!igB3.active());
-
- final CacheConfiguration<String, String> ccfg = new CacheConfiguration<>();
- ccfg.setName("main-cache");
-
- final AtomicInteger cnt = new AtomicInteger();
-
- final AtomicInteger cntA = new AtomicInteger();
- final AtomicInteger cntD = new AtomicInteger();
-
- final AtomicLong timeA = new AtomicLong();
- final AtomicLong timeD = new AtomicLong();
-
- final AtomicBoolean stop = new AtomicBoolean();
-
- final AtomicBoolean canAct = new AtomicBoolean(true);
-
- try {
- final IgniteInternalFuture<Void> af = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get()) {
- Ignite ig = randomBackUp(false);
-
- if (canAct.get()) {
- long start = System.currentTimeMillis();
-
- ig.active(true);
-
- IgniteCache<String, String> cache = ig.getOrCreateCache(ccfg);
-
- cache.put("key" + cnt.get(), "value" + cnt.get());
-
- cnt.incrementAndGet();
-
- timeA.addAndGet((System.currentTimeMillis() - start));
-
- cntA.incrementAndGet();
-
- for (Ignite ign : allBackUpNodes())
- assertTrue(ign.active());
-
- canAct.set(false);
- }
-
- }
- return null;
- }
- });
-
- final IgniteInternalFuture<Void> df = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- while (!stop.get()) {
- Ignite ig = randomBackUp(false);
-
- if (!canAct.get()) {
- long start = System.currentTimeMillis();
-
- IgniteCache<String, String> cache = ig.getOrCreateCache(ccfg);
-
- for (int i = 0; i < cnt.get(); i++)
- assertEquals("value" + i, cache.get("key" + i));
-
- ig.active(false);
-
- timeD.addAndGet((System.currentTimeMillis() - start));
-
- cntD.incrementAndGet();
-
- for (Ignite ign : allBackUpNodes())
- assertTrue(!ign.active());
-
- canAct.set(true);
- }
-
- }
- return null;
- }
- });
-
- sleep(60_000);
-
- stop.set(true);
-
- af.get();
- df.get();
- }
- finally {
- log.info("total activate/deactivate:" + cntA.get() + "/" + cntD.get() + " aTime/dTime:"
- + (timeA.get() / cntA.get() + "/" + (timeD.get() / cntD.get()) + " nodes: " + backUpNodes()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java
deleted file mode 100644
index f6fbc2c..0000000
--- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateServiceTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.cache.database.standbycluster;
-
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.services.Service;
-import org.apache.ignite.services.ServiceConfiguration;
-import org.apache.ignite.services.ServiceContext;
-import org.apache.ignite.services.ServiceDescriptor;
-
-/**
- *
- */
-public class GridChangeGlobalStateServiceTest extends GridChangeGlobalStateAbstractTest {
- /** {@inheritDoc} */
- @Override protected int backUpClientNodes() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override protected int primaryNodes() {
- return 1;
- }
-
- /** {@inheritDoc} */
- @Override protected int backUpNodes() {
- return 1;
- }
-
- /**
- *
- */
- public void testDeployService() throws Exception {
- Ignite ig1P = primary(0);
-
- Ignite ig1B = backUp(0);
-
- String serName = "service";
-
- ServiceConfiguration serConf = new ServiceConfiguration();
- serConf.setTotalCount(1);
- serConf.setName(serName);
- serConf.setService(new TestService());
-
- ig1P.services().deploy(serConf);
-
- stopAllPrimary();
-
- ig1B.active(true);
-
- U.sleep(3000);
-
- Collection<ServiceDescriptor> descs = ig1B.services().serviceDescriptors();
-
- assertTrue(!F.isEmpty(descs));
-
- TestService srv = ig1B.services().service(serName);
-
- assertTrue(srv != null);
- }
-
- /**
- *
- */
- private static class TestService implements Service{
- /** */
- private static final long serialVersionUID = 0L;
-
- /** {@inheritDoc} */
- @Override public void cancel(ServiceContext ctx) {
- System.out.println("cancel service");
- }
-
- /** {@inheritDoc} */
- @Override public void init(ServiceContext ctx) throws Exception {
- System.out.println("init service");
- }
-
- /** {@inheritDoc} */
- @Override public void execute(ServiceContext ctx) throws Exception {
- System.out.println("execute service");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java
deleted file mode 100644
index b7dd082..0000000
--- a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/GridChangeGlobalStateTest.java
+++ /dev/null
@@ -1,711 +0,0 @@
-/*
- * 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.cache.database.standbycluster;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteAtomicSequence;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteServices;
-import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
-import org.apache.ignite.internal.util.typedef.F;
-
-import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
-import static org.apache.ignite.testframework.GridTestUtils.runAsync;
-
-/**
- *
- */
-public class GridChangeGlobalStateTest extends GridChangeGlobalStateAbstractTest {
- /**
- * @throws Exception if fail.
- */
- public void testStopPrimaryAndActivateFromServerNode() throws Exception {
- Ignite ig1P = primary(0);
- Ignite ig2P = primary(1);
- Ignite ig3P = primary(2);
-
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- assertTrue(ig1P.active());
- assertTrue(ig2P.active());
- assertTrue(ig3P.active());
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- stopAllPrimary();
-
- ig2B.active(true);
-
- assertTrue(ig1B.active());
- assertTrue(ig2B.active());
- assertTrue(ig3B.active());
- }
-
- /**
- * @throws Exception if fail.
- */
- public void testStopPrimaryAndActivateFromClientNode() throws Exception {
- Ignite ig1P = primary(0);
- Ignite ig2P = primary(1);
- Ignite ig3P = primary(2);
-
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- Ignite ig1C = backUpClient(0);
- Ignite ig2C = backUpClient(1);
- Ignite ig3C = backUpClient(2);
-
- assertTrue(ig1P.active());
- assertTrue(ig2P.active());
- assertTrue(ig3P.active());
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
-
- stopAllPrimary();
-
- ig2B.active(true);
-
- assertTrue(ig1B.active());
- assertTrue(ig2B.active());
- assertTrue(ig3B.active());
-
- assertTrue(ig1C.active());
- assertTrue(ig2C.active());
- assertTrue(ig3C.active());
- }
-
- /**
- * @throws Exception if fail.
- */
- public void testConcurrentActivateFromClientNodeAndServerNode() throws Exception {
- final Ignite ig1B = backUp(0);
- final Ignite ig2B = backUp(1);
- final Ignite ig3B = backUp(2);
-
- final Ignite ig1C = backUpClient(0);
- final Ignite ig2C = backUpClient(1);
- final Ignite ig3C = backUpClient(2);
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- stopAllPrimary();
-
- final AtomicInteger exCnt = new AtomicInteger();
-
- final CyclicBarrier barrier = new CyclicBarrier(backUpNodes() + backUpClientNodes());
-
- IgniteInternalFuture<Void> f1 = runAsync(new Callable<Void>() {
- @Override public Void call() throws Exception {
- try {
- barrier.await();
- ig1B.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- return null;
- }
- });
-
- IgniteInternalFuture<Void> f2 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig2B.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- IgniteInternalFuture<Void> f3 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig3B.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- IgniteInternalFuture<Void> f4 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig1C.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- IgniteInternalFuture<Void> f5 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig2C.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- IgniteInternalFuture<Void> f6 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig3C.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- f1.get();
- f2.get();
- f3.get();
-
- f4.get();
- f5.get();
- f6.get();
-
- assertTrue(exCnt.get() > 0);
-
- assertTrue(ig1B.active());
- assertTrue(ig2B.active());
- assertTrue(ig3B.active());
-
- assertTrue(ig1C.active());
- assertTrue(ig2C.active());
- assertTrue(ig3C.active());
- }
-
- /**
- * @throws Exception if fail.
- */
- public void testConcurrentActivateFromServerNode() throws Exception {
- final Ignite ig1B = backUp(0);
- final Ignite ig2B = backUp(1);
- final Ignite ig3B = backUp(2);
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- stopAllPrimary();
-
- final AtomicInteger exCnt = new AtomicInteger();
-
- final CyclicBarrier barrier = new CyclicBarrier(3);
-
- IgniteInternalFuture<Void> act1 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig1B.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- IgniteInternalFuture<Void> act2 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig2B.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- IgniteInternalFuture<Void> act3 = runAsync(new Runnable() {
- @Override public void run() {
- try {
- barrier.await();
- ig3B.active(true);
- }catch (Exception e){
- exCnt.incrementAndGet();
- }
- }
- });
-
- act1.get();
- act2.get();
- act3.get();
-
- assertEquals(2, exCnt.get());
-
- assertTrue(ig1B.active());
- assertTrue(ig2B.active());
- assertTrue(ig3B.active());
- }
-
- /**
- *
- */
- public void testActiveAndInActiveAtTheSameTimeCluster() throws Exception {
- Ignite ig1P = primary(0);
- Ignite ig2P = primary(1);
- Ignite ig3P = primary(2);
-
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- assertTrue(ig1P.cluster().nodes().size() == 6);
- assertTrue(ig2P.cluster().nodes().size() == 6);
- assertTrue(ig3P.cluster().nodes().size() == 6);
-
- List<ClusterNode> primaryNodes = Arrays.asList(
- ig1P.cluster().localNode(), ig2P.cluster().localNode(), ig3P.cluster().localNode()
- );
-
- List<ClusterNode> backUpNodes = Arrays.asList(
- ig1B.cluster().localNode(), ig3B.cluster().localNode(), ig3B.cluster().localNode()
- );
-
- assertTrue(!ig1P.cluster().forRemotes().nodes().containsAll(backUpNodes));
- assertTrue(!ig2P.cluster().forRemotes().nodes().containsAll(backUpNodes));
- assertTrue(!ig3P.cluster().forRemotes().nodes().containsAll(backUpNodes));
-
- assertTrue(ig1B.cluster().nodes().size() == 6);
- assertTrue(ig2B.cluster().nodes().size() == 6);
- assertTrue(ig3B.cluster().nodes().size() == 6);
-
- assertTrue(!ig1B.cluster().forRemotes().nodes().containsAll(primaryNodes));
- assertTrue(!ig2B.cluster().forRemotes().nodes().containsAll(primaryNodes));
- assertTrue(!ig3B.cluster().forRemotes().nodes().containsAll(primaryNodes));
- }
-
- /**
- *
- */
- public void testActivateOnAlreadyActivatedCluster() throws Exception {
- Ignite ig1P = primary(0);
- Ignite ig2P = primary(1);
- Ignite ig3P = primary(2);
-
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- Ignite ig1C = backUpClient(0);
- Ignite ig2C = backUpClient(1);
- Ignite ig3C = backUpClient(2);
-
- assertTrue(ig1P.active());
- assertTrue(ig2P.active());
- assertTrue(ig3P.active());
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
-
- stopAllPrimary();
-
- ig2B.active(true);
-
- assertTrue(ig1B.active());
- assertTrue(ig2B.active());
- assertTrue(ig3B.active());
-
- assertTrue(ig1C.active());
- assertTrue(ig2C.active());
- assertTrue(ig3C.active());
-
- ig1B.active(true);
- ig2B.active(true);
- ig3B.active(true);
-
- ig1C.active(true);
- ig2C.active(true);
- ig3C.active(true);
-
- assertTrue(ig1B.active());
- assertTrue(ig2B.active());
- assertTrue(ig3B.active());
-
- assertTrue(ig1C.active());
- assertTrue(ig2C.active());
- assertTrue(ig3C.active());
- }
-
- /**
- *
- */
- public void testTryUseCacheInActiveCluster() throws Exception {
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- Ignite ig1C = backUpClient(0);
- Ignite ig2C = backUpClient(1);
- Ignite ig3C = backUpClient(2);
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
-
- checkExceptionTryUseCache(ig1B);
- checkExceptionTryUseCache(ig2B);
- checkExceptionTryUseCache(ig3B);
-
- checkExceptionTryUseCache(ig1C);
- checkExceptionTryUseCache(ig2C);
- checkExceptionTryUseCache(ig3C);
- }
-
- /**
- * @param ig Ig.
- */
- private void checkExceptionTryUseCache(final Ignite ig) {
- assertThrows(log, new Callable<Void>() {
- @Override public Void call() throws Exception {
- IgniteCache cache = ig.cache("cache");
- return null;
- }
- }, IgniteException.class, "can not perform operation, because cluster inactive");
- }
-
- /**
- *
- */
- public void testTryUseServiceInActiveCluster() throws Exception {
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- Ignite ig1C = backUpClient(0);
- Ignite ig2C = backUpClient(1);
- Ignite ig3C = backUpClient(2);
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
-
- checkExceptionTryUseService(ig1B);
- checkExceptionTryUseService(ig2B);
- checkExceptionTryUseService(ig3B);
-
- checkExceptionTryUseService(ig1C);
- checkExceptionTryUseService(ig2C);
- checkExceptionTryUseService(ig3C);
- }
-
- /**
- *
- */
- private void checkExceptionTryUseService(final Ignite ig) {
- assertThrows(log, new Callable<Void>() {
- @Override public Void call() throws Exception {
- IgniteServices srvs = ig.services();
-
- return null;
- }
- }, IgniteException.class, "can not perform operation, because cluster inactive");
- }
-
- /**
- *
- */
- public void testTryUseDataStructureInActiveCluster() throws Exception {
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- Ignite ig1C = backUpClient(0);
- Ignite ig2C = backUpClient(1);
- Ignite ig3C = backUpClient(2);
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
-
- checkExceptionTryUseDataStructure(ig1B);
- checkExceptionTryUseDataStructure(ig2B);
- checkExceptionTryUseDataStructure(ig3B);
-
- checkExceptionTryUseDataStructure(ig1C);
- checkExceptionTryUseDataStructure(ig2C);
- checkExceptionTryUseDataStructure(ig3C);
- }
-
- /**
- *
- */
- private void checkExceptionTryUseDataStructure(final Ignite ig){
- assertThrows(log, new Callable<Void>() {
- @Override public Void call() throws Exception {
- IgniteAtomicSequence seq = ig.atomicSequence("seq", 0, true);
- return null;
- }
- }, IgniteException.class, "can not perform operation, because cluster inactive");
- }
-
- /**
- *
- */
- public void testFailGetLock() throws Exception {
- Ignite ig1P = primary(0);
- Ignite ig2P = primary(1);
- Ignite ig3P = primary(2);
-
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- Ignite ig1C = backUpClient(0);
- Ignite ig2C = backUpClient(1);
-
- final Ignite ig3C = backUpClient(2);
-
- assertTrue(ig1P.active());
- assertTrue(ig2P.active());
- assertTrue(ig3P.active());
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
-
- stopPrimary(0);
-
- boolean exc = false;
-
- try {
- ig3C.active(true);
- }
- catch (IgniteException e) {
- exc = true;
-
- log.error("stack trace from remote node", e);
-
- for (Throwable t : e.getSuppressed())
- assertTrue(t.getMessage().contains("can't get lock during"));
- }
-
- if (!exc)
- fail();
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
- }
-
- /**
- *
- */
- public void testActivateAfterFailGetLock() throws Exception {
- Ignite ig1P = primary(0);
- Ignite ig2P = primary(1);
- Ignite ig3P = primary(2);
-
- Ignite ig1CP = primaryClient(0);
- Ignite ig2CP = primaryClient(1);
- Ignite ig3CP = primaryClient(2);
-
- Ignite ig1B = backUp(0);
- Ignite ig2B = backUp(1);
- Ignite ig3B = backUp(2);
-
- Ignite ig1CB = backUpClient(0);
- Ignite ig2CB = backUpClient(1);
- Ignite ig3CB = backUpClient(2);
-
- assertTrue(ig1P.active());
- assertTrue(ig2P.active());
- assertTrue(ig3P.active());
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1CB.active());
- assertTrue(!ig2CB.active());
- assertTrue(!ig3CB.active());
-
- stopPrimary(0);
-
- boolean exc = false;
-
- try {
- ig3CB.active(true);
- }
- catch (IgniteException e) {
- exc = true;
-
- log.error("stack trace from remote node", e);
-
- for (Throwable t : e.getSuppressed())
- assertTrue(t.getMessage().contains("can't get lock during"));
- }
-
- if (!exc)
- fail();
-
- assertTrue(!ig1B.active());
- assertTrue(!ig2B.active());
- assertTrue(!ig3B.active());
-
- assertTrue(!ig1CB.active());
- assertTrue(!ig2CB.active());
- assertTrue(!ig3CB.active());
-
- assertTrue(ig2P.active());
- assertTrue(ig3P.active());
-
- assertTrue(ig1CP.active());
- assertTrue(ig2CP.active());
- assertTrue(ig3CP.active());
-
- stopAllPrimary();
-
- ig2CB.active(true);
-
- assertTrue(ig1B.active());
- assertTrue(ig2B.active());
- assertTrue(ig3B.active());
-
- assertTrue(ig1CB.active());
- assertTrue(ig2CB.active());
- assertTrue(ig3CB.active());
- }
-
- /**
- * @throws Exception if fail.
- */
- public void testDeActivateFromServerNode() throws Exception {
- Ignite ig1 = primary(0);
- Ignite ig2 = primary(1);
- Ignite ig3 = primary(2);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- ig1.active(false);
-
- assertTrue(!ig1.active());
- assertTrue(!ig2.active());
- assertTrue(!ig3.active());
- }
-
- /**
- * @throws Exception if fail.
- */
- public void testDeActivateFromClientNode() throws Exception {
- Ignite ig1 = primary(0);
- Ignite ig2 = primary(1);
- Ignite ig3 = primary(2);
-
- Ignite ig1C = primaryClient(0);
- Ignite ig2C = primaryClient(1);
- Ignite ig3C = primaryClient(2);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- ig1C.active(false);
-
- assertTrue(!ig1.active());
- assertTrue(!ig2.active());
- assertTrue(!ig3.active());
-
- assertTrue(!ig1C.active());
- assertTrue(!ig2C.active());
- assertTrue(!ig3C.active());
- }
-
- /**
- * @throws Exception if fail.
- */
- public void testDeActivateCheckCacheDestroy() throws Exception {
- String chName = "myCache";
-
- Ignite ig1 = primary(0);
- Ignite ig2 = primary(1);
- Ignite ig3 = primary(2);
-
- ig1.getOrCreateCache(chName);
-
- assertTrue(ig1.active());
- assertTrue(ig2.active());
- assertTrue(ig3.active());
-
- ig1.active(false);
-
- assertTrue(!ig1.active());
- assertTrue(!ig2.active());
- assertTrue(!ig3.active());
-
- IgniteEx ex = (IgniteEx)ig1;
-
- GridCacheProcessor cache = ex.context().cache();
-
- assertTrue(F.isEmpty(cache.jcaches()));
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java
new file mode 100644
index 0000000..f392e6b
--- /dev/null
+++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateAbstractTest.java
@@ -0,0 +1,366 @@
+/*
+ * 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.cache.database.standbycluster;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public abstract class IgniteChangeGlobalStateAbstractTest extends GridCommonAbstractTest {
+ /** Primary suffix. */
+ private static final String primarySuffix = "-primary";
+
+ /** BackUp suffix. */
+ private static final String backUpSuffix = "-backUp";
+
+ /** BackUp suffix. */
+ private static final String clientSuffix = "-client";
+
+ /** Primary ip finder. */
+ protected final TcpDiscoveryIpFinder primaryIpFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** Back up ip finder. */
+ protected final TcpDiscoveryIpFinder backUpIpFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** Consistent id count. */
+ private int consistentIdCnt;
+
+ /** Nodes. */
+ protected Map<String, Ignite> nodes = new ConcurrentHashMap<>();
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ nodes.clear();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), testName(), true));
+
+ startPrimaryNodes(primaryNodes());
+
+ startPrimaryClientNodes(primaryClientNodes());
+
+ startBackUpNodes(backUpNodes());
+
+ startBackUpClientNodes(backUpClientNodes());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAll(clientSuffix);
+
+ stopAll(primarySuffix);
+
+ stopAll(backUpSuffix);
+
+ nodes.clear();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), testName(), true));
+ }
+
+ /**
+ *
+ */
+ protected int primaryNodes() {
+ return 3;
+ }
+
+ /**
+ *
+ */
+ protected int primaryClientNodes() {
+ return 3;
+ }
+
+ /**
+ *
+ */
+ protected int backUpNodes() {
+ return 3;
+ }
+
+ /**
+ *
+ */
+ protected int backUpClientNodes() {
+ return 3;
+ }
+
+ /**
+ * @param idx idx.
+ */
+ protected Ignite primary(int idx) {
+ return nodes.get("node" + idx + primarySuffix);
+ }
+
+ /**
+ * @param idx idx.
+ */
+ protected Ignite primaryClient(int idx) {
+ return nodes.get("node" + idx + primarySuffix + clientSuffix);
+ }
+
+ /**
+ * @param idx idx.
+ */
+ protected Ignite backUp(int idx) {
+ return nodes.get("node" + idx + backUpSuffix);
+ }
+
+ /**
+ * @param idx idx.
+ */
+ protected Ignite backUpClient(int idx) {
+ return nodes.get("node" + idx + backUpSuffix + clientSuffix);
+ }
+
+ /**
+ * @param cnt Count.
+ */
+ protected void startPrimaryNodes(int cnt) throws Exception {
+ for (int i = 0; i < cnt; i++)
+ startPrimary(i);
+ }
+
+ /**
+ * @param idx Index.
+ */
+ protected void startPrimary(int idx) throws Exception {
+ String node = "node" + idx;
+
+ String name = node + primarySuffix;
+
+ IgniteConfiguration cfg = getConfiguration(name);
+ cfg.setConsistentId(node);
+ cfg.setActiveOnStart(true);
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(primaryIpFinder);
+
+ Ignite ig = startGrid(name, cfg);
+
+ nodes.put(name, ig);
+ }
+
+ /**
+ * @param cnt Count.
+ */
+ protected void startBackUpNodes(int cnt) throws Exception {
+ for (int i = 0; i < cnt; i++)
+ startBackUp(i);
+ }
+
+ /**
+ * @param idx Index.
+ */
+ protected void startBackUp(int idx) throws Exception {
+ String node = "node" + idx;
+
+ String name = node + backUpSuffix;
+
+ IgniteConfiguration cfg = getConfiguration(name);
+ cfg.setConsistentId(node);
+ cfg.setActiveOnStart(false);
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(backUpIpFinder);
+
+ Ignite ig = startGrid(name, cfg);
+
+ nodes.put(name, ig);
+ }
+
+ /**
+ * @param cnt Count.
+ */
+ protected void startPrimaryClientNodes(int cnt) throws Exception {
+ for (int i = 0; i < cnt; i++) {
+ String node = "node" + i;
+
+ String name = node + primarySuffix + clientSuffix;
+
+ IgniteConfiguration cfg = getConfiguration(name);
+ cfg.setConsistentId(node);
+ cfg.setClientMode(true);
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(primaryIpFinder);
+
+ Ignite ig = startGrid(name, cfg);
+
+ nodes.put(name, ig);
+ }
+ }
+
+ /**
+ * @param cnt Count.
+ */
+ protected void startBackUpClientNodes(int cnt) throws Exception {
+ for (int i = 0; i < cnt; i++) {
+ String node = "node" + i;
+
+ String name = node + backUpSuffix + clientSuffix;
+
+ IgniteConfiguration cfg = getConfiguration(name);
+ cfg.setConsistentId(node);
+ cfg.setActiveOnStart(false);
+ cfg.setClientMode(true);
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(backUpIpFinder);
+
+ Ignite ig = startGrid(name, cfg);
+
+ nodes.put(name, ig);
+ }
+ }
+
+ /**
+ *
+ */
+ protected Iterable<Ignite> allBackUpNodes(){
+ List<Ignite> r = new ArrayList<>();
+
+ for (String name : this.nodes.keySet())
+ if (name.contains(backUpSuffix))
+ r.add(nodes.get(name));
+
+ return r;
+ }
+
+ /**
+ *
+ */
+ protected Ignite randomBackUp(boolean includeClient) {
+ int nodes = 0;
+
+ List<Ignite> igs = new ArrayList<>();
+
+ for (String name : this.nodes.keySet())
+ if (name.contains(backUpSuffix)){
+ if (includeClient)
+ igs.add(this.nodes.get(name));
+ else {
+ if (name.contains(clientSuffix))
+ continue;
+
+ igs.add(this.nodes.get(name));
+ }
+ }
+
+ int idx = ThreadLocalRandom.current().nextInt(0, igs.size());
+
+ return igs.get(idx);
+ }
+
+
+ /**
+ * @param i Idx.
+ */
+ protected void stopPrimary(int i) {
+ String name = "node" + i + primarySuffix;
+
+ nodes.get(name).close();
+
+ nodes.remove(name);
+ }
+
+ /**
+ *
+ */
+ protected void stopAllPrimary() {
+ stopAll(primarySuffix);
+ }
+
+ /**
+ *
+ */
+ protected void stopAllBackUp() {
+ stopAll(backUpSuffix);
+ }
+
+ /**
+ *
+ */
+ protected void stopAllClient() {
+ stopAll(clientSuffix);
+ }
+
+ /**
+ * @param suffix Suffix.
+ */
+ private void stopAll(String suffix) {
+ for (String name : nodes.keySet())
+ if (name.contains(suffix)) {
+ Ignite ig = nodes.get(name);
+
+ stopGrid(ig.name());
+
+ nodes.remove(name);
+ }
+ }
+
+ /**
+ * @param gridName Grid name.
+ */
+ @Override protected IgniteConfiguration getConfiguration(final String gridName) throws Exception {
+ final IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration();
+
+ pCfg.setPersistentStorePath(testName() + "/db");
+ pCfg.setWalArchivePath(testName() + "/db/wal/archive");
+ pCfg.setWalStorePath(testName() + "/db/wal");
+
+ cfg.setPersistentStoreConfiguration(pCfg);
+
+ final MemoryConfiguration memCfg = new MemoryConfiguration();
+
+ memCfg.setPageSize(1024);
+ memCfg.setConcurrencyLevel(64);
+
+ MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+ memPlcCfg.setInitialSize(5 * 1024 * 1024);
+ memPlcCfg.setMaxSize(5 * 1024 * 1024);
+ memPlcCfg.setName("dfltMemPlc");
+
+ memCfg.setMemoryPolicies(memPlcCfg);
+ memCfg.setDefaultMemoryPolicyName("dfltMemPlc");
+
+ cfg.setMemoryConfiguration(memCfg);
+
+ return cfg;
+ }
+
+ /**
+ *
+ */
+ protected String testName() {
+ return getClass().getSimpleName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java
new file mode 100644
index 0000000..ebbab58
--- /dev/null
+++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateCacheTest.java
@@ -0,0 +1,168 @@
+/*
+ * 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.cache.database.standbycluster;
+
+import javax.cache.configuration.Configuration;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
+import org.apache.ignite.internal.util.typedef.F;
+
+/**
+ *
+ */
+public class IgniteChangeGlobalStateCacheTest extends IgniteChangeGlobalStateAbstractTest {
+ /**
+ *
+ */
+ public void testCheckValueAfterActivation(){
+ String cacheName = "my-cache";
+
+ Ignite ig1P = primary(0);
+
+ Ignite ig1B = backUp(0);
+ Ignite ig2B = backUp(1);
+ Ignite ig3B = backUp(2);
+
+ IgniteCache<String, String> cacheP = ig1P.getOrCreateCache(cacheName);
+
+ cacheP.put("key","value");
+
+ stopAllPrimary();
+
+ ig1B.active(true);
+
+ IgniteCache<String, String> cache1B = ig1B.cache(cacheName);
+ IgniteCache<String, String> cache2B = ig2B.cache(cacheName);
+ IgniteCache<String, String> cache3B = ig3B.cache(cacheName);
+
+ assertTrue(cache1B != null);
+ assertTrue(cache2B != null);
+ assertTrue(cache3B != null);
+
+ assertEquals(cache1B.get("key"), "value");
+ assertEquals(cache2B.get("key"), "value");
+ assertEquals(cache3B.get("key"), "value");
+ }
+
+ /**
+ *
+ */
+ public void testMoreKeyValueAfterActivate() throws Exception {
+ String cacheName = "my-cache";
+
+ Ignite ig1P = primary(0);
+ Ignite ig2P = primary(1);
+ Ignite ig3P = primary(2);
+
+ Ignite ig1B = backUp(0);
+ Ignite ig2B = backUp(1);
+ Ignite ig3B = backUp(2);
+
+ CacheConfiguration<String, String> cacheCfg = new CacheConfiguration<>(cacheName);
+
+ IgniteCache<String, String> cache1P = ig1P.getOrCreateCache(cacheCfg);
+
+ for (int i = 0; i < 4_000; i++)
+ cache1P.put("key" + i, "value" + i);
+
+ IgniteCache<String, String> cache2P = ig2P.cache(cacheName);
+
+ for (int i = 4_000; i < 8_000; i++)
+ cache2P.put("key" + i, "value" + i);
+
+ IgniteCache<String, String> cache3P = ig3P.cache(cacheName);
+
+ for (int i = 8_000; i < 12_000; i++)
+ cache3P.put("key" + i, "value" + i);
+
+ stopAllPrimary();
+
+ ig1B.active(true);
+
+ IgniteCache<String, String> cache1B = ig1B.cache(cacheName);
+ IgniteCache<String, String> cache2B = ig2B.cache(cacheName);
+ IgniteCache<String, String> cache3B = ig3B.cache(cacheName);
+
+ assertTrue(cache1B != null);
+ assertTrue(cache2B != null);
+ assertTrue(cache3B != null);
+
+ for (int i = 0; i < 4_000; i++)
+ assertEquals("value" + i, cache1B.get("key" + i));
+
+ for (int i = 4_000; i < 8_000; i++)
+ assertEquals("value" + i, cache2B.get("key" + i));
+
+ for (int i = 8_000; i < 12_000; i++)
+ assertEquals("value" + i, cache3B.get("key" + i));
+ }
+
+ /**
+ * @throws Exception if fail.
+ */
+ public void testDeActivateAndActivateCacheValue() throws Exception {
+ String chName = "myCache";
+
+ Ignite ig1 = primary(0);
+ Ignite ig2 = primary(1);
+ Ignite ig3 = primary(2);
+
+ IgniteCache<String, String> cacheExp = ig1.getOrCreateCache(chName);
+
+ Configuration<String, String> cfgExp = cacheExp.getConfiguration(CacheConfiguration.class);
+
+ cacheExp.put("key", "value");
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ ig2.active(false);
+
+ IgniteEx ex1 = (IgniteEx)ig1;
+ IgniteEx ex2 = (IgniteEx)ig2;
+ IgniteEx ex3 = (IgniteEx)ig3;
+
+ GridCacheProcessor cache1 = ex1.context().cache();
+ GridCacheProcessor cache2 = ex2.context().cache();
+ GridCacheProcessor cache3 = ex3.context().cache();
+
+ assertTrue(F.isEmpty(cache1.jcaches()));
+ assertTrue(F.isEmpty(cache2.jcaches()));
+ assertTrue(F.isEmpty(cache3.jcaches()));
+
+ assertTrue(!ig1.active());
+ assertTrue(!ig2.active());
+ assertTrue(!ig3.active());
+
+ ig3.active(true);
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ IgniteCache<String, String> cacheAct = ig2.cache(chName);
+
+ Configuration<String, String> cfgAct = cacheAct.getConfiguration(CacheConfiguration.class);
+
+ assertEquals("value", cacheAct.get("key"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java
new file mode 100644
index 0000000..bd65597
--- /dev/null
+++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStreamerTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.cache.database.standbycluster;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+
+/**
+ *
+ */
+public class IgniteChangeGlobalStateDataStreamerTest extends IgniteChangeGlobalStateAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected int backUpNodes() {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int backUpClientNodes() {
+ return 0;
+ }
+
+ /**
+ *
+ */
+ public void testDeActivateAndActivateDataStreamer() throws InterruptedException {
+
+ Ignite ig1 = primary(0);
+ Ignite ig2 = primary(1);
+ Ignite ig3 = primary(2);
+
+ Ignite ig1C = primaryClient(0);
+ Ignite ig2C = primaryClient(1);
+ Ignite ig3C = primaryClient(2);
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ assertTrue(ig1C.active());
+ assertTrue(ig2C.active());
+ assertTrue(ig3C.active());
+
+ String cacheName = "myStreamCache";
+
+ ig2C.getOrCreateCache(cacheName);
+
+ try (IgniteDataStreamer<Integer, String> stmr = ig1.dataStreamer(cacheName)) {
+ for (int i = 0; i < 100; i++)
+ stmr.addData(i, Integer.toString(i));
+ }
+
+ ig2C.active(false);
+
+ assertTrue(!ig1.active());
+ assertTrue(!ig2.active());
+ assertTrue(!ig3.active());
+
+ assertTrue(!ig1C.active());
+ assertTrue(!ig2C.active());
+ assertTrue(!ig3C.active());
+
+ boolean fail = false;
+
+ try {
+ IgniteDataStreamer<String, String> strm2 = ig2.dataStreamer(cacheName);
+ }
+ catch (Exception e) {
+ fail = true;
+
+ assertTrue(e.getMessage().contains("can not perform operation, because cluster inactive"));
+ }
+
+ if (!fail)
+ fail("exception was not throw");
+
+ ig3C.active(true);
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ assertTrue(ig1C.active());
+ assertTrue(ig2C.active());
+ assertTrue(ig3C.active());
+
+ try (IgniteDataStreamer<Integer, String> stmr2 = ig2.dataStreamer(cacheName)) {
+ for (int i = 100; i < 200; i++)
+ stmr2.addData(i, Integer.toString(i));
+ }
+
+ IgniteCache<Integer, String> cache = ig3.cache(cacheName);
+
+ for (int i = 0; i < 200; i++)
+ assertEquals(String.valueOf(i), cache.get(i));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd4d0400/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java
----------------------------------------------------------------------
diff --git a/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java
new file mode 100644
index 0000000..d10521e
--- /dev/null
+++ b/modules/pds/src/test/java/org/apache/ignite/cache/database/standbycluster/IgniteChangeGlobalStateDataStructureTest.java
@@ -0,0 +1,278 @@
+/*
+ * 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.cache.database.standbycluster;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteAtomicLong;
+import org.apache.ignite.IgniteAtomicSequence;
+import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
+
+/**
+ *
+ */
+public class IgniteChangeGlobalStateDataStructureTest extends IgniteChangeGlobalStateAbstractTest {
+ /**
+ *
+ */
+ public void testDeActivateAndActivateAtomicLong() throws Exception{
+ String lName = "myLong";
+
+ Ignite ig1 = primary(0);
+ Ignite ig2 = primary(1);
+ Ignite ig3 = primary(2);
+
+ IgniteAtomicLong lexp = ig1.atomicLong(lName, 100, true);
+
+ lexp.incrementAndGet();
+ lexp.incrementAndGet();
+ lexp.incrementAndGet();
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ ig2.active(false);
+
+ IgniteEx ex1 = (IgniteEx)ig1;
+ IgniteEx ex2 = (IgniteEx)ig2;
+ IgniteEx ex3 = (IgniteEx)ig3;
+
+ GridCacheProcessor cache1 = ex1.context().cache();
+ GridCacheProcessor cache2 = ex2.context().cache();
+ GridCacheProcessor cache3 = ex3.context().cache();
+
+ assertTrue(F.isEmpty(cache1.jcaches()));
+ assertTrue(F.isEmpty(cache2.jcaches()));
+ assertTrue(F.isEmpty(cache3.jcaches()));
+
+ assertTrue(!ig1.active());
+ assertTrue(!ig2.active());
+ assertTrue(!ig3.active());
+
+ ig3.active(true);
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ IgniteAtomicLong lact1 = ig1.atomicLong(lName, 0, false);
+ IgniteAtomicLong lact2 = ig2.atomicLong(lName, 0, false);
+ IgniteAtomicLong lact3 = ig3.atomicLong(lName, 0, false);
+
+ assertEquals(103, lact1.get());
+ assertEquals(103, lact2.get());
+ assertEquals(103, lact3.get());
+
+ lact1.incrementAndGet();
+
+ assertEquals(104, lact1.get());
+ assertEquals(104, lact2.get());
+ assertEquals(104, lact3.get());
+
+ lact2.incrementAndGet();
+
+ assertEquals(105, lact1.get());
+ assertEquals(105, lact2.get());
+ assertEquals(105, lact3.get());
+
+ lact3.incrementAndGet();
+
+ assertEquals(106, lact3.get());
+ assertEquals(106, lact3.get());
+ assertEquals(106, lact3.get());
+ }
+
+ /**
+ *
+ */
+ public void testDeActivateAndActivateCountDownLatch() throws Exception {
+ final AtomicInteger cnt = new AtomicInteger();
+
+ String latchName = "myLatch";
+
+ Ignite ig1 = primary(0);
+ Ignite ig2 = primary(1);
+ Ignite ig3 = primary(2);
+
+ IgniteCountDownLatch latchExp1 = ig1.countDownLatch(latchName, 5, false, true);
+
+ latchExp1.countDown();
+
+ assertEquals(4, latchExp1.count());
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ ig2.active(false);
+
+ IgniteEx ex1 = (IgniteEx)ig1;
+ IgniteEx ex2 = (IgniteEx)ig2;
+ IgniteEx ex3 = (IgniteEx)ig3;
+
+ GridCacheProcessor cache1 = ex1.context().cache();
+ GridCacheProcessor cache2 = ex2.context().cache();
+ GridCacheProcessor cache3 = ex3.context().cache();
+
+ assertTrue(F.isEmpty(cache1.jcaches()));
+ assertTrue(F.isEmpty(cache2.jcaches()));
+ assertTrue(F.isEmpty(cache3.jcaches()));
+
+ assertTrue(!ig1.active());
+ assertTrue(!ig2.active());
+ assertTrue(!ig3.active());
+
+ ig3.active(true);
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ final IgniteCountDownLatch latchAct1 = ig1.countDownLatch(latchName, 0, false, false);
+ final IgniteCountDownLatch latchAct2 = ig2.countDownLatch(latchName, 0, false, false);
+ final IgniteCountDownLatch latchAct3 = ig3.countDownLatch(latchName, 0, false, false);
+
+ runAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ latchAct1.await();
+ cnt.incrementAndGet();
+ return null;
+ }
+ });
+
+ runAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ latchAct2.await();
+ cnt.incrementAndGet();
+ return null;
+ }
+ });
+
+ runAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ latchAct3.await();
+ cnt.incrementAndGet();
+ return null;
+ }
+ });
+
+
+ assertEquals(4, latchAct1.count());
+ assertEquals(4, latchAct2.count());
+ assertEquals(4, latchAct3.count());
+
+ latchAct1.countDown();
+ latchAct2.countDown();
+ latchAct3.countDown();
+
+ assertEquals(1, latchAct1.count());
+ assertEquals(1, latchAct2.count());
+ assertEquals(1, latchAct3.count());
+
+ latchAct1.countDown();
+
+ U.sleep(3000);
+
+ assertEquals(3, cnt.get());
+ }
+
+ /**
+ *
+ */
+ public void testDeActivateAndActivateAtomicSequence(){
+ String seqName = "mySeq";
+
+ Ignite ig1 = primary(0);
+ Ignite ig2 = primary(1);
+ Ignite ig3 = primary(2);
+
+ IgniteAtomicSequence seqExp1 = ig1.atomicSequence(seqName, 0, true);
+ IgniteAtomicSequence seqExp2 = ig2.atomicSequence(seqName, 0, false);
+ IgniteAtomicSequence seqExp3 = ig3.atomicSequence(seqName, 0, false);
+
+ assertEquals(0, seqExp1.get());
+ assertEquals(1000, seqExp2.get());
+ assertEquals(2000, seqExp3.get());
+
+ seqExp1.incrementAndGet();
+ seqExp2.incrementAndGet();
+ seqExp3.incrementAndGet();
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ ig2.active(false);
+
+ IgniteEx ex1 = (IgniteEx)ig1;
+ IgniteEx ex2 = (IgniteEx)ig2;
+ IgniteEx ex3 = (IgniteEx)ig3;
+
+ GridCacheProcessor cache1 = ex1.context().cache();
+ GridCacheProcessor cache2 = ex2.context().cache();
+ GridCacheProcessor cache3 = ex3.context().cache();
+
+ assertTrue(F.isEmpty(cache1.jcaches()));
+ assertTrue(F.isEmpty(cache2.jcaches()));
+ assertTrue(F.isEmpty(cache3.jcaches()));
+
+ assertTrue(!ig1.active());
+ assertTrue(!ig2.active());
+ assertTrue(!ig3.active());
+
+ ig3.active(true);
+
+ assertTrue(ig1.active());
+ assertTrue(ig2.active());
+ assertTrue(ig3.active());
+
+ IgniteAtomicSequence seqAct1 = ig1.atomicSequence(seqName, 0, false);
+ IgniteAtomicSequence seqAct2 = ig2.atomicSequence(seqName, 0, false);
+ IgniteAtomicSequence seqAct3 = ig3.atomicSequence(seqName, 0, false);
+
+ assertEquals(1, seqAct1.get());
+ assertEquals(1001, seqAct2.get());
+ assertEquals(2001, seqAct3.get());
+
+ seqAct1.incrementAndGet();
+
+ assertEquals(2, seqAct1.get());
+ assertEquals(1001, seqAct2.get());
+ assertEquals(2001, seqAct3.get());
+
+ seqAct2.incrementAndGet();
+
+ assertEquals(2, seqAct1.get());
+ assertEquals(1002, seqAct2.get());
+ assertEquals(2001, seqAct3.get());
+
+ seqAct3.incrementAndGet();
+
+ assertEquals(2, seqAct1.get());
+ assertEquals(1002, seqAct2.get());
+ assertEquals(2002, seqAct3.get());
+ }
+}