Search in sources :

Example 1 with IgniteClientDisconnectedException

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

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

the class SchemaExchangeSelfTest method testServerRestartWithNewTypes.

/**
 * Test client reconnect after server restart accompanied by schema change.
 *
 * @throws Exception If failed.
 */
@Test
public void testServerRestartWithNewTypes() throws Exception {
    IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
    assertTypes(node1, ValueClass.class);
    IgniteEx node2 = startClientNoCache(2);
    GridCacheContext<Object, Object> context0 = node2.context().cache().context().cacheContext(CU.cacheId(CACHE_NAME));
    node2.cache(CACHE_NAME);
    GridCacheContext<Object, Object> context = node2.context().cache().context().cacheContext(CU.cacheId(CACHE_NAME));
    GridCacheAdapter<Object, Object> entries = node2.context().cache().internalCache(CACHE_NAME);
    assertTrue(entries.active());
    node2.cache(CACHE_NAME);
    assertTypes(node2, ValueClass.class);
    stopGrid(1);
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return grid(2).context().clientDisconnected();
        }
    }, 10_000L));
    IgniteFuture reconnFut = null;
    try {
        node2.cache(CACHE_NAME);
        fail();
    } catch (IgniteClientDisconnectedException e) {
        reconnFut = e.reconnectFuture();
    }
    node1 = start(1, KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class);
    assertTypes(node1, ValueClass.class, ValueClass2.class);
    assertCacheStarted(CACHE_NAME, node1);
    reconnFut.get();
    assertCacheNotStarted(CACHE_NAME, node2);
    node2.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node2);
    assertTypes(node2, ValueClass.class, ValueClass2.class);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Test(org.junit.Test)

Example 3 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectCacheQueriesFailoverTest method testReconnectCacheQueries.

/**
 * @throws Exception If failed.
 */
@Test
public void testReconnectCacheQueries() throws Exception {
    final Ignite client = grid(serverCount());
    final IgniteCache<Integer, Person> cache = client.cache(DEFAULT_CACHE_NAME);
    assertNotNull(cache);
    reconnectFailover(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            SqlQuery<Integer, Person> sqlQry = new SqlQuery<>(Person.class, "where id > 1");
            try {
                assertEquals(9999, cache.query(sqlQry).getAll().size());
            } catch (CacheException e) {
                if (e.getCause() instanceof IgniteClientDisconnectedException)
                    throw e;
                else
                    log.info("Ignore error: " + e);
            }
            try {
                SqlFieldsQuery fieldsQry = new SqlFieldsQuery("select avg(p.id) from Person p");
                List<List<?>> res = cache.query(fieldsQry).getAll();
                assertEquals(1, res.size());
                Integer avg = (Integer) res.get(0).get(0);
                assertEquals(5_000, avg.intValue());
            } catch (CacheException e) {
                if (e.getCause() instanceof IgniteClientDisconnectedException)
                    throw e;
                else
                    log.info("Ignore error: " + e);
            }
            return null;
        }
    });
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CacheException(javax.cache.CacheException) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Ignite(org.apache.ignite.Ignite) List(java.util.List) Test(org.junit.Test) IgniteClientReconnectFailoverAbstractTest(org.apache.ignite.internal.IgniteClientReconnectFailoverAbstractTest)

Example 4 with IgniteClientDisconnectedException

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

the class IgniteClientReconnectMassiveShutdownTest method getRetryFuture.

/**
 * Gets retry or reconnect future if passed in {@code 'Exception'} has corresponding class in {@code 'cause'}
 * hierarchy.
 *
 * @param e {@code Exception}.
 * @return Internal future.
 * @throws Exception If unable to find retry or reconnect future.
 */
private IgniteFuture<?> getRetryFuture(Exception e) throws Exception {
    if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
        IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
        assertNotNull(cause);
        return cause.reconnectFuture();
    } else if (X.hasCause(e, ClusterTopologyException.class)) {
        ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
        assertNotNull(cause);
        return cause.retryReadyFuture();
    } else if (X.hasCause(e, CacheInvalidStateException.class)) {
        // All partition owners have left the cluster, partition data has been lost.
        return new IgniteFinishedFutureImpl<>();
    } else
        throw e;
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFinishedFutureImpl(org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl)

Example 5 with IgniteClientDisconnectedException

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

the class ClientReconnectAfterClusterRestartTest method checkReconnectClient.

/**
 */
public void checkReconnectClient() throws Exception {
    try {
        startGrid(SERVER_ID);
        Ignite client = startClientGrid(CLIENT_ID);
        checkTopology(2);
        IgniteCache<Long, BinaryObject> cache = client.getOrCreateCache(CACHE_PARAMS).withKeepBinary();
        client.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event event) {
                switch(event.type()) {
                    case EventType.EVT_CLIENT_NODE_DISCONNECTED:
                        info("Client disconnected");
                        break;
                    case EventType.EVT_CLIENT_NODE_RECONNECTED:
                        info("Client reconnected");
                }
                return true;
            }
        }, EventType.EVT_CLIENT_NODE_DISCONNECTED, EventType.EVT_CLIENT_NODE_RECONNECTED);
        IgniteDataStreamer<Long, BinaryObject> streamer = client.dataStreamer(CACHE_PARAMS);
        streamer.allowOverwrite(true);
        streamer.keepBinary(true);
        streamer.perNodeBufferSize(10000);
        streamer.perNodeParallelOperations(100);
        BinaryObjectBuilder builder = client.binary().builder("PARAMS");
        builder.setField("ID", 1L);
        builder.setField("PARTITIONID", 1L);
        builder.setField("CLIENTID", 1L);
        builder.setField("PARAMETRCODE", 1L);
        builder.setField("PARAMETRVALUE", "Test value");
        builder.setField("PARENTID", 1L);
        BinaryObject obj = builder.build();
        streamer.addData(1L, obj);
        streamer.flush();
        stopAllServers(false);
        Thread.sleep(2_000);
        startGrid(SERVER_ID);
        try {
            assertNull(cache.get(1L));
        } catch (CacheException ce) {
            IgniteClientDisconnectedException icde = (IgniteClientDisconnectedException) ce.getCause();
            icde.reconnectFuture().get();
            assertNull(cache.get(1L));
        }
        info("Pre-insert");
        builder = client.binary().builder("PARAMS");
        builder.setField("ID", 2L);
        builder.setField("PARTITIONID", 1L);
        builder.setField("CLIENTID", 1L);
        builder.setField("PARAMETRCODE", 1L);
        builder.setField("PARAMETRVALUE", "Test value");
        builder.setField("PARENTID", 1L);
        obj = builder.build();
        // streamer.addData(2L, obj);
        cache.put(2L, obj);
        builder = client.binary().builder("PARAMS");
        builder.setField("ID", 3L);
        builder.setField("PARTITIONID", 1L);
        builder.setField("CLIENTID", 1L);
        builder.setField("PARAMETRCODE", 1L);
        builder.setField("PARAMETRVALUE", "Test value");
        builder.setField("PARENTID", 1L);
        obj = builder.build();
        // streamer.addData(3L, obj);
        cache.put(3L, obj);
        builder = client.binary().builder("PARAMS");
        builder.setField("ID", 4L);
        builder.setField("PARTITIONID", 1L);
        builder.setField("CLIENTID", 1L);
        builder.setField("PARAMETRCODE", 1L);
        builder.setField("PARAMETRVALUE", "Test value");
        builder.setField("PARENTID", 1L);
        obj = builder.build();
        cache.put(4L, obj);
        info("Post-insert");
        obj = cache.get(4L);
        assertNotNull(obj);
        info("End");
    } finally {
        stopAllGrids();
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

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