@Override public boolean apply() { return svcs.service(svcName) == null; } }, 10 * 1000);
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws IgniteCheckedException { ServiceResource ann = (ServiceResource)mtd.getAnnotation(); Class svcItf = ann.proxyInterface(); Object svc; if (svcItf == Void.class) svc = ignite.services().service(ann.serviceName()); else svc = ignite.services().serviceProxy(ann.serviceName(), svcItf, ann.proxySticky()); Class<?>[] types = mtd.getMethod().getParameterTypes(); if (types.length != 1) throw new IgniteCheckedException("Setter does not have single parameter of required type [type=" + svc.getClass().getName() + ", setter=" + mtd + ']'); if (svc != null) GridResourceUtils.inject(mtd.getMethod(), target, svc); } }
/** * @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()); }
/** * */ @Ignore("https://issues.apache.org/jira/browse/IGNITE-6629") @Test 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); }
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws IgniteCheckedException { ServiceResource ann = (ServiceResource)field.getAnnotation(); Class svcItf = ann.proxyInterface(); Object svc; if (svcItf == Void.class) svc = ignite.services().service(ann.serviceName()); else svc = ignite.services().serviceProxy(ann.serviceName(), svcItf, ann.proxySticky()); if (svc != null) GridResourceUtils.inject(field.getField(), target, svc); }
@Override public boolean apply() { return svcs.service(svcName) != null; } }, 10 * 1000);
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws IgniteCheckedException { ServiceResource ann = (ServiceResource)mtd.getAnnotation(); Class svcItf = ann.proxyInterface(); Object svc; if (svcItf == Void.class) svc = ignite.services().service(ann.serviceName()); else svc = ignite.services().serviceProxy(ann.serviceName(), svcItf, ann.proxySticky()); Class<?>[] types = mtd.getMethod().getParameterTypes(); if (types.length != 1) throw new IgniteCheckedException("Setter does not have single parameter of required type [type=" + svc.getClass().getName() + ", setter=" + mtd + ']'); if (svc != null) GridResourceUtils.inject(mtd.getMethod(), target, svc); } }
@Override public boolean apply() { return svcs.service(svcName) != null; } }, 10 * 1000);
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws IgniteCheckedException { ServiceResource ann = (ServiceResource)field.getAnnotation(); Class svcItf = ann.proxyInterface(); Object svc; if (svcItf == Void.class) svc = ignite.services().service(ann.serviceName()); else svc = ignite.services().serviceProxy(ann.serviceName(), svcItf, ann.proxySticky()); if (svc != null) GridResourceUtils.inject(field.getField(), target, svc); }
@Override public boolean apply() { return svcs.service(svcName) == null; } }, 10 * 1000);
/** * @param services Ignite services. * @param srvcName Service name to wait. * @throws IgniteInterruptedCheckedException If interrupted. */ private void waitForServiceDeploymentIfNeeded(IgniteServices services, String srvcName) throws IgniteInterruptedCheckedException { if (!isEventDrivenServiceProcessorEnabled) GridTestUtils.waitForCondition(() -> services.service(srvcName) != null, DEPLOYMENT_WAIT_TIMEOUT); }
@Override public boolean apply() { TestService srvc = grid(srvcNode).services().service(srvcName); if (srvc == null) return false; assertEquals(srvcNode, srvc.serviceNode()); return true; } }, 5000);
@Override public Object execute() throws IgniteException { MyService svc = ignite.services().service("my-service"); while (!isCancelled()) { try { Thread.sleep(1000); svc.hello(); } catch (InterruptedException ignored) { // No-op. } } assertTrue(isCancelled()); return svc.hello(); } });
Ignite ignite = entry.unwrap(Ignite.class); PartitionObserver observer = ignite.services().service(PartitionObserver.class.getName());
assertNotNull(node0.services().service("myService"));
/** * @throws Exception In case of an error. */ @Test public void testDeploymentProcessingOnCoordinatorLeaveTopology() throws Exception { try { IgniteEx ignite0 = (IgniteEx)startGrids(4); ((BlockingTcpDiscoverySpi)ignite0.context().discovery().getInjectedDiscoverySpi()).block(); IgniteEx ignite2 = grid(2); IgniteFuture fut = ignite2.services().deployNodeSingletonAsync("testService", new LongInitializedTestService(5000L)); IgniteFuture fut2 = ignite2.services().deployNodeSingletonAsync("testService2", new LongInitializedTestService(5000L)); IgniteFuture fut3 = ignite2.services().deployNodeSingletonAsync("testService3", new LongInitializedTestService(5000L)); assertEquals(ignite0.localNode(), U.oldest(ignite2.cluster().nodes(), null)); stopNode(ignite0); fut.get(TEST_FUTURE_WAIT_TIMEOUT); fut2.get(TEST_FUTURE_WAIT_TIMEOUT); fut3.get(TEST_FUTURE_WAIT_TIMEOUT); IgniteEx ignite3 = grid(3); assertNotNull(ignite3.services().service("testService")); assertNotNull(ignite3.services().service("testService2")); assertNotNull(ignite3.services().service("testService3")); } finally { stopAllGrids(); } }
/** * @throws Exception In case of an error. */ @Test public void testDeploymentProcessingOnServersLeaveTopology() throws Exception { try { startGrids(4); IgniteEx client = startGrid(getConfiguration("client").setClientMode(true)); IgniteEx ignite1 = grid(1); IgniteEx ignite2 = grid(2); ((BlockingTcpCommunicationSpi)ignite1.configuration().getCommunicationSpi()).block(); ((BlockingTcpCommunicationSpi)ignite2.configuration().getCommunicationSpi()).block(); IgniteFuture fut = client.services().deployNodeSingletonAsync("testService", new LongInitializedTestService(5000L)); IgniteFuture fut2 = client.services().deployNodeSingletonAsync("testService2", new LongInitializedTestService(5000L)); stopNode(ignite1); stopNode(ignite2); fut.get(TEST_FUTURE_WAIT_TIMEOUT); fut2.get(TEST_FUTURE_WAIT_TIMEOUT); IgniteEx ignite3 = grid(3); assertNotNull(ignite3.services().service("testService")); assertNotNull(ignite3.services().service("testService2")); } finally { stopAllGrids(); } }
svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key); assertNull(svcs.service(svcName));