Repository: ignite Updated Branches: refs/heads/ignite-zk feb1b7b8b -> 0a9fefb71
zk Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0a9fefb7 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0a9fefb7 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0a9fefb7 Branch: refs/heads/ignite-zk Commit: 0a9fefb71a4b62890b08a56f0c2437a6ef949e1d Parents: feb1b7b Author: sboikov <[email protected]> Authored: Tue Jan 9 23:32:29 2018 +0300 Committer: sboikov <[email protected]> Committed: Tue Jan 9 23:32:29 2018 +0300 ---------------------------------------------------------------------- .../discovery/zk/internal/ZookeeperClient.java | 8 +- .../zk/internal/ZookeeperDiscoveryImpl.java | 26 +++- .../continuous/GridEventConsumeSelfTest.java | 2 +- .../zk/internal/ZookeeperClientTest.java | 2 - .../zk/internal/ZookeeperDiscoverySpiTest.java | 1 - .../config/GridTestProperties.java | 9 ++ .../testframework/junits/GridAbstractTest.java | 21 +++ .../zk/ZookeeperDiscoverySpiTestSuite1.java | 40 ++++++ .../zk/ZookeeperDiscoverySpiTestSuite2.java | 138 +++++++++++++++++++ ...ZookeeperDiscoverySuitePreprocessorTest.java | 101 ++++++++++++++ .../zk/ZookeeperDiscoveryTestSuite.java | 40 ------ 11 files changed, 335 insertions(+), 53 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java index 5085012..786d997 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java @@ -176,8 +176,12 @@ public class ZookeeperClient implements Watcher { switch (zkState) { case SaslAuthenticated: - // No-op. - return; + return; // No-op. + + case AuthFailed: + newState = state; + + break; case Disconnected: newState = ConnectionState.Disconnected; http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java index 030e43e..fb57eb0 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java @@ -843,11 +843,19 @@ public class ZookeeperDiscoveryImpl { * @param zkClient Client. * @param basePath Base path. * @param partCnt Parts count. + * @param checkExists If {@code true} checks path exists before calling delete (this check added to avoid errors + * in ZooKeeper log). + * @throws Exception If failed. */ - private void deleteMultiplePartsAsync(ZookeeperClient zkClient, String basePath, int partCnt) { + private void deleteMultiplePartsAsync(ZookeeperClient zkClient, String basePath, int partCnt, boolean checkExists) + throws Exception + { for (int i = 0; i < partCnt; i++) { String path = multipartPathName(basePath, i); + if (checkExists && !zkClient.exists(path)) + continue; + zkClient.deleteIfExistsAsync(path); } } @@ -3540,8 +3548,9 @@ public class ZookeeperDiscoveryImpl { /** * @param evtData Event data. + * @throws Exception If failed. */ - private void handleProcessedJoinEventAsync(ZkDiscoveryNodeJoinEventData evtData) { + private void handleProcessedJoinEventAsync(ZkDiscoveryNodeJoinEventData evtData) throws Exception { if (log.isDebugEnabled()) log.debug("All nodes processed node join [evtData=" + evtData + ']'); @@ -3552,7 +3561,8 @@ public class ZookeeperDiscoveryImpl { if (evtData.secSubjPartCnt > 0) { deleteMultiplePartsAsync(rtState.zkClient, zkPaths.joinEventSecuritySubjectPath(evtData.eventId()), - evtData.secSubjPartCnt); + evtData.secSubjPartCnt, + false); } } @@ -3560,8 +3570,9 @@ public class ZookeeperDiscoveryImpl { * @param nodeId Node ID. * @param joinDataPrefixId Path prefix. * @param partCnt Parts count. + * @throws Exception If failed. */ - private void deleteJoiningNodeData(UUID nodeId, UUID joinDataPrefixId, int partCnt) { + private void deleteJoiningNodeData(UUID nodeId, UUID joinDataPrefixId, int partCnt) throws Exception { String evtDataPath = zkPaths.joiningNodeDataPath(nodeId, joinDataPrefixId); if (log.isDebugEnabled()) @@ -3570,19 +3581,20 @@ public class ZookeeperDiscoveryImpl { rtState.zkClient.deleteIfExistsAsync(evtDataPath); if (partCnt > 1) - deleteMultiplePartsAsync(rtState.zkClient, evtDataPath + ":", partCnt); + deleteMultiplePartsAsync(rtState.zkClient, evtDataPath + ":", partCnt, true); } /** * @param evtData Event data. + * @throws Exception If failed. */ - private void deleteDataForJoinedAsync(ZkDiscoveryNodeJoinEventData evtData) { + private void deleteDataForJoinedAsync(ZkDiscoveryNodeJoinEventData evtData) throws Exception { String dataForJoinedPath = zkPaths.joinEventDataPathForJoined(evtData.eventId()); if (log.isDebugEnabled()) log.debug("Delete data for joined node [path=" + dataForJoinedPath + ']'); - deleteMultiplePartsAsync(rtState.zkClient, dataForJoinedPath, evtData.dataForJoinedPartCnt); + deleteMultiplePartsAsync(rtState.zkClient, dataForJoinedPath, evtData.dataForJoinedPartCnt, true); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java index f07b1a3..21bfdd0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java @@ -1165,7 +1165,7 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest { @Override public boolean apply(UUID uuid, Event evt) { return true; } - }, null, EVT_JOB_STARTED).get(3000); + }, null, EVT_JOB_STARTED).get(10_000); started.add(consumeId); http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientTest.java index 899b8e6..37dd350 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClientTest.java @@ -34,8 +34,6 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.zookeeper.AsyncCallback; import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.Stat; http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java index e020bcc..2fa798f 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiTest.java @@ -90,7 +90,6 @@ import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.lang.IgniteOutClosure; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.lang.IgniteUuid; -import org.apache.ignite.logger.java.JavaLogger; import org.apache.ignite.marshaller.jdk.JdkMarshaller; import org.apache.ignite.plugin.security.SecurityCredentials; import org.apache.ignite.plugin.security.SecurityPermission; http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java index 4507572..e2594ca 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java @@ -83,6 +83,15 @@ public final class GridTestProperties { /** "True value" enables {@link BinaryBasicNameMapper} in {@link BinaryTypeConfiguration#getNameMapper()} */ public static final String BINARY_MARSHALLER_USE_SIMPLE_NAME_MAPPER = "binary.marshaller.use.simple.name.mapper"; + /** + * Name of class which provides static method preprocessConfiguration(IgniteConfiguration cfg) to + * alter {@link org.apache.ignite.configuration.IgniteConfiguration} before node is started. + * <p> + * Note: this pre-preprocessor is started only if test starts node using one of GridAbstractTest's startGrid + * method. + */ + public static final String IGNITE_CFG_PREPROCESSOR_CLS = "ignite.cfg.preprocessor.class"; + /** */ static { // Initialize IGNITE_HOME system property. http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index 15cec62..09ed8f8 100755 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -125,6 +125,7 @@ import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; import static org.apache.ignite.internal.GridKernalState.DISCONNECTED; import static org.apache.ignite.testframework.config.GridTestProperties.BINARY_MARSHALLER_USE_SIMPLE_NAME_MAPPER; +import static org.apache.ignite.testframework.config.GridTestProperties.IGNITE_CFG_PREPROCESSOR_CLS; /** * Common abstract test for Ignite tests. @@ -855,6 +856,26 @@ public abstract class GridAbstractTest extends TestCase { startingIgniteInstanceName.set(igniteInstanceName); try { + String cfgProcClsName = System.getProperty(IGNITE_CFG_PREPROCESSOR_CLS); + + if (cfgProcClsName != null) { + try { + Class<?> cfgProc = Class.forName(cfgProcClsName); + + Method method = cfgProc.getMethod("preprocessConfiguration", IgniteConfiguration.class); + + if (!Modifier.isStatic(method.getModifiers())) + throw new Exception("Non-static pre-processor method in pre-processor class: " + cfgProcClsName); + + method.invoke(null, cfg); + } + catch (Exception e) { + log.error("Failed to pre-process IgniteConfiguration using pre-processor class: " + cfgProcClsName); + + throw new IgniteException(e); + } + } + Ignite node = IgnitionEx.start(cfg, ctx); IgniteConfiguration nodeCfg = node.configuration(); http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite1.java ---------------------------------------------------------------------- diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite1.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite1.java new file mode 100644 index 0000000..8e076f1 --- /dev/null +++ b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite1.java @@ -0,0 +1,40 @@ +/* + * 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.spi.discovery.zk; + +import junit.framework.TestSuite; +import org.apache.ignite.spi.discovery.zk.internal.ZookeeperClientTest; +import org.apache.ignite.spi.discovery.zk.internal.ZookeeperDiscoverySpiTest; + +/** + * + */ +public class ZookeeperDiscoverySpiTestSuite1 extends TestSuite { + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("ZookeeperDiscoverySpi Test Suite"); + + suite.addTestSuite(ZookeeperClientTest.class); + suite.addTestSuite(ZookeeperDiscoverySpiTest.class); + + return suite; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite2.java ---------------------------------------------------------------------- diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite2.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite2.java new file mode 100644 index 0000000..5639815 --- /dev/null +++ b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpiTestSuite2.java @@ -0,0 +1,138 @@ +/* + * 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.spi.discovery.zk; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import junit.framework.TestSuite; +import org.apache.curator.test.InstanceSpec; +import org.apache.curator.test.TestingCluster; +import org.apache.ignite.IgniteException; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteClientReconnectCacheTest; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteCachePutRetryAtomicSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteCachePutRetryTransactionalSelfTest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridCachePartitionedNodeRestartTest; +import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedNodeRestartSelfTest; +import org.apache.ignite.internal.processors.continuous.GridEventConsumeSelfTest; +import org.apache.ignite.spi.discovery.DiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.testframework.config.GridTestProperties; + +/** + * Regular Ignite tests executed with ZookeeperDiscoverySpi. + */ +public class ZookeeperDiscoverySpiTestSuite2 extends TestSuite { + /** */ + private static TestingCluster testingCluster; + + /** + * @return Test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + IgnitionEx.TEST_ZK = false; + + System.setProperty("zookeeper.forceSync", "false"); + + testingCluster = createTestingCluster(3); + + testingCluster.start(); + + System.setProperty(GridTestProperties.IGNITE_CFG_PREPROCESSOR_CLS, ZookeeperDiscoverySpiTestSuite2.class.getName()); + + TestSuite suite = new TestSuite("ZookeeperDiscoverySpi Test Suite"); + + suite.addTestSuite(ZookeeperDiscoverySuitePreprocessorTest.class); + suite.addTestSuite(GridEventConsumeSelfTest.class); + suite.addTestSuite(IgniteClientReconnectCacheTest.class); + suite.addTestSuite(IgniteCachePutRetryAtomicSelfTest.class); + suite.addTestSuite(IgniteCachePutRetryTransactionalSelfTest.class); + suite.addTestSuite(GridCachePartitionedNodeRestartTest.class); + suite.addTestSuite(GridCacheReplicatedNodeRestartSelfTest.class); + + return suite; + } + /** + * Called via reflection by {@link org.apache.ignite.testframework.junits.GridAbstractTest}. + * + * @param cfg Configuration to change. + */ + public synchronized static void preprocessConfiguration(IgniteConfiguration cfg) { + if (testingCluster == null) + throw new IllegalStateException("Test Zookeeper cluster is not started."); + + ZookeeperDiscoverySpi zkSpi = new ZookeeperDiscoverySpi(); + + DiscoverySpi spi = cfg.getDiscoverySpi(); + + if (spi instanceof TcpDiscoverySpi) + zkSpi.setClientReconnectDisabled(((TcpDiscoverySpi)spi).isClientReconnectDisabled()); + + zkSpi.setSessionTimeout(20_000); + zkSpi.setZkConnectionString(testingCluster.getConnectString()); + + cfg.setDiscoverySpi(zkSpi); + } + + /** + * @param instances Number of instances in + * @return Test cluster. + */ + public static TestingCluster createTestingCluster(int instances) { + String tmpDir = System.getProperty("java.io.tmpdir"); + + List<InstanceSpec> specs = new ArrayList<>(); + + for (int i = 0; i < instances; i++) { + File file = new File(tmpDir, "apacheIgniteTestZk-" + i); + + if (file.isDirectory()) + deleteRecursively0(file); + else { + if (!file.mkdirs()) + throw new IgniteException("Failed to create directory for test Zookeeper server: " + file.getAbsolutePath()); + } + + specs.add(new InstanceSpec(file, -1, -1, -1, true, -1, -1, 500)); + } + + return new TestingCluster(specs); + } + + /** + * @param file File or directory to delete. + */ + private static void deleteRecursively0(File file) { + File[] files = file.listFiles(); + + if (files == null) + return; + + for (File f : files) { + if (f.isDirectory()) + deleteRecursively0(f); + else { + if (!f.delete()) + throw new IgniteException("Failed to delete file: " + f.getAbsolutePath()); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySuitePreprocessorTest.java ---------------------------------------------------------------------- diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySuitePreprocessorTest.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySuitePreprocessorTest.java new file mode 100644 index 0000000..28cf17f --- /dev/null +++ b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySuitePreprocessorTest.java @@ -0,0 +1,101 @@ +/* + * 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.spi.discovery.zk; + +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.spi.discovery.DiscoverySpi; +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.config.GridTestProperties; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Sanity test verifying that configuration callback specified via + * {@link GridTestProperties#IGNITE_CFG_PREPROCESSOR_CLS} really works. + * <p> + * This test should be run as part of {@link ZookeeperDiscoverySpiTestSuite2}. + */ +public class ZookeeperDiscoverySuitePreprocessorTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + // Test sets TcpDiscoverySpi, but it should be automatically changed to ZookeeperDiscoverySpi. + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + + spi.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(spi); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** + * @throws Exception If failed. + */ + public void testSpiConfigurationIsChanged() throws Exception { + startGrid(0); + + checkDiscoverySpi(1); + + startGrid(1); + + checkDiscoverySpi(2); + + startGridsMultiThreaded(2, 2); + + checkDiscoverySpi(4); + + startGrid(); + + checkDiscoverySpi(5); + } + + /** + * @param expNodes Expected nodes number. + * @throws Exception If failed. + */ + private void checkDiscoverySpi(int expNodes) throws Exception { + List<Ignite> nodes = G.allGrids(); + + assertEquals(expNodes, nodes.size()); + + for (Ignite node : nodes) { + DiscoverySpi spi = node.configuration().getDiscoverySpi(); + + assertTrue("Node should be started with " + ZookeeperDiscoverySpi.class.getName(), + spi instanceof ZookeeperDiscoverySpi); + } + + waitForTopology(expNodes); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/0a9fefb7/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoveryTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoveryTestSuite.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoveryTestSuite.java deleted file mode 100644 index 4ea9b37..0000000 --- a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoveryTestSuite.java +++ /dev/null @@ -1,40 +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.spi.discovery.zk; - -import junit.framework.TestSuite; -import org.apache.ignite.internal.processors.continuous.GridEventConsumeSelfTest; - -/** - * - */ -public class ZookeeperDiscoveryTestSuite extends TestSuite { - /** - * @return Test suite. - * @throws Exception Thrown in case of the failure. - */ - public static TestSuite suite() throws Exception { - // TODO ZK - TestSuite suite = new TestSuite("ZookeeperDiscoverySpi Test Suite"); - - // Regular tests executed with ZookeeperDiscoverySpi. - suite.addTestSuite(GridEventConsumeSelfTest.class); - - return suite; - } -}
