use of org.apache.ignite.IgniteServices in project ignite by apache.
the class GridServiceProcessorMultiNodeSelfTest method testDeployLimits.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("deprecation")
@Test
public void testDeployLimits() throws Exception {
final String name = "serviceWithLimitsUpdateTopology";
IgniteEx g = randomGrid();
final int totalInstances = nodeCount() + 1;
CountDownLatch latch = new CountDownLatch(nodeCount());
DummyService.exeLatch(name, latch);
ServiceConfiguration srvcCfg = new ServiceConfiguration();
srvcCfg.setName(name);
srvcCfg.setMaxPerNodeCount(1);
srvcCfg.setTotalCount(totalInstances);
srvcCfg.setService(new DummyService());
IgniteServices svcs = g.services().withAsync();
svcs.deploy(srvcCfg);
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());
latch = new CountDownLatch(1);
DummyService.exeLatch(name, latch);
int extraNodes = 2;
startExtraNodes(extraNodes);
try {
latch.await();
waitForDeployment(name, totalInstances);
// 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, totalInstances, DummyService.started(name) - DummyService.cancelled(name));
checkCount(name, g, totalInstances);
} finally {
stopExtraNodes(extraNodes);
}
}
use of org.apache.ignite.IgniteServices in project ignite by apache.
the class GridServiceProcessorMultiNodeSelfTest method testDeployOnEachNodeUpdateTopology.
/**
* @throws Exception If failed.
*/
@Test
public void testDeployOnEachNodeUpdateTopology() throws Exception {
// Prestart client node.
Ignite client = startClientGrid("client", getConfiguration("client"));
try {
final String name = "serviceOnEachNodeUpdateTopology";
IgniteEx 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, prestartedNodes + extraNodes);
} finally {
stopExtraNodes(extraNodes);
}
} finally {
stopGrid("client");
}
}
use of org.apache.ignite.IgniteServices in project ignite by apache.
the class IgniteServiceConfigVariationsFullApiTest method testService.
/**
* Tests deployment and contract.
*
* @param svc Service.
* @param sticky Sticky.
* @param deployC Closure.
* @throws Exception If failed.
*/
protected void testService(TestService svc, boolean sticky, DeployClosure deployC) throws Exception {
IgniteServices services;
IgniteEx ignite = testedGrid();
services = ignite.services();
try {
Object expected = value(++cntr);
// Put value for testing Service instance serialization.
svc.setValue(expected);
deployC.run(services, SERVICE_NAME, svc);
// Expect correct value from local instance.
assertEquals(expected, svc.getValue());
// Use stickiness to make sure data will be fetched from the same instance.
TestService proxy = services.serviceProxy(SERVICE_NAME, TestService.class, sticky);
// Expect that correct value is returned from deployed instance.
assertEquals(expected, proxy.getValue());
expected = value(++cntr);
// Change value.
proxy.setValue(expected);
// Expect correct value after being read back.
int r = 1000;
while (r-- > 0) assertEquals(expected, proxy.getValue());
assertEquals("Expected 1 deployed service", 1, services.serviceDescriptors().size());
} finally {
// Randomize stop method invocation
boolean tmp = ThreadLocalRandom.current().nextBoolean();
if (tmp)
services.cancelAll();
else
services.cancel(SERVICE_NAME);
}
}
use of org.apache.ignite.IgniteServices in project ignite by apache.
the class GridServiceProcessorAbstractSelfTest method testSameConfiguration.
/**
* @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);
}
use of org.apache.ignite.IgniteServices in project ignite by apache.
the class GridServiceProcessorAbstractSelfTest method testAffinityDeployOld.
/**
* @throws Exception If failed.
*/
@Test
public void testAffinityDeployOld() throws Exception {
Ignite g = randomGrid();
final Integer affKey = 1;
// Store a cache key.
g.cache(CACHE_NAME).put(affKey, affKey.toString());
String name = "serviceAffinityOld";
IgniteServices svcs = g.services().withAsync();
svcs.deployKeyAffinitySingleton(name, new AffinityService(affKey), CACHE_NAME, affKey);
IgniteFuture<?> fut = svcs.future();
info("Deployed service: " + name);
fut.get();
info("Finished waiting for service future: " + name);
checkCount(name, g.services().serviceDescriptors(), 1);
}
Aggregations