Search in sources :

Example 46 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectCollectionsTest method setReconnectInProgress.

/**
 * @param colCfg Collection configuration.
 * @throws Exception If failed.
 */
private void setReconnectInProgress(final CollectionConfiguration colCfg) throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    final Ignite srv = ignite(0);
    final String setName = "set-in-progress-" + colCfg.getAtomicityMode();
    final IgniteSet<String> clientSet = client.set(setName, colCfg);
    final IgniteSet<String> srvSet = srv.set(setName, null);
    assertTrue(clientSet.add("1"));
    assertFalse(srvSet.add("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 {
                for (int i = 0; i < 100; i++) clientSet.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((Boolean) fut.get(2, TimeUnit.SECONDS));
    assertTrue(clientSet.add("3"));
    assertFalse(srvSet.add("3"));
    srvSet.close();
}
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)

Example 47 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectServicesTest method testReconnectInDeployingNew.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testReconnectInDeployingNew() throws Exception {
    IgniteEx client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    final IgniteServices services = client.services();
    Ignite srv = ignite(0);
    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;
        }
    });
    reconnectClientNode(client, srv, () -> {
        // Check that client waiting operation.
        GridTestUtils.assertThrows(log, () -> fut.get(200), IgniteFutureTimeoutCheckedException.class, null);
        try {
            assertNotDone(fut);
        } catch (Exception e) {
            fail("Unexpected exception has been thrown, err=" + e.getMessage());
        }
    });
    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 48 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectStreamerTest method testStreamerReconnect.

/**
 * @throws Exception If failed.
 */
@Test
public void testStreamerReconnect() throws Exception {
    final Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    final IgniteCache<Object, Object> srvCache = srv.cache(CACHE_NAME);
    IgniteDataStreamer<Integer, Integer> streamer = client.dataStreamer(CACHE_NAME);
    for (int i = 0; i < 50; i++) streamer.addData(i, i);
    streamer.flush();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return srvCache.localSize() == 50;
        }
    }, 2000L);
    assertEquals(50, srvCache.localSize());
    reconnectClientNode(client, srv, new Runnable() {

        @Override
        public void run() {
            try {
                client.dataStreamer(CACHE_NAME);
                fail();
            } catch (IgniteClientDisconnectedException e) {
                assertNotNull(e.reconnectFuture());
            }
        }
    });
    checkStreamerClosed(streamer);
    streamer = client.dataStreamer(CACHE_NAME);
    for (int i = 50; i < 100; i++) streamer.addData(i, i);
    streamer.flush();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return srvCache.localSize() == 100;
        }
    }, 2000L);
    assertEquals(100, srvCache.localSize());
    streamer.close();
    streamer.future().get(2, TimeUnit.SECONDS);
    srvCache.removeAll();
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 49 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testAtomicSeqReconnectInProgress() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    final IgniteAtomicSequence clientAtomicSeq = client.atomicSequence("atomicSeqInProg", 0, true);
    clientAtomicSeq.batchSize(1);
    final IgniteAtomicSequence srvAtomicSeq = srv.atomicSequence("atomicSeqInProg", 0, false);
    srvAtomicSeq.batchSize(1);
    commSpi.blockMessage(GridNearLockResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (int i = 0; i < 3000; i++) {
                try {
                    clientAtomicSeq.incrementAndGet();
                } 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));
    // Check that after reconnect working.
    assert clientAtomicSeq.incrementAndGet() >= 0;
    assert srvAtomicSeq.incrementAndGet() >= 0;
    clientAtomicSeq.close();
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test)

Example 50 with IgniteClientDisconnectedException

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

the class IgniteCacheContinuousQueryReconnectTest method testReconnect.

/**
 * @throws Exception If failed.
 */
private void testReconnect(boolean clientQuery) throws Exception {
    Ignite srv1 = startGrid(0);
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

        @Override
        public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
        // No-op.
        }
    });
    qry.setAutoUnsubscribe(false);
    qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {

        @Override
        public boolean evaluate(CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
            cnt.incrementAndGet();
            return true;
        }
    });
    Ignite client = startClientGrid(1);
    IgniteCache<Object, Object> cache1 = srv1.cache(DEFAULT_CACHE_NAME);
    IgniteCache<Object, Object> clCache = client.cache(DEFAULT_CACHE_NAME);
    // 0 remote listeners.
    putAndCheck(clCache, 0);
    (clientQuery ? clCache : cache1).query(qry);
    // 1 remote listener.
    putAndCheck(clCache, 1);
    startGrid(2);
    // 2 remote listeners.
    putAndCheck(clCache, 2);
    stopGrid(0);
    while (true) {
        try {
            clCache.get(1);
            break;
        } catch (IgniteClientDisconnectedException e) {
            // Wait for reconnect.
            e.reconnectFuture().get();
        } catch (CacheException e) {
            if (e.getCause() instanceof IgniteClientDisconnectedException)
                // Wait for reconnect.
                ((IgniteClientDisconnectedException) e.getCause()).reconnectFuture().get();
        }
    }
    // 1 remote listener.
    putAndCheck(clCache, 1);
    startGrid(3);
    // 2 remote listeners.
    putAndCheck(clCache, 2);
    // Client node.
    stopGrid(1);
    client = startClientGrid(4);
    clCache = client.cache(DEFAULT_CACHE_NAME);
    // 2 remote listeners.
    putAndCheck(clCache, 2);
    startGrid(5);
    // 3 remote listeners.
    putAndCheck(clCache, 3);
}
Also used : CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Ignite(org.apache.ignite.Ignite)

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