Search in sources :

Example 1 with IgniteServices

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

the class IgniteClientReconnectServicesTest method testReconnectInDeploying.

/**
 * @throws Exception If failed.
 */
public void testReconnectInDeploying() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    final IgniteServices services = client.services();
    Ignite srv = clientRouter(client);
    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));
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException)

Example 2 with IgniteServices

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

the class IgniteClientReconnectServicesTest method testReconnect.

/**
 * @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());
}
Also used : DummyService(org.apache.ignite.internal.processors.service.DummyService) IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with IgniteServices

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

the class IgniteClientReconnectServicesTest method testReconnectInProgress.

/**
 * @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));
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test)

Example 4 with IgniteServices

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

the class IgniteClientReconnectServicesTest method testServiceRemove.

/**
 * @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());
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test)

Example 5 with IgniteServices

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

the class SystemCacheNotConfiguredTest method test.

/**
 * @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:"));
}
Also used : IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) 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