use of org.apache.ignite.services.Service in project ignite by apache.
the class GridServiceProcessorMultiNodeSelfTest method testDeployOnEachProjectionNodeUpdateTopology.
/**
* @throws Exception If failed.
*/
public void testDeployOnEachProjectionNodeUpdateTopology() throws Exception {
// Prestart client node.
Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
try {
final String name = "serviceOnEachProjectionNodeUpdateTopology";
Ignite g = randomGrid();
int prestartedSrvcs = 1;
CountDownLatch latch = new CountDownLatch(prestartedSrvcs);
DummyService.exeLatch(name, latch);
IgniteServices svcs = g.services(g.cluster().forClients());
IgniteFuture<?> fut = svcs.deployNodeSingletonAsync(name, new DummyService());
info("Deployed service: " + name);
fut.get();
info("Finished waiting for service future: " + name);
latch.await();
// Ensure service is deployed
assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
assertEquals(name, prestartedSrvcs, DummyService.started(name));
assertEquals(name, 0, DummyService.cancelled(name));
int servers = 2;
int clients = 2;
latch = new CountDownLatch(clients);
DummyService.exeLatch(name, latch);
startExtraNodes(servers, clients);
try {
latch.await();
waitForDeployment(name, clients);
// Since we start extra nodes, there may be extra start and cancel events,
// so we check only the difference between start and cancel and
// not start and cancel events individually.
assertEquals(name, clients + prestartedSrvcs, DummyService.started(name) - DummyService.cancelled(name));
checkCount(name, g.services().serviceDescriptors(), clients + prestartedSrvcs);
} finally {
stopExtraNodes(servers + clients);
}
} finally {
stopGrid("client");
}
}
use of org.apache.ignite.services.Service in project ignite by apache.
the class GridServiceProcessorMultiNodeSelfTest method testDeployOnEachNodeUpdateTopology.
/**
* @throws Exception If failed.
*/
public void testDeployOnEachNodeUpdateTopology() throws Exception {
// Prestart client node.
Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
try {
final String name = "serviceOnEachNodeUpdateTopology";
Ignite g = randomGrid();
final int prestartedNodes = nodeCount() + 1;
CountDownLatch latch = new CountDownLatch(prestartedNodes);
DummyService.exeLatch(name, latch);
ServiceConfiguration srvcCfg = new ServiceConfiguration();
srvcCfg.setNodeFilter(new CacheConfiguration.IgniteAllNodesPredicate());
srvcCfg.setName(name);
srvcCfg.setMaxPerNodeCount(1);
srvcCfg.setService(new DummyService());
IgniteServices svcs = g.services();
IgniteFuture<?> fut = svcs.deployAsync(srvcCfg);
info("Deployed service: " + name);
fut.get();
info("Finished waiting for service future: " + name);
latch.await();
// Ensure service is deployed
assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
assertEquals(name, prestartedNodes, DummyService.started(name));
assertEquals(name, 0, DummyService.cancelled(name));
int servers = 2;
int clients = 2;
int extraNodes = servers + clients;
latch = new CountDownLatch(extraNodes);
DummyService.exeLatch(name, latch);
startExtraNodes(servers, clients);
try {
latch.await();
waitForDeployment(name, prestartedNodes + extraNodes);
// Since we start extra nodes, there may be extra start and cancel events,
// so we check only the difference between start and cancel and
// not start and cancel events individually.
assertEquals(name, prestartedNodes + extraNodes, DummyService.started(name) - DummyService.cancelled(name));
checkCount(name, g.services().serviceDescriptors(), prestartedNodes + extraNodes);
} finally {
stopExtraNodes(extraNodes);
}
} finally {
stopGrid("client");
}
}
use of org.apache.ignite.services.Service in project ignite by apache.
the class GridServiceProcessorProxySelfTest method testLocalProxyInvocation.
/**
* @throws Exception If failed.
*/
public void testLocalProxyInvocation() throws Exception {
final String name = "testLocalProxyInvocation";
final Ignite ignite = grid(0);
ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>());
for (int i = 0; i < nodeCount(); i++) {
final int idx = i;
final AtomicReference<MapService<Integer, String>> ref = new AtomicReference<>();
// wait because after deployNodeSingleton we don't have guarantees what service was deploy.
boolean wait = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
MapService<Integer, String> svc = grid(idx).services().serviceProxy(name, MapService.class, false);
ref.set(svc);
return svc instanceof Service;
}
}, 2000);
// Make sure service is a local instance.
assertTrue("Invalid service instance [srv=" + ref.get() + ", node=" + i + ']', wait);
ref.get().put(i, Integer.toString(i));
}
MapService<Integer, String> map = ignite.services().serviceProxy(name, MapService.class, false);
for (int i = 0; i < nodeCount(); i++) assertEquals(1, map.size());
}
use of org.apache.ignite.services.Service in project ignite by apache.
the class GridServiceProcessorProxySelfTest method testRemoteNotStickProxyInvocation.
/**
* @throws Exception If failed.
*/
public void testRemoteNotStickProxyInvocation() throws Exception {
final String name = "testRemoteNotStickProxyInvocation";
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, false);
// 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);
size += map.size();
}
assertEquals(nodeCount(), size);
}
use of org.apache.ignite.services.Service in project ignite by apache.
the class GridServiceProcessorProxySelfTest method testSingletonProxyInvocation.
/**
* @throws Exception If failed.
*/
public void testSingletonProxyInvocation() throws Exception {
final String name = "testProxyInvocationFromSeveralNodes";
final Ignite ignite = grid(0);
ignite.services(ignite.cluster().forLocal()).deployClusterSingleton(name, new MapServiceImpl<String, Integer>());
for (int i = 1; i < nodeCount(); i++) {
MapService<Integer, String> svc = grid(i).services().serviceProxy(name, MapService.class, false);
// Make sure service is a proxy.
assertFalse(svc instanceof Service);
svc.put(i, Integer.toString(i));
}
assertEquals(nodeCount() - 1, ignite.services().serviceProxy(name, MapService.class, false).size());
}
Aggregations