Search in sources :

Example 26 with IgniteServices

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);
    }
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteServices(org.apache.ignite.IgniteServices) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 27 with IgniteServices

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");
    }
}
Also used : ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) 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) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 28 with IgniteServices

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);
    }
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 29 with IgniteServices

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);
}
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 30 with IgniteServices

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) 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