Java Code Examples for org.apache.ignite.internal.IgniteEx#services()

The following examples show how to use org.apache.ignite.internal.IgniteEx#services() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteServiceConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @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");
    }
}
 
Example 3
Source File: IgniteServiceDynamicCachesSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @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();

    if (ig.context().service() instanceof GridServiceProcessor) {
        svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);

        assertNull(svcs.service(svcName));

        ig.createCache(ccfg);
    }
    else if (ig.context().service() instanceof IgniteServiceProcessor) {
        GridTestUtils.assertThrowsWithCause(() -> {
            svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);

            return null;
        }, ServiceDeploymentException.class);

        ig.createCache(ccfg);

        svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);
    }
    else
        fail("Unexpected service implementation.");

    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);
    }
}
 
Example 4
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testAffinityDeployUpdateTopology() throws Exception {
    IgniteEx g = randomGrid();

    final Integer affKey = 1;

    // Store a cache key.
    g.cache(CACHE_NAME).put(affKey, affKey.toString());

    final String name = "serviceAffinityUpdateTopology";

    IgniteServices svcs = g.services();

    IgniteFuture<?> fut = svcs.deployKeyAffinitySingletonAsync(name, new AffinityService(affKey),
        CACHE_NAME, affKey);

    info("Deployed service: " + name);

    fut.get();

    info("Finished waiting for service future: " + name);

    checkCount(name, g.services().serviceDescriptors(), 1);

    int nodeCnt = 2;

    startExtraNodes(nodeCnt);

    try {
        checkCount(name, g, 1);
    }
    finally {
        stopExtraNodes(nodeCnt);
    }
}
 
Example 5
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSingletonUpdateTopology() throws Exception {
    String name = "serviceSingletonUpdateTopology";

    IgniteEx g = randomGrid();

    CountDownLatch latch = new CountDownLatch(1);

    DummyService.exeLatch(name, latch);

    IgniteServices svcs = g.services();

    IgniteFuture<?> fut = svcs.deployClusterSingletonAsync(name, new DummyService());

    info("Deployed service: " + name);

    fut.get();

    info("Finished waiting for service future: " + name);

    latch.await();

    Assert.assertEquals(name, 1, DummyService.started(name));
    Assert.assertEquals(name, 0, DummyService.cancelled(name));

    int nodeCnt = 2;

    startExtraNodes(nodeCnt);

    try {
        Assert.assertEquals(name, 1, DummyService.started(name));
        Assert.assertEquals(name, 0, DummyService.cancelled(name));

        info(">>> Passed checks.");

        checkCount(name, g, 1);
    }
    finally {
        stopExtraNodes(nodeCnt);
    }
}
 
Example 6
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @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");
    }
}
 
Example 7
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @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");
    }
}