@Override public void run(IgniteServices services, String svcName, TestService svc) throws Exception { services.deployNodeSingleton(svcName, (Service)svc); waitForServiceDeploymentIfNeeded(services, svcName); } }));
@Override public Void call() throws Exception { info("Start deploy service."); ignite0.services(grp).deployNodeSingleton("testService", new TestService()); info("Service deployed."); return null; } }, "deploy-thread");
/** {@inheritDoc} */ @Override public Object execute() throws IgniteException { ignite.services().deployNodeSingleton(serviceName, new PlatformTestService()); return null; } }
/** * @throws Exception If failed. */ @Test public void testDeployService1() throws Exception { startGridsMultiThreaded(3); grid(0).services(grid(0).cluster()).deployNodeSingleton("test", new GridCacheAbstractFullApiSelfTest.DummyServiceImpl()); }
/** * @throws Exception If failed. */ @Test public void testJobCancel() throws Exception { Ignite server = startGrid("server"); server.services().deployNodeSingleton("my-service", new MyService()); Ignition.setClientMode(true); Ignite client = startGrid("client"); ComputeTaskFuture<Integer> fut = client.compute().executeAsync(new MyTask(), null); Thread.sleep(3000); server.close(); assertEquals(42, fut.get().intValue()); }
/** * @throws Exception If failed. */ @Test public void testGetServiceByName() throws Exception { String name = "serviceByName"; Ignite g = randomGrid(); g.services().deployNodeSingleton(name, new DummyService()); DummyService svc = g.services().service(name); assertNotNull(svc); Collection<DummyService> svcs = g.services().services(name); assertEquals(1, svcs.size()); }
/** * @throws Exception If failed. */ @Test public void testDeployService2() throws Exception { helper.clientMode(false); startGrid(0); helper.clientMode(true); startGrid(1); grid(0).services(grid(0).cluster()).deployNodeSingleton("test", new GridCacheAbstractFullApiSelfTest.DummyServiceImpl()); }
/** * @throws Exception If failed. */ @Test public void testCancelEachNode() throws Exception { Ignite g = randomGrid(); String name = "serviceCancelEachNode"; CountDownLatch latch = new CountDownLatch(nodeCount()); DummyService.exeLatch(name, latch); g.services().deployNodeSingleton(name, new DummyService()); info("Deployed service: " + name); latch.await(); assertEquals(name, nodeCount(), DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); latch = new CountDownLatch(nodeCount()); DummyService.cancelLatch(name, latch); g.services().cancel(name); info("Cancelled service: " + name); latch.await(); assertEquals(name, nodeCount(), DummyService.started(name)); assertEquals(name, nodeCount(), DummyService.cancelled(name)); }
/** * Unwraps error message from InvocationTargetException. * * @throws Exception If failed. */ @SuppressWarnings("ThrowableNotThrown") @Test public void testException() throws Exception { String name = "errorService"; Ignite ignite = grid(0); ignite.services(ignite.cluster().forRemotes()).deployNodeSingleton(name, new ErrorServiceImpl()); final ErrorService svc = ignite.services().serviceProxy(name, ErrorService.class, false); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { svc.go(); return null; } }, ErrorServiceException.class, "Test exception"); }
/** * @throws Exception If failed. */ @Test public void testCancelAsyncEachNode() throws Exception { Ignite g = randomGrid(); String name = "serviceCancelEachNodeAsync"; CountDownLatch latch = new CountDownLatch(nodeCount()); DummyService.exeLatch(name, latch); g.services().deployNodeSingleton(name, new DummyService()); info("Deployed service: " + name); latch.await(); assertEquals(name, nodeCount(), DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); latch = new CountDownLatch(nodeCount()); DummyService.cancelLatch(name, latch); g.services().cancelAsync(name).get(); info("Cancelled service: " + name); latch.await(); assertEquals(name, nodeCount(), DummyService.started(name)); assertEquals(name, nodeCount(), DummyService.cancelled(name)); }
/** * @throws Exception If failed. */ @Test public void testDeployService3() throws Exception { IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Object>() { @Override public Object call() throws Exception { helper.clientModeThreadLocal(true); startGrid(0); return null; } }, "start-node"); helper.clientModeThreadLocal(false); startGrid(1); fut.get(); grid(0).services(grid(0).cluster()).deployNodeSingleton("test", new GridCacheAbstractFullApiSelfTest.DummyServiceImpl()); }
/** * @throws Exception If failed. */ @Test public void testDeployOnEachNodeOld() throws Exception { Ignite g = randomGrid(); String name = "serviceOnEachNodeOld"; CountDownLatch latch = new CountDownLatch(nodeCount()); DummyService.exeLatch(name, latch); IgniteServices svcs = g.services().withAsync(); svcs.deployNodeSingleton(name, new DummyService()); IgniteFuture<?> fut = svcs.future(); info("Deployed service: " + name); fut.get(); info("Finished waiting for service future: " + name); latch.await(); assertEquals(name, nodeCount(), DummyService.started(name)); assertEquals(name, 0, DummyService.cancelled(name)); checkCount(name, g.services().serviceDescriptors(), nodeCount()); }
/** * @throws Exception If failed. */ @Test public void testMultiNodeProxy() throws Exception { Ignite ignite = randomGrid(); int extras = 3; startExtraNodes(extras); String name = "testMultiNodeProxy"; ignite.services().deployNodeSingleton(name, new CounterServiceImpl()); CounterService svc = ignite.services().serviceProxy(name, CounterService.class, false); for (int i = 0; i < extras; i++) { svc.increment(); stopGrid(nodeCount() + i); } assertEquals(extras, svc.get()); }
/** * @throws Exception If failed. */ @Test public void testNodeSingletonNotDeployedProxy() throws Exception { String name = "testNodeSingletonNotDeployedProxy"; IgniteEx ignite = randomGrid(); try { // Deploy only on remote nodes. ignite.services(ignite.cluster().forRemotes()).deployNodeSingleton(name, new CounterServiceImpl()); assertFalse("Should not reach here in this mode, because exception should be thrown.", ignite.context().service() instanceof IgniteServiceProcessor); info("Deployed service: " + name); // Get local proxy. CounterService svc = ignite.services().serviceProxy(name, CounterService.class, false); svc.increment(); fail("Should never reach here."); } catch (IgniteException e) { info("Got expected exception: " + e.getMessage()); } } }
/** * @throws Exception If failed. */ @Test public void testRemoteStickyProxyInvocation() throws Exception { final String name = "testRemoteStickyProxyInvocation"; final Ignite ignite = grid(0); ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>()); // Get remote proxy. MapService<Integer, String> svc = ignite.services(ignite.cluster().forRemotes()). serviceProxy(name, MapService.class, true); // Make sure service is a local instance. assertFalse(svc instanceof Service); for (int i = 0; i < nodeCount(); i++) svc.put(i, Integer.toString(i)); int size = 0; for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { MapService<Integer, String> map = ignite.services(ignite.cluster().forNode(n)). serviceProxy(name, MapService.class, false); // Make sure service is a local instance. assertFalse(map instanceof Service); if (map.size() != 0) size += map.size(); } assertEquals(nodeCount(), size); }
/** * @throws Exception If failed. */ @Test public void testTransformResourceInjection() throws Exception { ClusterGroup servers = grid(0).cluster().forServers(); if(F.isEmpty(servers.nodes())) return; grid(0).services( grid(0).cluster()).deployNodeSingleton(SERVICE_NAME1, new DummyServiceImpl()); IgniteCache<String, Integer> cache = jcache(); Ignite ignite = ignite(0); doTransformResourceInjection(ignite, cache, false, false); doTransformResourceInjection(ignite, cache, true, false); doTransformResourceInjection(ignite, cache, true, true); if (txEnabled()) { doTransformResourceInjectionInTx(ignite, cache, false, false); doTransformResourceInjectionInTx(ignite, cache, true, false); doTransformResourceInjectionInTx(ignite, cache, true, true); } }
/** * @throws Exception If failed. */ @Test public void testDifferentConfigurationOld() throws Exception { String name = "dupServiceOld"; IgniteServices svcs1 = randomGrid().services().withAsync(); IgniteServices svcs2 = randomGrid().services().withAsync(); svcs1.deployClusterSingleton(name, new DummyService()); IgniteFuture<?> fut1 = svcs1.future(); svcs2.deployNodeSingleton(name, new DummyService()); IgniteFuture<?> fut2 = svcs2.future(); info("Deployed service: " + name); fut1.get(); info("Finished waiting for service future: " + name); try { fut2.get(); fail("Failed to receive mismatching configuration exception."); } catch (IgniteException e) { info("Received mismatching configuration exception: " + e.getMessage()); } }
/** * @throws Exception If failed. */ @Test public void testNodeSingletonRemoteNotStickyProxy() throws Exception { String name = "testNodeSingletonRemoteNotStickyProxy"; Ignite ignite = randomGrid(); // Deploy only on remote nodes. ignite.services(ignite.cluster().forRemotes()).deployNodeSingleton(name, new CounterServiceImpl()); info("Deployed service: " + name); // Get local proxy. CounterService svc = ignite.services().serviceProxy(name, CounterService.class, false); for (int i = 0; i < 10; i++) svc.increment(); assertEquals(10, svc.get()); int total = 0; for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { CounterService rmtSvc = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, CounterService.class, false); int cnt = rmtSvc.localIncrements(); // Since deployment is not stick, count on each node must be less than 10. assertTrue("Invalid local increments: " + cnt, cnt != 10); total += cnt; } assertEquals(10, total); }
/** * @throws Exception If failed. */ @Test public void testNodeSingletonRemoteStickyProxy() throws Exception { String name = "testNodeSingletonRemoteStickyProxy"; Ignite ignite = randomGrid(); // Deploy only on remote nodes. ignite.services(ignite.cluster().forRemotes()).deployNodeSingleton(name, new CounterServiceImpl()); // Get local proxy. CounterService svc = ignite.services().serviceProxy(name, CounterService.class, true); for (int i = 0; i < 10; i++) svc.increment(); assertEquals(10, svc.get()); int total = 0; for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { CounterService rmtSvc = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, CounterService.class, false); int cnt = rmtSvc.localIncrements(); assertTrue("Invalid local increments: " + cnt, cnt == 10 || cnt == 0); total += rmtSvc.localIncrements(); } assertEquals(10, total); }
/** * @throws Exception If failed. */ @Test public void testNodeSingletonProxy() throws Exception { String name = "testNodeSingletonProxy"; Ignite ignite = randomGrid(); ignite.services().deployNodeSingleton(name, new CounterServiceImpl()); CounterService svc = ignite.services().serviceProxy(name, CounterService.class, false); for (int i = 0; i < 10; i++) svc.increment(); assertEquals(10, svc.get()); assertEquals(10, svc.localIncrements()); assertEquals(10, ignite.services(ignite.cluster().forLocal()). serviceProxy(name, CounterService.class, false).localIncrements()); // Make sure that remote proxies were not called. for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { CounterService rmtSvc = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, CounterService.class, false); assertEquals(0, rmtSvc.localIncrements()); } }