Search in sources :

Example 21 with IgniteServices

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

the class GridServiceProcessorAbstractSelfTest method testDeploySingletonOld.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeploySingletonOld() throws Exception {
    Ignite g = randomGrid();
    String name = "serviceSingletonOld";
    CountDownLatch latch = new CountDownLatch(1);
    DummyService.exeLatch(name, latch);
    IgniteServices svcs = g.services().withAsync();
    svcs.deployClusterSingleton(name, new DummyService());
    IgniteFuture<?> fut = svcs.future();
    info("Deployed service: " + name);
    fut.get();
    info("Finished waiting for service future: " + name);
    latch.await();
    assertEquals(name, 1, DummyService.started(name));
    assertEquals(name, 0, DummyService.cancelled(name));
    checkCount(name, g.services().serviceDescriptors(), 1);
}
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 22 with IgniteServices

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

the class GridServiceProcessorAbstractSelfTest method testSameConfigurationOld.

/**
 * @throws Exception If failed.
 */
@Test
public void testSameConfigurationOld() 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.deployClusterSingleton(name, new DummyService());
    IgniteFuture<?> fut2 = svcs2.future();
    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);
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with IgniteServices

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

the class GridServiceProcessorAbstractSelfTest method testDifferentConfiguration.

/**
 * @throws Exception If failed.
 */
@Test
public void testDifferentConfiguration() throws Exception {
    String name = "dupService";
    IgniteServices svcs1 = randomGrid().services();
    IgniteServices svcs2 = randomGrid().services();
    IgniteFuture<?> fut1 = svcs1.deployClusterSingletonAsync(name, new DummyService());
    IgniteFuture<?> fut2 = svcs2.deployNodeSingletonAsync(name, new DummyService());
    info("Deployed service: " + name);
    try {
        fut1.get();
        info("Finished waiting for service future: " + name);
        fut2.get();
        fail("Failed to receive mismatching configuration exception.");
    } catch (IgniteException e) {
        info("Received mismatching configuration exception: " + e.getMessage());
    }
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) 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)

Example 24 with IgniteServices

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

the class GridServiceProcessorMultiNodeSelfTest method testDeployOnEachProjectionNodeUpdateTopology.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeployOnEachProjectionNodeUpdateTopology() throws Exception {
    // Prestart client node.
    Ignite client = startClientGrid("client", getConfiguration("client"));
    try {
        final String name = "serviceOnEachProjectionNodeUpdateTopology";
        IgniteEx 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, clients + prestartedSrvcs);
        } finally {
            stopExtraNodes(servers + clients);
        }
    } finally {
        stopGrid("client");
    }
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) IgniteEx(org.apache.ignite.internal.IgniteEx) Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 25 with IgniteServices

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

the class GridServiceProcessorMultiNodeSelfTest method testDeployOnEachNodeButClientUpdateTopology.

/**
 * @throws Exception If failed.
 */
@Test
public void testDeployOnEachNodeButClientUpdateTopology() throws Exception {
    // Prestart client node.
    Ignite client = startClientGrid("client", getConfiguration("client"));
    try {
        final String name = "serviceOnEachNodeButClientUpdateTopology";
        IgniteEx g = randomGrid();
        CountDownLatch latch = new CountDownLatch(nodeCount());
        DummyService.exeLatch(name, latch);
        IgniteServices svcs = g.services();
        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, nodeCount(), DummyService.started(name));
        assertEquals(name, 0, DummyService.cancelled(name));
        int servers = 2;
        latch = new CountDownLatch(servers);
        DummyService.exeLatch(name, latch);
        int clients = 2;
        startExtraNodes(servers, clients);
        try {
            latch.await();
            waitForDeployment(name, servers);
            // 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, nodeCount() + servers, DummyService.started(name) - DummyService.cancelled(name));
            checkCount(name, g, nodeCount() + servers);
        } finally {
            stopExtraNodes(servers + clients);
        }
    } finally {
        stopGrid("client");
    }
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) IgniteEx(org.apache.ignite.internal.IgniteEx) Service(org.apache.ignite.services.Service) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) 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