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));
}
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);
}
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;
}
});
}
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;
}
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();
}
}
Aggregations