use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectCacheTest method reconnectTransactionInProgress1.
/**
* @param client Client.
* @param txConcurrency Transaction concurrency mode.
* @param cache Cache.
* @throws Exception If failed.
*/
private void reconnectTransactionInProgress1(IgniteEx client, final TransactionConcurrency txConcurrency, final IgniteCache<Object, Object> cache) throws Exception {
Ignite srv = ignite(0);
final IgniteDiscoverySpi clientSpi = spi0(client);
final DiscoverySpi srvSpi = spi0(srv);
final CountDownLatch disconnectLatch = new CountDownLatch(1);
final CountDownLatch reconnectLatch = new CountDownLatch(1);
log.info("Block reconnect.");
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
clientSpi.setInternalListener(lsnr);
lsnr.startBlockJoin();
client.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
info("Disconnected: " + evt);
disconnectLatch.countDown();
} else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
info("Reconnected: " + evt);
reconnectLatch.countDown();
}
return true;
}
}, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
final IgniteTransactions txs = client.transactions();
final CountDownLatch afterPut1 = new CountDownLatch(1);
final CountDownLatch afterPut2 = new CountDownLatch(1);
final CountDownLatch putFailed = new CountDownLatch(1);
IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
log.info("Start tx1: " + txConcurrency);
try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
cache.put(1, 1);
afterPut1.countDown();
afterPut2.await();
cache.put(2, 2);
fail();
} catch (CacheException e) {
log.info("Expected exception: " + e);
putFailed.countDown();
IgniteClientDisconnectedException e0 = (IgniteClientDisconnectedException) e.getCause();
e0.reconnectFuture().get();
}
log.info("Start tx2: " + txConcurrency);
try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
cache.put(1, 1);
cache.put(2, 2);
tx.commit();
}
assertEquals(1, cache.get(1));
assertEquals(2, cache.get(2));
try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
cache.put(3, 3);
cache.put(4, 4);
tx.commit();
}
assertEquals(1, cache.get(1));
assertEquals(2, cache.get(2));
assertEquals(3, cache.get(3));
assertEquals(4, cache.get(4));
cache.removeAll();
return true;
} catch (AssertionError e) {
throw e;
} catch (Throwable e) {
log.error("Unexpected error", e);
fail("Unexpected error: " + e);
return false;
}
}
});
assertTrue(afterPut1.await(5000, MILLISECONDS));
assertNotDone(fut);
srvSpi.failNode(client.localNode().id(), null);
waitReconnectEvent(disconnectLatch);
afterPut2.countDown();
assertTrue(putFailed.await(5000, MILLISECONDS));
lsnr.stopBlockJoin();
waitReconnectEvent(reconnectLatch);
assertTrue(fut.get());
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectComputeTest method testReconnectBroadcastInProgress.
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectBroadcastInProgress() 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().broadcast(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
return 42;
}
});
} 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 IgniteClientReconnectComputeTest method testReconnectAffinityCallInProgress.
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectAffinityCallInProgress() throws Exception {
final Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
IgniteCache<Integer, Integer> cache = client.getOrCreateCache("test-cache");
for (int i = 0; i < 100; i++) cache.put(i, i);
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().affinityCall("test-cache", 40, new IgniteCallable<Object>() {
@Override
public Integer call() throws Exception {
return 42;
}
});
} 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 IgniteClientReconnectStopTest method testStopWhenDisconnected.
/**
* @throws Exception If failed.
*/
@Test
public void testStopWhenDisconnected() throws Exception {
Ignite client = startClientGrid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = clientRouter(client);
DiscoverySpi srvSpi = spi0(srv);
final CountDownLatch disconnectLatch = new CountDownLatch(1);
final CountDownLatch reconnectLatch = new CountDownLatch(1);
final IgniteDiscoverySpi clientSpi = spi0(client);
DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
clientSpi.setInternalListener(lsnr);
log.info("Block reconnect.");
lsnr.startBlockJoin();
client.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
info("Disconnected: " + evt);
disconnectLatch.countDown();
} else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
info("Reconnected: " + evt);
reconnectLatch.countDown();
}
return true;
}
}, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
srvSpi.failNode(client.cluster().localNode().id(), null);
waitReconnectEvent(disconnectLatch);
IgniteFuture<?> reconnectFut = null;
try {
client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
fail();
} catch (IgniteClientDisconnectedException e) {
log.info("Expected operation exception: " + e);
reconnectFut = e.reconnectFuture();
}
assertNotNull(reconnectFut);
client.close();
try {
reconnectFut.get();
fail();
} catch (IgniteException e) {
log.info("Expected reconnect exception: " + e);
}
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientRejoinTest method testClientsReconnectAfterStart.
/**
* @throws Exception If failed.
*/
@Test
public void testClientsReconnectAfterStart() throws Exception {
Ignite srv1 = startGrid("server1");
crd = ((IgniteKernal) srv1).localNode();
Ignite srv2 = startGrid("server2");
final CountDownLatch latch = new CountDownLatch(1);
List<Ignite> clientNodes = new ArrayList<>();
final int CLIENTS_NUM = 5;
for (int i = 0; i < CLIENTS_NUM; i++) clientNodes.add(startClientGrid("client" + i));
blockAll = true;
GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
U.sleep(5_000);
block = true;
blockAll = false;
System.out.println(">>> Allow with blocked coordinator.");
latch.countDown();
return null;
}
});
IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
latch.await();
U.sleep((new Random().nextInt(15) + 30) * 1000);
block = false;
System.out.println(">>> Allow coordinator.");
return null;
}
});
fut.get();
for (Ignite client : clientNodes) {
while (true) {
try {
IgniteCache<Integer, Integer> cache = client.getOrCreateCache("some");
for (int i = 0; i < 100; i++) cache.put(i, i);
for (int i = 0; i < 100; i++) assertEquals((Integer) i, cache.get(i));
cache.clear();
break;
} catch (IgniteClientDisconnectedException e) {
e.reconnectFuture().get();
}
}
}
assertEquals(CLIENTS_NUM, srv1.cluster().forClients().nodes().size());
assertEquals(CLIENTS_NUM, srv2.cluster().forClients().nodes().size());
}
Aggregations