Search in sources :

Example 21 with IgniteClientDisconnectedException

use of org.apache.ignite.IgniteClientDisconnectedException 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 22 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectAbstractTest method check.

/**
 * @param e Client disconnected exception.
 * @return Reconnect future.
 */
protected IgniteFuture<?> check(CacheException e) {
    log.info("Expected exception: " + e);
    if (!(e.getCause() instanceof IgniteClientDisconnectedException))
        log.error("Unexpected cause: " + e.getCause(), e);
    assertTrue("Unexpected cause: " + e.getCause(), e.getCause() instanceof IgniteClientDisconnectedException);
    IgniteClientDisconnectedException e0 = (IgniteClientDisconnectedException) e.getCause();
    assertNotNull(e0.reconnectFuture());
    return e0.reconnectFuture();
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 23 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectAtomicsTest method testAtomicStampedReconnectInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testAtomicStampedReconnectInProgress() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    final IgniteAtomicStamped clientAtomicStamped = client.atomicStamped("atomicStampedInProgress", 0, 0, true);
    assertEquals(true, clientAtomicStamped.compareAndSet(0, 1, 0, 1));
    assertEquals(1, clientAtomicStamped.value());
    assertEquals(1, clientAtomicStamped.stamp());
    IgniteAtomicStamped srvAtomicStamped = srv.atomicStamped("atomicStampedInProgress", 0, 0, false);
    assertEquals(true, srvAtomicStamped.compareAndSet(1, 2, 1, 2));
    assertEquals(2, srvAtomicStamped.value());
    assertEquals(2, srvAtomicStamped.stamp());
    BlockTcpCommunicationSpi servCommSpi = commSpi(srv);
    servCommSpi.blockMessage(GridNearTxPrepareResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                clientAtomicStamped.compareAndSet(2, 3, 2, 3);
            } 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);
    servCommSpi.unblockMessage();
    reconnectClientNode(client, srv, null);
    assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
    // Check that after reconnect working.
    assertEquals(false, clientAtomicStamped.compareAndSet(2, 3, 2, 3));
    assertEquals(3, clientAtomicStamped.value());
    assertEquals(3, clientAtomicStamped.stamp());
    assertEquals(true, srvAtomicStamped.compareAndSet(3, 4, 3, 4));
    assertEquals(4, srvAtomicStamped.value());
    assertEquals(4, srvAtomicStamped.stamp());
    srvAtomicStamped.close();
}
Also used : IgniteAtomicStamped(org.apache.ignite.IgniteAtomicStamped) 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 24 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectAtomicsTest method testAtomicReferenceReconnectInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testAtomicReferenceReconnectInProgress() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    final IgniteAtomicReference<String> clientAtomicRef = client.atomicReference("atomicRefInProg", "1st value", true);
    assertEquals("1st value", clientAtomicRef.get());
    assertTrue(clientAtomicRef.compareAndSet("1st value", "2st value"));
    assertEquals("2st value", clientAtomicRef.get());
    IgniteAtomicReference<String> srvAtomicRef = srv.atomicReference("atomicRefInProg", "1st value", false);
    assertEquals("2st value", srvAtomicRef.get());
    assertTrue(srvAtomicRef.compareAndSet("2st value", "3st value"));
    assertEquals("3st value", srvAtomicRef.get());
    BlockTcpCommunicationSpi servCommSpi = commSpi(srv);
    servCommSpi.blockMessage(GridNearTxPrepareResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                clientAtomicRef.compareAndSet("3st value", "4st value");
            } 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);
    servCommSpi.unblockMessage();
    reconnectClientNode(client, srv, null);
    assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
    // Check that after reconnect working.
    assertEquals("4st value", clientAtomicRef.get());
    assertEquals("4st value", srvAtomicRef.get());
    assertTrue(srvAtomicRef.compareAndSet("4st value", "5st value"));
    assertEquals("5st value", srvAtomicRef.get());
    srvAtomicRef.close();
}
Also used : 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 25 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectCollectionsTest method queueReconnectInProgress.

/**
 * @param colCfg Collection configuration.
 * @throws Exception If failed.
 */
private void queueReconnectInProgress(final CollectionConfiguration colCfg) throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    final String setName = "queue-rmv" + colCfg.getAtomicityMode();
    final IgniteQueue<String> clientQueue = client.queue(setName, 10, colCfg);
    final IgniteQueue<String> srvQueue = srv.queue(setName, 10, null);
    assertTrue(clientQueue.offer("1"));
    assertTrue(srvQueue.contains("1"));
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    if (colCfg.getAtomicityMode() == ATOMIC)
        commSpi.blockMessage(GridNearAtomicUpdateResponse.class);
    else
        commSpi.blockMessage(GridNearTxPrepareResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                clientQueue.add("2");
            } 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("Future was not failed. Atomic mode: " + colCfg.getAtomicityMode() + ".", (Boolean) fut.get());
    assertTrue(clientQueue.add("3"));
    assertEquals("1", clientQueue.poll());
}
Also used : GridNearAtomicUpdateResponse(org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateResponse) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) GridNearTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareResponse) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Aggregations

IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)55 Ignite (org.apache.ignite.Ignite)33 IgniteException (org.apache.ignite.IgniteException)26 Test (org.junit.Test)23 CacheException (javax.cache.CacheException)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 Event (org.apache.ignite.events.Event)9 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)9 UUID (java.util.UUID)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteDiscoverySpi (org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi)6 TransactionRollbackException (org.apache.ignite.transactions.TransactionRollbackException)6 IgniteCallable (org.apache.ignite.lang.IgniteCallable)5 DiscoverySpi (org.apache.ignite.spi.discovery.DiscoverySpi)5 Callable (java.util.concurrent.Callable)4 IgniteTransactions (org.apache.ignite.IgniteTransactions)4 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3