Search in sources :

Example 6 with IgniteServices

use of org.apache.ignite.IgniteServices in project ignite by apache.

the class GridServiceProcessorAbstractSelfTest method testDeployOnEachNodeOld.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeployOnEachNodeOld() throws Exception {
    Ignite g = randomGrid();
    String name = "serviceOnEachNodeOld";
    CountDownLatch latch = new CountDownLatch(nodeCount());
    DummyService.exeLatch(name, latch);
    IgniteServices svcs = g.services().withAsync();
    svcs.deployNodeSingleton(name, new DummyService());
    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());
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with IgniteServices

use of org.apache.ignite.IgniteServices in project ignite by apache.

the class GridServiceProcessorStopSelfTest method testStopDuringDeployment.

/**
 * @throws Exception If failed.
 */
@Test
public void testStopDuringDeployment() throws Exception {
    final CountDownLatch depLatch = new CountDownLatch(1);
    final CountDownLatch finishLatch = new CountDownLatch(1);
    final Ignite ignite = startGrid(0);
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            IgniteServices svcs = ignite.services();
            IgniteFuture f = svcs.deployClusterSingletonAsync("myClusterSingletonService", new TestServiceImpl());
            depLatch.countDown();
            try {
                f.get();
            } catch (IgniteException ignored) {
                finishLatch.countDown();
            } finally {
                finishLatch.countDown();
            }
            return null;
        }
    }, "deploy-thread");
    depLatch.await();
    Ignition.stopAll(true);
    boolean wait = finishLatch.await(15, TimeUnit.SECONDS);
    if (!wait)
        U.dumpThreads(log);
    assertTrue("Deploy future isn't completed", wait);
    fut.get();
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) IgniteException(org.apache.ignite.IgniteException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with IgniteServices

use of org.apache.ignite.IgniteServices in project ignite by apache.

the class IgniteServiceDynamicCachesSelfTest method testDeployCalledBeforeCacheStart.

/**
 * @throws Exception If failed.
 */
@Test
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testDeployCalledBeforeCacheStart() throws Exception {
    String cacheName = "cache";
    CacheConfiguration ccfg = new CacheConfiguration(cacheName);
    ccfg.setBackups(1);
    IgniteEx ig = grid(0);
    final IgniteServices svcs = ig.services();
    final String svcName = "myService";
    ig.createCache(ccfg);
    Object key = primaryKey(ig.cache(cacheName));
    ig.destroyCache(cacheName);
    awaitPartitionMapExchange();
    GridTestUtils.assertThrowsWithCause(() -> {
        svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);
        return null;
    }, ServiceDeploymentException.class);
    ig.createCache(ccfg);
    svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);
    try {
        boolean res = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return svcs.service(svcName) != null;
            }
        }, 10 * 1000);
        assertTrue("Service was not deployed", res);
        info("stopping cache: " + cacheName);
        ig.destroyCache(cacheName);
        res = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return svcs.service(svcName) == null;
            }
        }, 10 * 1000);
        assertTrue("Service was not undeployed", res);
    } finally {
        ig.services().cancelAll();
        ig.destroyCache(cacheName);
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) IgniteServices(org.apache.ignite.IgniteServices) 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 9 with IgniteServices

use of org.apache.ignite.IgniteServices in project ignite by apache.

the class GridServiceProcessorAbstractSelfTest method testDeployMultiple1Old.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeployMultiple1Old() throws Exception {
    Ignite g = randomGrid();
    String name = "serviceMultiple1Old";
    CountDownLatch latch = new CountDownLatch(nodeCount() * 2);
    DummyService.exeLatch(name, latch);
    IgniteServices svcs = g.services().withAsync();
    svcs.deployMultiple(name, new DummyService(), nodeCount() * 2, 3);
    IgniteFuture<?> fut = svcs.future();
    info("Deployed service: " + name);
    fut.get();
    info("Finished waiting for service future: " + name);
    latch.await();
    assertEquals(name, nodeCount() * 2, DummyService.started(name));
    assertEquals(name, 0, DummyService.cancelled(name));
    checkCount(name, g.services().serviceDescriptors(), nodeCount() * 2);
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 10 with IgniteServices

use of org.apache.ignite.IgniteServices in project ignite by apache.

the class GridServiceProcessorAbstractSelfTest method testDifferentConfigurationOld.

/**
 * @throws Exception If failed.
 */
@Test
public void testDifferentConfigurationOld() throws Exception {
    String name = "dupServiceOld";
    IgniteServices svcs1 = randomGrid().services().withAsync();
    IgniteServices svcs2 = randomGrid().services().withAsync();
    svcs1.deployClusterSingleton(name, new DummyService());
    IgniteFuture<?> fut1 = svcs1.future();
    svcs2.deployNodeSingleton(name, new DummyService());
    IgniteFuture<?> fut2 = svcs2.future();
    Exception err1 = null;
    try {
        fut1.get();
    } catch (ServiceDeploymentException e) {
        if (e.getMessage().contains("Failed to deploy some services."))
            err1 = e;
        else
            throw new IllegalStateException("An unexpeted error caught while deploying service.", e);
    }
    try {
        fut2.get();
        if (err1 == null)
            fail("Failed to receive mismatching configuration exception.");
    } catch (Exception e) {
        if (!e.getMessage().contains("Failed to deploy some service"))
            throw new IllegalStateException("An unexpeted error caught while concurrent deploying.", e);
    }
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteException(org.apache.ignite.IgniteException) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteServices (org.apache.ignite.IgniteServices)30 Test (org.junit.Test)26 Ignite (org.apache.ignite.Ignite)19 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 CountDownLatch (java.util.concurrent.CountDownLatch)11 GridCommonTest (org.apache.ignite.testframework.junits.common.GridCommonTest)9 IgniteException (org.apache.ignite.IgniteException)8 IgniteEx (org.apache.ignite.internal.IgniteEx)8 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 Service (org.apache.ignite.services.Service)3 ServiceConfiguration (org.apache.ignite.services.ServiceConfiguration)3 DummyService (org.apache.ignite.internal.processors.service.DummyService)2 PA (org.apache.ignite.internal.util.typedef.PA)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1