/** * @param cacheName Cache name. */ private int mapped(String cacheName) { int mapped = 0; ClusterGroup srvs = ignite.cluster().forServers(); Collection<ClusterNode> nodes = srvs.forDataNodes(cacheName).nodes(); for (ClusterNode node : nodes) mapped += ignite.affinity(cacheName).primaryPartitions(node).length; return mapped; }
@Override public boolean apply(Ignite ignite) { return serverCount() <= ignite.cluster().forServers().nodes().size(); } };
/** * Client sends a message and client receives it. * * @param async Async message send flag. * @throws Exception If failed. */ private void clientServerMessage(boolean async) throws Exception { Ignite ignite = grid(CLIENT_NODE_IDX); ClusterGroup grp = ignite.cluster().forServers(); assert !grp.nodes().isEmpty(); registerListenerAndSendMessages(ignite, grp, async); }
/** * @throws Exception If fail. */ private void clientServerOrderedMessage() throws Exception { Ignite ignite = grid(CLIENT_NODE_IDX); ClusterGroup grp = ignite.cluster().forServers(); assert !grp.nodes().isEmpty(); registerListenerAndSendOrderedMessages(ignite, grp); }
/** * @param async If {@code true}, then asynchronous method of deployment will be performed. * @throws Exception If failed. */ private void deployAllFail(boolean async) throws Exception { Ignite client = grid(CLIENT_NODE_NAME); CountDownLatch latch = new CountDownLatch(NUM_SERVICES - 1); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); subscribeExeLatch(cfgs, latch); ServiceConfiguration failingCfg = cfgs.get(cfgs.size() - 1); failingCfg.setName(null); assertFailingDeploy(client, async, cfgs, failingCfg); assertTrue("Waiting for services deployment timed out.", latch.await(30, TimeUnit.SECONDS)); assertDeployedServices(client, cfgs.subList(0, cfgs.size() - 1)); }
@Override public boolean apply(final Ignite ignite) { Collection<ClusterNode> srvs = ignite.cluster().forServers().nodes(); if (srvs.size() < serverCount()) return false; for (ClusterNode node : srvs) { int[] primaries = ignite.affinity(CACHE_NAME).primaryPartitions(node); if (primaries == null || primaries.length == 0) return false; } return true; } };
/** * Test execution of --wal delete command. * * @throws Exception if failed. */ @Test public void testUnusedWalDelete() throws Exception { Ignite ignite = startGrids(2); ignite.cluster().active(true); List<String> nodes = new ArrayList<>(2); for (ClusterNode node : ignite.cluster().forServers().nodes()) nodes.add(node.consistentId().toString()); injectTestSystemOut(); assertEquals(EXIT_CODE_OK, execute("--wal", "delete")); for (String id : nodes) assertTrue(testOut.toString().contains(id)); assertTrue(!testOut.toString().contains("error")); testOut.reset(); assertEquals(EXIT_CODE_OK, execute("--wal", "delete", nodes.get(0))); assertTrue(!testOut.toString().contains(nodes.get(1))); assertTrue(!testOut.toString().contains("error")); }
/** * Test execution of --wal print command. * * @throws Exception if failed. */ @Test public void testUnusedWalPrint() throws Exception { Ignite ignite = startGrids(2); ignite.cluster().active(true); List<String> nodes = new ArrayList<>(2); for (ClusterNode node : ignite.cluster().forServers().nodes()) nodes.add(node.consistentId().toString()); injectTestSystemOut(); assertEquals(EXIT_CODE_OK, execute("--wal", "print")); for (String id : nodes) assertTrue(testOut.toString().contains(id)); assertTrue(!testOut.toString().contains("error")); testOut.reset(); assertEquals(EXIT_CODE_OK, execute("--wal", "print", nodes.get(0))); assertTrue(!testOut.toString().contains(nodes.get(1))); assertTrue(!testOut.toString().contains("error")); }
/** * @throws Exception If failed. */ @Test public void testClashingNameDifferentConfig() throws Exception { Ignite client = grid(CLIENT_NODE_NAME); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); int numDepSvcs = NUM_SERVICES - 1; CountDownLatch latch = new CountDownLatch(numDepSvcs); List<ServiceConfiguration> fstBatch = cfgs.subList(0, NUM_SERVICES / 2); List<ServiceConfiguration> sndBatch = cfgs.subList(NUM_SERVICES / 4, NUM_SERVICES - 1); subscribeExeLatch(cfgs, latch); client.services().deployAll(fstBatch); ServiceConfiguration failingCfg = copyService(cfgs.get(NUM_SERVICES - 1)); // Same name, different config. failingCfg.setName(fstBatch.get(0).getName()); failingCfg.setTotalCount(fstBatch.get(0).getTotalCount() + 1); sndBatch.add(failingCfg); assertFailingDeploy(client, false, sndBatch, failingCfg); assertTrue("Waiting for services deployment timed out.", latch.await(30, TimeUnit.SECONDS)); assertDeployedServices(client, cfgs.subList(0, numDepSvcs)); }
/** * @throws Exception If failed. */ @Test public void testClashingNamesFail() throws Exception { Ignite client = grid(CLIENT_NODE_NAME); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); int numDepSvcs = NUM_SERVICES - 1; CountDownLatch latch = new CountDownLatch(numDepSvcs); List<ServiceConfiguration> fstBatch = cfgs.subList(0, NUM_SERVICES / 2); List<ServiceConfiguration> sndBatch = cfgs.subList(NUM_SERVICES / 4, NUM_SERVICES); subscribeExeLatch(cfgs, latch); IgniteFuture<Void> fut = client.services().deployAllAsync(fstBatch); ServiceConfiguration failingCfg = cfgs.get(NUM_SERVICES - 1); failingCfg.setName(null); assertFailingDeploy(client, false, sndBatch, failingCfg); fut.get(); assertTrue("Waiting for services deployment timed out.", latch.await(30, TimeUnit.SECONDS)); assertDeployedServices(client, cfgs.subList(0, numDepSvcs)); }
/** * @throws Exception If failed. */ @Test public void testCancelAll() throws Exception { Ignite client = grid(CLIENT_NODE_NAME); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); CountDownLatch latch = new CountDownLatch(NUM_SERVICES); subscribeExeLatch(cfgs, latch); client.services().deployAll(cfgs); latch.await(30, TimeUnit.SECONDS); client.services().cancelAll(); assertDeployedServices(client, Collections.<ServiceConfiguration>emptyList()); }
/** * @throws Exception If failed. */ @Test public void testDeployAll() throws Exception { Ignite client = grid(CLIENT_NODE_NAME); CountDownLatch latch = new CountDownLatch(NUM_SERVICES); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); subscribeExeLatch(cfgs, latch); client.services().deployAll(cfgs); assertTrue("Waiting for services deployment timed out.", latch.await(30, TimeUnit.SECONDS)); assertDeployedServices(client, cfgs); }
/** {@inheritDoc} */ @Override public void run() { IgniteCountDownLatch latch1 = createLatch1(); IgniteCountDownLatch latch2 = createLatch2(); IgniteCache<Object, Object> cache = igniteInstance.cache("testCache"); for (ClusterNode node : igniteInstance.cluster().forServers().nodes()) { Integer val = (Integer)cache.get(String.valueOf(node.id())); assertEquals(val, (Integer)iteration); } latch1.countDown(); assertTrue(latch1.await(10000)); cache.put(getUID(), (iteration + 1)); latch2.countDown(); }
/** * @throws Exception If failed. */ @Test public void testCancelAllAsync() throws Exception { Ignite client = grid(CLIENT_NODE_NAME); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); CountDownLatch latch = new CountDownLatch(NUM_SERVICES); subscribeExeLatch(cfgs, latch); client.services().deployAll(cfgs); latch.await(30, TimeUnit.SECONDS); IgniteFuture<Void> fut = client.services().cancelAllAsync(); fut.get(); assertDeployedServices(client, Collections.<ServiceConfiguration>emptyList()); }
/** * @throws Exception If failed. */ @Test public void testDeployAllAsync() throws Exception { Ignite client = grid(CLIENT_NODE_NAME); CountDownLatch latch = new CountDownLatch(NUM_SERVICES); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); subscribeExeLatch(cfgs, latch); IgniteFuture<Void> fut = client.services().deployAllAsync(cfgs); fut.get(); assertTrue("Waiting for services deployment timed out.", latch.await(30, TimeUnit.SECONDS)); assertDeployedServices(client, cfgs); }
/** * */ @Test public void testAddNodeToBaselineTopology() throws Exception { final long expectedActivationHash = (long)"A".hashCode() + "B".hashCode() + "C".hashCode() + "D".hashCode(); BaselineTopologyVerifier verifier = new BaselineTopologyVerifier() { @Override public void verify(BaselineTopology blt) { assertNotNull(blt); assertEquals(4, blt.consistentIds().size()); long activationHash = U.field(blt, "branchingPntHash"); assertEquals(expectedActivationHash, activationHash); } }; Ignite nodeA = startGridWithConsistentId("A"); Ignite nodeB = startGridWithConsistentId("B"); Ignite nodeC = startGridWithConsistentId("C"); nodeC.cluster().active(true); IgniteEx nodeD = (IgniteEx) startGridWithConsistentId("D"); nodeD.cluster().setBaselineTopology(baselineNodes(nodeA.cluster().forServers().nodes())); verifyBaselineTopologyOnNodes(verifier, new Ignite[]{nodeA, nodeB, nodeC, nodeD}); }
/** * @throws Exception If failed. */ @Test public void testClashingNames() throws Exception { Ignite client = grid(CLIENT_NODE_NAME); CountDownLatch latch = new CountDownLatch(NUM_SERVICES); List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES); subscribeExeLatch(cfgs, latch); List<ServiceConfiguration> fstBatch = cfgs.subList(0, NUM_SERVICES / 2); List<ServiceConfiguration> sndBatch = cfgs.subList(NUM_SERVICES / 4, NUM_SERVICES); IgniteFuture<Void> fstFut = client.services().deployAllAsync(fstBatch); IgniteFuture<Void> sndFut = client.services().deployAllAsync(sndBatch); fstFut.get(); sndFut.get(); assertTrue("Waiting for services deployment timed out.", latch.await(30, TimeUnit.SECONDS)); assertDeployedServices(client, cfgs); }
/** * @throws Exception If failed. */ @Test public void testForDaemons() throws Exception { assertEquals(4, ignite.cluster().nodes().size()); ClusterGroup daemons = ignite.cluster().forDaemons(); ClusterGroup srvs = ignite.cluster().forServers(); assertEquals(0, daemons.nodes().size()); assertEquals(2, srvs.nodes().size()); Ignition.setDaemon(true); try (Ignite g = startGrid(NODES_CNT)) { Ignition.setDaemon(false); try (Ignite g1 = startGrid(NODES_CNT + 1)) { assertEquals(1, ignite.cluster().forDaemons().nodes().size()); assertEquals(3, srvs.nodes().size()); assertEquals(1, daemons.nodes().size()); } } }
/** * @throws Exception If failed. */ @Test public void testClientServer() throws Exception { ClusterGroup srv = ignite.cluster().forServers(); assertEquals(2, srv.nodes().size()); assertTrue(srv.nodes().contains(ignite(0).cluster().localNode())); assertTrue(srv.nodes().contains(ignite(1).cluster().localNode())); ClusterGroup cli = ignite.cluster().forClients(); assertEquals(2, srv.nodes().size()); assertTrue(cli.nodes().contains(ignite(2).cluster().localNode())); assertTrue(cli.nodes().contains(ignite(3).cluster().localNode())); }
/** * @throws Exception If failed. */ @Test public void testLatchBroadcast() throws Exception { Ignite ignite = grid(0); ClusterGroup srvsGrp = ignite.cluster().forServers(); int numOfSrvs = srvsGrp.nodes().size(); ignite.destroyCache("testCache"); IgniteCache<Object, Object> cache = ignite.createCache("testCache"); for (ClusterNode node : srvsGrp.nodes()) cache.put(String.valueOf(node.id()), 0); for (int i = 0; i < 500; i++) { IgniteCountDownLatch latch1 = createLatch1(ignite, numOfSrvs); IgniteCountDownLatch latch2 = createLatch2(ignite, numOfSrvs); ignite.compute(srvsGrp).broadcast(new IgniteRunnableJob(latch1, latch2, i)); assertTrue(latch2.await(10000)); } }