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