Search in sources :

Example 46 with Service

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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 47 with Service

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());
}
Also used : Service(org.apache.ignite.services.Service) AtomicReference(java.util.concurrent.atomic.AtomicReference) PA(org.apache.ignite.internal.util.typedef.PA) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 48 with Service

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;
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Service(org.apache.ignite.services.Service)

Example 49 with Service

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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Callable(java.util.concurrent.Callable) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) ClusterNode(org.apache.ignite.cluster.ClusterNode) ServiceContext(org.apache.ignite.services.ServiceContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Service(org.apache.ignite.services.Service) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 50 with Service

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();
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) Service(org.apache.ignite.services.Service) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

Service (org.apache.ignite.services.Service)50 ExecutorService (java.util.concurrent.ExecutorService)22 PlatformService (org.apache.ignite.internal.processors.platform.services.PlatformService)18 Ignite (org.apache.ignite.Ignite)17 Test (org.junit.Test)17 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ArrayList (java.util.ArrayList)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteException (org.apache.ignite.IgniteException)9 IgniteEx (org.apache.ignite.internal.IgniteEx)9 ServiceConfiguration (org.apache.ignite.services.ServiceConfiguration)8 IgniteServices (org.apache.ignite.IgniteServices)6 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)6 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 ServiceContext (org.apache.ignite.services.ServiceContext)4 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 IOException (java.io.IOException)3