Search in sources :

Example 41 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectCacheTest method reconnectTransactionInProgress1.

/**
 * @param client Client.
 * @param txConcurrency Transaction concurrency mode.
 * @param cache Cache.
 * @throws Exception If failed.
 */
private void reconnectTransactionInProgress1(IgniteEx client, final TransactionConcurrency txConcurrency, final IgniteCache<Object, Object> cache) throws Exception {
    Ignite srv = ignite(0);
    final IgniteDiscoverySpi clientSpi = spi0(client);
    final DiscoverySpi srvSpi = spi0(srv);
    final CountDownLatch disconnectLatch = new CountDownLatch(1);
    final CountDownLatch reconnectLatch = new CountDownLatch(1);
    log.info("Block reconnect.");
    DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
    clientSpi.setInternalListener(lsnr);
    lsnr.startBlockJoin();
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                info("Disconnected: " + evt);
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                info("Reconnected: " + evt);
                reconnectLatch.countDown();
            }
            return true;
        }
    }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    final IgniteTransactions txs = client.transactions();
    final CountDownLatch afterPut1 = new CountDownLatch(1);
    final CountDownLatch afterPut2 = new CountDownLatch(1);
    final CountDownLatch putFailed = new CountDownLatch(1);
    IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                log.info("Start tx1: " + txConcurrency);
                try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
                    cache.put(1, 1);
                    afterPut1.countDown();
                    afterPut2.await();
                    cache.put(2, 2);
                    fail();
                } catch (CacheException e) {
                    log.info("Expected exception: " + e);
                    putFailed.countDown();
                    IgniteClientDisconnectedException e0 = (IgniteClientDisconnectedException) e.getCause();
                    e0.reconnectFuture().get();
                }
                log.info("Start tx2: " + txConcurrency);
                try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
                    cache.put(1, 1);
                    cache.put(2, 2);
                    tx.commit();
                }
                assertEquals(1, cache.get(1));
                assertEquals(2, cache.get(2));
                try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
                    cache.put(3, 3);
                    cache.put(4, 4);
                    tx.commit();
                }
                assertEquals(1, cache.get(1));
                assertEquals(2, cache.get(2));
                assertEquals(3, cache.get(3));
                assertEquals(4, cache.get(4));
                cache.removeAll();
                return true;
            } catch (AssertionError e) {
                throw e;
            } catch (Throwable e) {
                log.error("Unexpected error", e);
                fail("Unexpected error: " + e);
                return false;
            }
        }
    });
    assertTrue(afterPut1.await(5000, MILLISECONDS));
    assertNotDone(fut);
    srvSpi.failNode(client.localNode().id(), null);
    waitReconnectEvent(disconnectLatch);
    afterPut2.countDown();
    assertTrue(putFailed.await(5000, MILLISECONDS));
    lsnr.stopBlockJoin();
    waitReconnectEvent(reconnectLatch);
    assertTrue(fut.get());
}
Also used : CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteTransactions(org.apache.ignite.IgniteTransactions) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) Transaction(org.apache.ignite.transactions.Transaction) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi)

Example 42 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectComputeTest method testReconnectBroadcastInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectBroadcastInProgress() throws Exception {
    final Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    commSpi.blockMessage(GridJobExecuteResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                client.compute().broadcast(new IgniteCallable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        return 42;
                    }
                });
            } 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 : IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Test(org.junit.Test)

Example 43 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectComputeTest method testReconnectAffinityCallInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectAffinityCallInProgress() throws Exception {
    final Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    IgniteCache<Integer, Integer> cache = client.getOrCreateCache("test-cache");
    for (int i = 0; i < 100; i++) cache.put(i, i);
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    commSpi.blockMessage(GridJobExecuteResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                client.compute().affinityCall("test-cache", 40, new IgniteCallable<Object>() {

                    @Override
                    public Integer call() throws Exception {
                        return 42;
                    }
                });
            } 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 : IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Test(org.junit.Test)

Example 44 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectStopTest method testStopWhenDisconnected.

/**
 * @throws Exception If failed.
 */
@Test
public void testStopWhenDisconnected() throws Exception {
    Ignite client = startClientGrid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = clientRouter(client);
    DiscoverySpi srvSpi = spi0(srv);
    final CountDownLatch disconnectLatch = new CountDownLatch(1);
    final CountDownLatch reconnectLatch = new CountDownLatch(1);
    final IgniteDiscoverySpi clientSpi = spi0(client);
    DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
    clientSpi.setInternalListener(lsnr);
    log.info("Block reconnect.");
    lsnr.startBlockJoin();
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                info("Disconnected: " + evt);
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                info("Reconnected: " + evt);
                reconnectLatch.countDown();
            }
            return true;
        }
    }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    srvSpi.failNode(client.cluster().localNode().id(), null);
    waitReconnectEvent(disconnectLatch);
    IgniteFuture<?> reconnectFut = null;
    try {
        client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
        fail();
    } catch (IgniteClientDisconnectedException e) {
        log.info("Expected operation exception: " + e);
        reconnectFut = e.reconnectFuture();
    }
    assertNotNull(reconnectFut);
    client.close();
    try {
        reconnectFut.get();
        fail();
    } catch (IgniteException e) {
        log.info("Expected reconnect exception: " + e);
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) Test(org.junit.Test)

Example 45 with IgniteClientDisconnectedException

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

the class IgniteClientRejoinTest method testClientsReconnectAfterStart.

/**
 * @throws Exception If failed.
 */
@Test
public void testClientsReconnectAfterStart() throws Exception {
    Ignite srv1 = startGrid("server1");
    crd = ((IgniteKernal) srv1).localNode();
    Ignite srv2 = startGrid("server2");
    final CountDownLatch latch = new CountDownLatch(1);
    List<Ignite> clientNodes = new ArrayList<>();
    final int CLIENTS_NUM = 5;
    for (int i = 0; i < CLIENTS_NUM; i++) clientNodes.add(startClientGrid("client" + i));
    blockAll = true;
    GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            U.sleep(5_000);
            block = true;
            blockAll = false;
            System.out.println(">>> Allow with blocked coordinator.");
            latch.countDown();
            return null;
        }
    });
    IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            latch.await();
            U.sleep((new Random().nextInt(15) + 30) * 1000);
            block = false;
            System.out.println(">>> Allow coordinator.");
            return null;
        }
    });
    fut.get();
    for (Ignite client : clientNodes) {
        while (true) {
            try {
                IgniteCache<Integer, Integer> cache = client.getOrCreateCache("some");
                for (int i = 0; i < 100; i++) cache.put(i, i);
                for (int i = 0; i < 100; i++) assertEquals((Integer) i, cache.get(i));
                cache.clear();
                break;
            } catch (IgniteClientDisconnectedException e) {
                e.reconnectFuture().get();
            }
        }
    }
    assertEquals(CLIENTS_NUM, srv1.cluster().forClients().nodes().size());
    assertEquals(CLIENTS_NUM, srv2.cluster().forClients().nodes().size());
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SocketException(java.net.SocketException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) IgniteSpiOperationTimeoutException(org.apache.ignite.spi.IgniteSpiOperationTimeoutException) Random(java.util.Random) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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