Search in sources :

Example 16 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectCacheTest method testReconnectInitialExchangeInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectInitialExchangeInProgress() throws Exception {
    final UUID clientId = UUID.randomUUID();
    Ignite srv = grid(0);
    final CountDownLatch joinLatch = new CountDownLatch(1);
    srv.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_NODE_JOINED && ((DiscoveryEvent) evt).eventNode().id().equals(clientId)) {
                info("Client joined: " + evt);
                joinLatch.countDown();
            }
            return true;
        }
    }, EVT_NODE_JOINED);
    TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) srv.configuration().getCommunicationSpi();
    srvCommSpi.blockMessages(GridDhtPartitionsFullMessage.class, clientId);
    nodeId = clientId;
    IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                startClientGrid(optimize(getConfiguration(getTestIgniteInstanceName(SRV_CNT))));
                return true;
            } catch (IgniteClientDisconnectedException e) {
                log.info("Expected start error: " + e);
                try {
                    e.reconnectFuture().get();
                    fail();
                } catch (IgniteException e0) {
                    log.info("Expected future error: " + e0);
                }
                return true;
            } catch (Throwable e) {
                log.error("Unexpected error: " + e, e);
                throw e;
            }
        }
    });
    DiscoverySpi srvSpi = spi0(srv);
    try {
        if (!joinLatch.await(10_000, MILLISECONDS)) {
            log.error("Failed to wait for join event, will dump threads.");
            U.dumpThreads(log);
            fail("Failed to wait for join event.");
        }
        U.sleep(1000);
        assertNotDone(fut);
        srvSpi.failNode(clientId, null);
    } finally {
        srvCommSpi.stopBlock(false);
    }
    assertTrue(fut.get());
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) 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) IgniteException(org.apache.ignite.IgniteException) 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) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectComputeTest method testReconnectApplyInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectApplyInProgress() 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().apply(new IgniteClosure<Integer, Integer>() {

                    @Override
                    public Integer apply(Integer o) {
                        return o + 1;
                    }
                }, Arrays.asList(1, 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);
    commSpi.unblockMessage();
    reconnectClientNode(client, srv, null);
    assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
}
Also used : IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Test(org.junit.Test)

Example 18 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectFailoverAbstractTest method reconnectFailover.

/**
 * @param c Test closure.
 * @throws Exception If failed.
 */
protected final void reconnectFailover(final Callable<Void> c) throws Exception {
    final Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    IgniteDiscoverySpi srvSpi = spi0(srv);
    final AtomicBoolean stop = new AtomicBoolean(false);
    final IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                int iter = 0;
                while (!stop.get()) {
                    try {
                        c.call();
                    } catch (CacheException e) {
                        checkAndWait(e);
                    } catch (IgniteClientDisconnectedException e) {
                        checkAndWait(e);
                    }
                    if (++iter % 100 == 0)
                        log.info("Iteration: " + iter);
                    if (barrier != null)
                        barrier.await();
                }
                return null;
            } catch (Throwable e) {
                log.error("Unexpected error in operation thread: " + e, e);
                stop.set(true);
                throw e;
            }
        }
    }, THREADS, "test-operation-thread");
    final AtomicReference<CountDownLatch> disconnected = new AtomicReference<>();
    final AtomicReference<CountDownLatch> reconnected = new AtomicReference<>();
    IgnitePredicate<Event> p = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                info("Reconnected: " + evt);
                CountDownLatch latch = reconnected.get();
                assertNotNull(latch);
                assertEquals(1, latch.getCount());
                latch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                info("Disconnected: " + evt);
                CountDownLatch latch = disconnected.get();
                assertNotNull(latch);
                assertEquals(1, latch.getCount());
                latch.countDown();
            }
            return true;
        }
    };
    client.events().localListen(p, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    try {
        long stopTime = System.currentTimeMillis() + TEST_TIME;
        String err = null;
        while (System.currentTimeMillis() < stopTime && !fut.isDone()) {
            U.sleep(500);
            CountDownLatch disconnectLatch = new CountDownLatch(1);
            CountDownLatch reconnectLatch = new CountDownLatch(1);
            disconnected.set(disconnectLatch);
            reconnected.set(reconnectLatch);
            UUID nodeId = client.cluster().localNode().id();
            log.info("Fail client: " + nodeId);
            srvSpi.failNode(nodeId, null);
            if (!disconnectLatch.await(10_000, MILLISECONDS)) {
                err = "Failed to wait for disconnect";
                break;
            }
            if (!reconnectLatch.await(10_000, MILLISECONDS)) {
                err = "Failed to wait for reconnect";
                break;
            }
            barrier = new CyclicBarrier(THREADS + 1, new Runnable() {

                @Override
                public void run() {
                    barrier = null;
                }
            });
            try {
                barrier.await(10, SECONDS);
            } catch (TimeoutException ignored) {
                err = "Operations hang or fail with unexpected error.";
                break;
            }
        }
        if (err != null) {
            log.error("Test error: " + err);
            U.dumpThreads(log);
            CyclicBarrier barrier0 = barrier;
            if (barrier0 != null) {
                barrier = null;
                barrier0.reset();
            }
            stop.set(true);
            fut.get();
            fail(err);
        }
        stop.set(true);
        fut.get();
    } finally {
        client.events().stopLocalListen(p);
        stop.set(true);
    }
}
Also used : CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) TimeoutException(java.util.concurrent.TimeoutException) CacheException(javax.cache.CacheException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) UUID(java.util.UUID) TimeoutException(java.util.concurrent.TimeoutException)

Example 19 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectLockTest method testLockAfterClusterRestartAndClientReconnected.

/**
 * Check that lock cannot be acquired after cluster restart.
 *
 * @throws Exception If failed.
 */
@Test
public void testLockAfterClusterRestartAndClientReconnected() throws Exception {
    IgniteEx client = grid(serverCount());
    IgniteLock lock = client.reentrantLock("testLockAfterClusterRestartAndClientReconnected", true, true, true);
    // need to initialize lock instance before client reconnect
    lock.lock();
    lock.unlock();
    stopGrid(0);
    stopGrid(1);
    startGrid(0);
    startGrid(1);
    GridTestUtils.assertThrowsWithCause(() -> {
        try {
            lock.lock();
        } catch (IgniteClientDisconnectedException e) {
            e.reconnectFuture().get();
            lock.lock();
        }
    }, CacheStoppedException.class);
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteLock(org.apache.ignite.IgniteLock) Test(org.junit.Test)

Example 20 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectFailoverTest method testReconnectTxCache.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectTxCache() throws Exception {
    final Ignite client = grid(serverCount());
    final IgniteCache<Integer, Integer> cache = client.cache(TX_CACHE);
    assertNotNull(cache);
    assertEquals(TRANSACTIONAL, cache.getConfiguration(CacheConfiguration.class).getAtomicityMode());
    final IgniteTransactions txs = client.transactions();
    reconnectFailover(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try {
                TreeMap<Integer, Integer> map = new TreeMap<>();
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                for (int i = 0; i < 5; i++) {
                    Integer key = rnd.nextInt(0, 100_000);
                    cache.put(key, key);
                    assertEquals(key, cache.get(key));
                    map.put(key, key);
                }
                for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) {
                    try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
                        for (Map.Entry<Integer, Integer> e : map.entrySet()) {
                            cache.put(e.getKey(), e.getValue());
                            assertNotNull(cache.get(e.getKey()));
                        }
                        tx.commit();
                    }
                }
                cache.putAll(map);
                Map<Integer, Integer> res = cache.getAll(map.keySet());
                assertEquals(map, res);
            } catch (IgniteClientDisconnectedException e) {
                throw e;
            } catch (IgniteException e) {
                log.info("Ignore error: " + e);
            } catch (CacheException e) {
                if (e.getCause() instanceof IgniteClientDisconnectedException)
                    throw e;
                else
                    log.info("Ignore error: " + e);
            }
            return null;
        }
    });
}
Also used : CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteTransactions(org.apache.ignite.IgniteTransactions) TreeMap(java.util.TreeMap) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) TreeMap(java.util.TreeMap) Map(java.util.Map) 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