use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectCacheTest method testReconnectInitialExchangeInProgress.
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectInitialExchangeInProgress() throws Exception {
final UUID clientId = UUID.randomUUID();
Ignite srv = grid(0);
final CountDownLatch joinLatch = new CountDownLatch(1);
srv.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_NODE_JOINED && ((DiscoveryEvent) evt).eventNode().id().equals(clientId)) {
info("Client joined: " + evt);
joinLatch.countDown();
}
return true;
}
}, EVT_NODE_JOINED);
TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) srv.configuration().getCommunicationSpi();
srvCommSpi.blockMessages(GridDhtPartitionsFullMessage.class, clientId);
nodeId = clientId;
IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
startClientGrid(optimize(getConfiguration(getTestIgniteInstanceName(SRV_CNT))));
return true;
} catch (IgniteClientDisconnectedException e) {
log.info("Expected start error: " + e);
try {
e.reconnectFuture().get();
fail();
} catch (IgniteException e0) {
log.info("Expected future error: " + e0);
}
return true;
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
});
DiscoverySpi srvSpi = spi0(srv);
try {
if (!joinLatch.await(10_000, MILLISECONDS)) {
log.error("Failed to wait for join event, will dump threads.");
U.dumpThreads(log);
fail("Failed to wait for join event.");
}
U.sleep(1000);
assertNotDone(fut);
srvSpi.failNode(clientId, null);
} finally {
srvCommSpi.stopBlock(false);
}
assertTrue(fut.get());
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectComputeTest method testReconnectApplyInProgress.
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectApplyInProgress() 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().apply(new IgniteClosure<Integer, Integer>() {
@Override
public Integer apply(Integer o) {
return o + 1;
}
}, Arrays.asList(1, 2, 3));
} 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 IgniteClientReconnectFailoverAbstractTest method reconnectFailover.
/**
* @param c Test closure.
* @throws Exception If failed.
*/
protected final void reconnectFailover(final Callable<Void> c) throws Exception {
final Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
IgniteDiscoverySpi srvSpi = spi0(srv);
final AtomicBoolean stop = new AtomicBoolean(false);
final IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
int iter = 0;
while (!stop.get()) {
try {
c.call();
} catch (CacheException e) {
checkAndWait(e);
} catch (IgniteClientDisconnectedException e) {
checkAndWait(e);
}
if (++iter % 100 == 0)
log.info("Iteration: " + iter);
if (barrier != null)
barrier.await();
}
return null;
} catch (Throwable e) {
log.error("Unexpected error in operation thread: " + e, e);
stop.set(true);
throw e;
}
}
}, THREADS, "test-operation-thread");
final AtomicReference<CountDownLatch> disconnected = new AtomicReference<>();
final AtomicReference<CountDownLatch> reconnected = new AtomicReference<>();
IgnitePredicate<Event> p = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
info("Reconnected: " + evt);
CountDownLatch latch = reconnected.get();
assertNotNull(latch);
assertEquals(1, latch.getCount());
latch.countDown();
} else if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
info("Disconnected: " + evt);
CountDownLatch latch = disconnected.get();
assertNotNull(latch);
assertEquals(1, latch.getCount());
latch.countDown();
}
return true;
}
};
client.events().localListen(p, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
try {
long stopTime = System.currentTimeMillis() + TEST_TIME;
String err = null;
while (System.currentTimeMillis() < stopTime && !fut.isDone()) {
U.sleep(500);
CountDownLatch disconnectLatch = new CountDownLatch(1);
CountDownLatch reconnectLatch = new CountDownLatch(1);
disconnected.set(disconnectLatch);
reconnected.set(reconnectLatch);
UUID nodeId = client.cluster().localNode().id();
log.info("Fail client: " + nodeId);
srvSpi.failNode(nodeId, null);
if (!disconnectLatch.await(10_000, MILLISECONDS)) {
err = "Failed to wait for disconnect";
break;
}
if (!reconnectLatch.await(10_000, MILLISECONDS)) {
err = "Failed to wait for reconnect";
break;
}
barrier = new CyclicBarrier(THREADS + 1, new Runnable() {
@Override
public void run() {
barrier = null;
}
});
try {
barrier.await(10, SECONDS);
} catch (TimeoutException ignored) {
err = "Operations hang or fail with unexpected error.";
break;
}
}
if (err != null) {
log.error("Test error: " + err);
U.dumpThreads(log);
CyclicBarrier barrier0 = barrier;
if (barrier0 != null) {
barrier = null;
barrier0.reset();
}
stop.set(true);
fut.get();
fail(err);
}
stop.set(true);
fut.get();
} finally {
client.events().stopLocalListen(p);
stop.set(true);
}
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectLockTest method testLockAfterClusterRestartAndClientReconnected.
/**
* Check that lock cannot be acquired after cluster restart.
*
* @throws Exception If failed.
*/
@Test
public void testLockAfterClusterRestartAndClientReconnected() throws Exception {
IgniteEx client = grid(serverCount());
IgniteLock lock = client.reentrantLock("testLockAfterClusterRestartAndClientReconnected", true, true, true);
// need to initialize lock instance before client reconnect
lock.lock();
lock.unlock();
stopGrid(0);
stopGrid(1);
startGrid(0);
startGrid(1);
GridTestUtils.assertThrowsWithCause(() -> {
try {
lock.lock();
} catch (IgniteClientDisconnectedException e) {
e.reconnectFuture().get();
lock.lock();
}
}, CacheStoppedException.class);
}
use of org.apache.ignite.IgniteClientDisconnectedException in project ignite by apache.
the class IgniteClientReconnectFailoverTest method testReconnectTxCache.
/**
* @throws Exception If failed.
*/
@Test
public void testReconnectTxCache() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCache<Integer, Integer> cache = client.cache(TX_CACHE);
assertNotNull(cache);
assertEquals(TRANSACTIONAL, cache.getConfiguration(CacheConfiguration.class).getAtomicityMode());
final IgniteTransactions txs = client.transactions();
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
TreeMap<Integer, Integer> map = new TreeMap<>();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 5; i++) {
Integer key = rnd.nextInt(0, 100_000);
cache.put(key, key);
assertEquals(key, cache.get(key));
map.put(key, key);
}
for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) {
try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
for (Map.Entry<Integer, Integer> e : map.entrySet()) {
cache.put(e.getKey(), e.getValue());
assertNotNull(cache.get(e.getKey()));
}
tx.commit();
}
}
cache.putAll(map);
Map<Integer, Integer> res = cache.getAll(map.keySet());
assertEquals(map, res);
} catch (IgniteClientDisconnectedException e) {
throw e;
} catch (IgniteException e) {
log.info("Ignore error: " + e);
} catch (CacheException e) {
if (e.getCause() instanceof IgniteClientDisconnectedException)
throw e;
else
log.info("Ignore error: " + e);
}
return null;
}
});
}
Aggregations