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

The following examples show how to use org.apache.ignite.Ignite#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: IgniteClientReconnectServicesTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectInDeploying() throws Exception {
    Assume.assumeTrue(!isEventDrivenServiceProcessorEnabled());

    Ignite client = grid(serverCount());

    assertTrue(client.cluster().localNode().isClient());

    final IgniteServices services = client.services();

    Ignite srv = ignite(0);

    BlockTcpCommunicationSpi commSpi = commSpi(srv);

    commSpi.blockMessage(GridNearTxPrepareResponse.class);

    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
        @Override public Object call() throws Exception {
            try {
                services.deployClusterSingleton("testReconnectInDeploying", new TestServiceImpl());
            }
            catch (IgniteClientDisconnectedException e) {
                checkAndWait(e);

                return true;
            }

            return false;
        }
    });

    // Check that client waiting operation.
    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            return fut.get(200);
        }
    }, IgniteFutureTimeoutCheckedException.class, null);

    assertNotDone(fut);

    commSpi.unblockMessage();

    reconnectClientNode(client, srv, null);

    assertTrue((Boolean)fut.get(2, TimeUnit.SECONDS));
}
 
Example 2
Source File: IgniteClientReconnectServicesTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectInProgress() throws Exception {
    Ignite client = grid(serverCount());

    assertTrue(client.cluster().localNode().isClient());

    final IgniteServices services = client.services();

    final Ignite srv = ignite(0);

    services.deployClusterSingleton("testReconnectInProgress", new TestServiceImpl());

    final TestService srvc = services.serviceProxy("testReconnectInProgress", TestService.class, false);

    assertNotNull(srvc);

    BlockTcpCommunicationSpi commSpi = commSpi(srv);

    commSpi.blockMessage(GridJobExecuteResponse.class);

    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
        @Override public Object call() throws Exception {
            try {
                srvc.test();
            }
            catch (IgniteClientDisconnectedException e) {
                checkAndWait(e);

                return true;
            }

            return false;
        }
    });

    // Check that client waiting operation.
    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            return fut.get(200);
        }
    }, IgniteFutureTimeoutCheckedException.class, null);

    assertNotDone(fut);

    commSpi.unblockMessage();

    reconnectClientNode(client, srv, null);

    assertTrue((Boolean)fut.get(2, TimeUnit.SECONDS));
}
 
Example 3
Source File: SystemCacheNotConfiguredTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void test() throws Exception {
    captureErr();

    new Thread(this::startServer).start();

    Ignite client = startClientGrid(getConfiguration("client"));

    IgniteServices services = client.services();

    SimpleService srvc = services.serviceProxy("service", SimpleService.class, false);

    Thread.sleep(1000);

    srvc.isWorking();

    assertFalse(getErr().contains("Cache is not configured:"));
}
 
Example 4
Source File: IgniteServiceDynamicCachesSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployCalledAfterCacheStart() throws Exception {
    String cacheName = "cache";

    CacheConfiguration ccfg = new CacheConfiguration(cacheName);
    ccfg.setBackups(1);

    Ignite ig = ignite(0);

    ig.createCache(ccfg);

    try {
        final IgniteServices svcs = ig.services();

        final String svcName = "myService";

        svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, primaryKey(ig.cache(cacheName)));

        boolean res = GridTestUtils.waitForCondition(new PA() {
            @Override public boolean apply() {
                return svcs.service(svcName) != null;
            }
        }, 10 * 1000);

        assertTrue("Service was not deployed", res);

        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 5
Source File: IgniteClientReconnectServicesTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testReconnect() throws Exception {
    Ignite client = grid(serverCount());

    assertTrue(client.cluster().localNode().isClient());

    IgniteServices services = client.services();

    services.deployClusterSingleton("testReconnect", new TestServiceImpl());

    TestService srvc = services.serviceProxy("testReconnect", TestService.class, false);

    assertNotNull(srvc);

    long topVer = grid(0).cluster().topologyVersion();

    assertEquals((Object)topVer, srvc.test());

    Ignite srv = ignite(0);

    reconnectClientNode(client, srv, null);

    CountDownLatch latch = new CountDownLatch(1);

    DummyService.exeLatch("testReconnect2", latch);

    services.deployClusterSingleton("testReconnect2", new DummyService());

    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));

    assertEquals((Object)(topVer + 2), srvc.test());
}
 
Example 6
Source File: IgniteClientReconnectServicesTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testServiceRemove() throws Exception {
    Ignite client = grid(serverCount());

    assertTrue(client.cluster().localNode().isClient());

    Ignite srv = ignite(0);

    IgniteServices clnServices = client.services();

    final IgniteServices srvServices = srv.services();

    srvServices.deployClusterSingleton("testServiceRemove", new TestServiceImpl());

    final TestService srvc = clnServices.serviceProxy("testServiceRemove", TestService.class, false);

    assertNotNull(srvc);

    assertNotNull(srvc.test());

    reconnectClientNode(client, srv, new Runnable() {
        @Override public void run() {
            srvServices.cancel("testServiceRemove");
        }
    });

    GridTestUtils.assertThrows(log, new Callable<Object>() {
        @Override public Object call() throws Exception {
            return srvc.test();
        }
    }, IgniteException.class, null);

    clnServices.deployClusterSingleton("testServiceRemove", new TestServiceImpl());

    TestService newSrvc = clnServices.serviceProxy("testServiceRemove", TestService.class, false);

    assertNotNull(newSrvc);
    assertNotNull(newSrvc.test());
}
 
Example 7
Source File: CacheLateAffinityAssignmentTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testServiceReassign() throws Exception {
    skipCheckOrder = true;

    Ignite ignite0 = startServer(0, 1);

    IgniteServices svcs = ignite0.services();

    for (int i = 0; i < 10; i++)
        svcs.deployKeyAffinitySingleton("service-" + i, new TestServiceImpl(i), CACHE_NAME1, i);

    startServer(1, 2);

    startServer(2, 3);

    Map<String, List<List<ClusterNode>>> assignments = checkAffinity(3, topVer(3, 1), true);

    checkServicesDeploy(ignite(0), assignments.get(CACHE_NAME1));

    stopGrid(0);

    boolean primaryChanged = calculateAffinity(4, false, assignments);

    assignments = checkAffinity(2, topVer(4, 0), !primaryChanged);

    if (primaryChanged)
        checkAffinity(2, topVer(4, 1), true);

    checkServicesDeploy(ignite(1), assignments.get(CACHE_NAME1));
}