use of org.apache.ignite.services.Service in project gridgain by gridgain.
the class GridServiceProcessorProxySelfTest method testRemoteStickyProxyInvocation.
/**
* @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);
}
use of org.apache.ignite.services.Service in project gridgain by gridgain.
the class GridServiceProcessorProxySelfTest method testLocalProxyInvocation.
/**
* @throws Exception If failed.
*/
@Test
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 gridgain by gridgain.
the class IgniteServiceDeployment2ClassLoadersDefaultMarshallerTest method serviceConfig.
/**
* @param firstGrp First group flag.
* @return Service configuration.
* @throws Exception If failed.
*/
private ServiceConfiguration serviceConfig(final boolean firstGrp) throws Exception {
ServiceConfiguration srvCfg = new ServiceConfiguration();
srvCfg.setNodeFilter(new TestNodeFilter(firstGrp ? grp1 : grp2));
Class<Service> srvcCls;
if (firstGrp)
srvcCls = (Class<Service>) extClsLdr1.loadClass(NOOP_SERVICE_CLS_NAME);
else
srvcCls = (Class<Service>) extClsLdr2.loadClass(NOOP_SERVICE_2_CLS_NAME);
Service srvc = srvcCls.newInstance();
srvCfg.setService(srvc);
srvCfg.setName("TestDeploymentService" + (firstGrp ? 1 : 2));
srvCfg.setMaxPerNodeCount(1);
return srvCfg;
}
use of org.apache.ignite.services.Service in project gridgain by gridgain.
the class ServicePredicateAccessCacheTest method testPredicateAccessCache.
/**
* @throws Exception If failed.
*/
@Test
public void testPredicateAccessCache() throws Exception {
final IgniteEx ignite0 = startGrid(0);
CacheConfiguration<String, String> cacheCfg = new CacheConfiguration<>();
cacheCfg.setName("testCache");
cacheCfg.setAtomicityMode(ATOMIC);
cacheCfg.setCacheMode(REPLICATED);
cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
IgniteCache<String, String> cache = ignite0.getOrCreateCache(cacheCfg);
if (ignite0.context().service() instanceof IgniteServiceProcessor)
cache.put(ignite0.cluster().localNode().id().toString(), "val");
latch = new CountDownLatch(1);
final ClusterGroup grp = ignite0.cluster().forPredicate((IgnitePredicate<ClusterNode>) node -> {
System.out.println("Predicated started [thread=" + Thread.currentThread().getName() + ']');
latch.countDown();
try {
Thread.sleep(3000);
} catch (InterruptedException ignore) {
}
System.out.println("Call contains key [thread=" + Thread.currentThread().getName() + ']');
boolean ret = Ignition.localIgnite().cache("testCache").containsKey(node.id().toString());
System.out.println("After contains key [ret=" + ret + ", thread=" + Thread.currentThread().getName() + ']');
return ret;
});
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
info("Start deploy service.");
ignite0.services(grp).deployNodeSingleton("testService", new TestService());
info("Service deployed.");
return null;
}
}, "deploy-thread");
latch.await();
startGrid(1);
fut.get();
}
use of org.apache.ignite.services.Service in project gridgain by gridgain.
the class P2PClassLoadingFailureHandlingTest method serviceP2PClassLoadingProblemShouldNotCauseFailureHandling.
/**
*/
@Test
public void serviceP2PClassLoadingProblemShouldNotCauseFailureHandling() throws Exception {
Service svc = instantiateClassLoadedWithExternalClassLoader("org.apache.ignite.tests.p2p.classloadproblem.ServiceCausingP2PClassLoadProblem");
ServiceConfiguration serviceConfig = new ServiceConfiguration().setName("p2p-classloading-failure").setTotalCount(1).setService(svc);
try {
client.services().deploy(serviceConfig);
// fall through
// TODO: GG-34888 - the exception should always be thrown
} catch (ServiceDeploymentException e) {
assertThat(e.getMessage(), startsWith("Failed to deploy some services"));
}
assertThatFailureHandlerIsNotCalled();
}
Aggregations