@Override public Void call() throws Exception { IgniteServices svcs = ignite.services(); IgniteFuture f = svcs.deployClusterSingletonAsync("myClusterSingletonService", new TestServiceImpl()); depLatch.countDown(); try { f.get(); } catch (IgniteException ignored) { finishLatch.countDown(); } finally { finishLatch.countDown(); } return null; } }, "deploy-thread");
/** * @throws Exception If failed. */ @Test public void testSameConfiguration() throws Exception { String name = "dupServiceOld"; IgniteServices svcs1 = randomGrid().services(); IgniteServices svcs2 = randomGrid().services(); IgniteFuture<?> fut1 = svcs1.deployClusterSingletonAsync(name, new DummyService()); IgniteFuture<?> fut2 = svcs2.deployClusterSingletonAsync(name, new DummyService()); info("Deployed service: " + name); fut1.get(); info("Finished waiting for service future1: " + name); // This must succeed without exception because configuration is the same. fut2.get(); info("Finished waiting for service future2: " + name); }
/** * @param staticDeploy If {@code true}, then static deployment will be used instead of a dynamic one. * @param nodeNum Nouber of test node. * @throws Exception If node failed to start. */ private Ignite deployServiceFromNewNode(boolean staticDeploy, int nodeNum) throws Exception { Ignite ignite; if (staticDeploy) { srvcCfg = getClusterSingletonServiceConfiguration(); ignite = startGrid(nodeNum); } else { ignite = startGrid(nodeNum); IgniteFuture<Void> depFut = ignite.services().deployClusterSingletonAsync(SERVICE_NAME, new DummyService()); depFut.get(10, TimeUnit.SECONDS); } return ignite; }
/** * @throws Exception If failed. */ @Test public void testDeploySingleton() throws Exception { Ignite g = randomGrid(); String name = "serviceSingleton"; CountDownLatch latch = new CountDownLatch(1); DummyService.exeLatch(name, latch); IgniteFuture<?> fut = g.services().deployClusterSingletonAsync(name, new DummyService()); info("Deployed service: " + name); fut.get(); info("Finished waiting for service future: " + name); latch.await(); assertEquals(name, 1, DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); checkCount(name, g.services().serviceDescriptors(), 1); }
/** * @param from If {@code true}, then added node will be an initiator of deployment. * Otherwise deployment <b>to</b> this node will be tested. * @throws Exception If failed. */ private void checkDeployWithNodeAddedToBlt(boolean from) throws Exception { persistence = true; Ignite insideNode = startGrid(0); IgniteCluster cluster = insideNode.cluster(); cluster.active(true); Ignite outsideNode = startGrid(1); cluster.setBaselineTopology(cluster.topologyVersion()); CountDownLatch exeLatch = new CountDownLatch(from ? 1 : 2); DummyService.exeLatch(SERVICE_NAME, exeLatch); if (from) { IgniteFuture<Void> depFut = outsideNode.services().deployClusterSingletonAsync(SERVICE_NAME, new DummyService()); depFut.get(10, TimeUnit.SECONDS); } else { IgniteFuture<Void> depFut = outsideNode.services().deployNodeSingletonAsync(SERVICE_NAME, new DummyService()); depFut.get(10, TimeUnit.SECONDS); } assertTrue(exeLatch.await(10, TimeUnit.SECONDS)); }
/** * @throws Exception If failed. */ @Test public void testSingletonUpdateTopology() throws Exception { String name = "serviceSingletonUpdateTopology"; IgniteEx g = randomGrid(); CountDownLatch latch = new CountDownLatch(1); DummyService.exeLatch(name, latch); IgniteServices svcs = g.services(); IgniteFuture<?> fut = svcs.deployClusterSingletonAsync(name, new DummyService()); info("Deployed service: " + name); fut.get(); info("Finished waiting for service future: " + name); latch.await(); Assert.assertEquals(name, 1, DummyService.started(name)); Assert.assertEquals(name, 0, DummyService.cancelled(name)); int nodeCnt = 2; startExtraNodes(nodeCnt); try { Assert.assertEquals(name, 1, DummyService.started(name)); Assert.assertEquals(name, 0, DummyService.cancelled(name)); info(">>> Passed checks."); checkCount(name, g, 1); } finally { stopExtraNodes(nodeCnt); } }
/** * @throws Exception If failed. */ @Test public void testDifferentConfiguration() throws Exception { String name = "dupService"; IgniteServices svcs1 = randomGrid().services(); IgniteServices svcs2 = randomGrid().services(); IgniteFuture<?> fut1 = svcs1.deployClusterSingletonAsync(name, new DummyService()); IgniteFuture<?> fut2 = svcs2.deployNodeSingletonAsync(name, new DummyService()); info("Deployed service: " + name); try { fut1.get(); info("Finished waiting for service future: " + name); fut2.get(); fail("Failed to receive mismatching configuration exception."); } catch (IgniteException e) { info("Received mismatching configuration exception: " + e.getMessage()); } }