use of org.apache.ignite.lang.IgniteFutureTimeoutException in project ignite by apache.
the class GridEventStorageManagerSelfTest method testWaitForEvent.
/**
* @throws Exception If failed.
*/
@Test
public void testWaitForEvent() throws Exception {
Ignite ignite = grid();
final int usrType = Integer.MAX_VALUE - 1;
IgniteFuture<Event> fut = waitForLocalEvent(ignite.events(), new IgnitePredicate<Event>() {
@Override
public boolean apply(Event e) {
return e.type() == usrType;
}
}, usrType);
try {
fut.get(500);
fail("GridFutureTimeoutException must have been thrown.");
} catch (IgniteFutureTimeoutException e) {
info("Caught expected exception: " + e);
}
ignite.events().recordLocal(new EventAdapter(null, "Test message.", usrType) {
});
assert fut.get() != null;
assertEquals(usrType, fut.get().type());
}
use of org.apache.ignite.lang.IgniteFutureTimeoutException in project ignite by apache.
the class GridEventStorageManagerSelfTest method testWaitForEventContinuationTimeout.
/**
* @throws Exception If failed.
*/
@Test
public void testWaitForEventContinuationTimeout() throws Exception {
Ignite ignite = grid();
try {
// We'll never wait for nonexistent type of event.
int usrType = Integer.MAX_VALUE - 1;
waitForLocalEvent(ignite.events(), F.<Event>alwaysTrue(), usrType).get(1000);
fail("GridFutureTimeoutException must have been thrown.");
} catch (IgniteFutureTimeoutException e) {
info("Caught expected exception: " + e);
}
}
use of org.apache.ignite.lang.IgniteFutureTimeoutException in project ignite by apache.
the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method testTxOriginatingNodeFails.
/**
* @param keys Keys to update.
* @param fullFailure Flag indicating whether to simulate rollback state.
* @throws Exception If failed.
*/
protected void testTxOriginatingNodeFails(Collection<Integer> keys, final boolean fullFailure) throws Exception {
assertFalse(keys.isEmpty());
final Collection<IgniteKernal> grids = new ArrayList<>();
ClusterNode txNode = grid(originatingNode()).localNode();
for (int i = 1; i < gridCount(); i++) grids.add((IgniteKernal) grid(i));
failingNodeId = grid(0).localNode().id();
final Map<Integer, String> map = new HashMap<>();
final String initVal = "initialValue";
for (Integer key : keys) {
grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
map.put(key, String.valueOf(key));
}
Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
info("Node being checked: " + grid(1).localNode().id());
for (Integer key : keys) {
Collection<ClusterNode> nodes = new ArrayList<>();
nodes.addAll(grid(1).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(key));
nodes.remove(txNode);
nodeMap.put(key, nodes);
}
info("Starting tx [values=" + map + ", topVer=" + ((IgniteKernal) grid(1)).context().discovery().topologyVersion() + ']');
if (fullFailure)
ignoreMessages(ignoreMessageClasses(), F.asList(grid(1).localNode().id()));
final IgniteEx originatingNodeGrid = grid(originatingNode());
GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteCache<Integer, String> cache = originatingNodeGrid.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
Transaction tx = originatingNodeGrid.transactions().txStart();
assertEquals(PESSIMISTIC, tx.concurrency());
try {
cache.putAll(map);
info("Before commitAsync");
IgniteFuture<?> fut = tx.commitAsync();
info("Got future for commitAsync().");
fut.get(3, TimeUnit.SECONDS);
} catch (IgniteFutureTimeoutException ignored) {
info("Failed to wait for commit future completion [fullFailure=" + fullFailure + ']');
}
return null;
}
}).get();
info(">>> Stopping originating node " + txNode);
G.stop(grid(originatingNode()).name(), true);
ignoreMessages(Collections.<Class<?>>emptyList(), Collections.<UUID>emptyList());
info(">>> Stopped originating node: " + txNode.id());
boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (IgniteKernal g : grids) {
GridCacheAdapter<?, ?> cache = g.internalCache(DEFAULT_CACHE_NAME);
IgniteTxManager txMgr = cache.isNear() ? ((GridNearCacheAdapter) cache).dht().context().tm() : cache.context().tm();
int txNum = txMgr.idMapSize();
if (txNum != 0)
return false;
}
return true;
}
}, 10000);
assertTrue(txFinished);
info("Transactions finished.");
for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
final Integer key = e.getKey();
final String val = map.get(key);
assertFalse(e.getValue().isEmpty());
for (ClusterNode node : e.getValue()) {
final UUID checkNodeId = node.id();
compute(G.ignite(checkNodeId).cluster().forNode(node)).call(new IgniteCallable<Void>() {
/**
*/
@IgniteInstanceResource
private Ignite ignite;
@Override
public Void call() throws Exception {
IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
if (atomicityMode() != TRANSACTIONAL_SNAPSHOT) {
assertEquals("Failed to check entry value on node: " + checkNodeId, fullFailure ? initVal : val, cache.localPeek(key));
}
return null;
}
});
}
}
awaitPartitionMapExchange();
for (Map.Entry<Integer, String> e : map.entrySet()) {
long cntr0 = -1;
for (Ignite g : G.allGrids()) {
Integer key = e.getKey();
assertEquals(fullFailure ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(key));
if (g.affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(((IgniteEx) g).localNode(), key)) {
long nodeCntr = updateCoutner(g, key);
if (cntr0 == -1)
cntr0 = nodeCntr;
assertEquals(cntr0, nodeCntr);
}
}
}
}
use of org.apache.ignite.lang.IgniteFutureTimeoutException in project ignite by apache.
the class IgniteCacheLockFailoverSelfTest method testLockFailover.
/**
* @throws Exception If failed.
*/
@Test
public void testLockFailover() throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
Integer key = backupKey(cache);
final AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!stop.get()) {
stopGrid(1);
U.sleep(500);
startGrid(1);
}
return null;
}
});
try {
long end = System.currentTimeMillis() + 60_000;
long iter = 0;
while (System.currentTimeMillis() < end) {
if (iter % 100 == 0)
log.info("Iteration: " + iter);
iter++;
GridCacheAdapter<Object, Object> adapter = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
IgniteInternalFuture<Boolean> fut = adapter.lockAsync(key, 0);
try {
fut.get(30_000);
U.sleep(1);
} catch (IgniteFutureTimeoutException e) {
info("Entry: " + adapter.peekEx(key));
fail("Lock timeout [fut=" + fut + ", err=" + e + ']');
} catch (Exception e) {
log.error("Error: " + e);
} finally {
adapter.unlock(key);
}
}
} finally {
stop.set(true);
restartFut.get();
}
}
use of org.apache.ignite.lang.IgniteFutureTimeoutException in project ignite by apache.
the class IgniteUtils method exceptionConverters.
/**
* Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
*
* @return Exception converters.
*/
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
}
});
m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureCancelledException(e.getMessage(), e);
}
});
m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteFutureTimeoutException(e.getMessage(), e);
}
});
m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ClusterGroupEmptyException(e.getMessage(), e);
}
});
m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
if (checked.retryReadyFuture() != null)
topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
return topEx;
}
});
m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteDeploymentException(e.getMessage(), e);
}
});
m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskTimeoutException(e.getMessage(), e);
}
});
m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new ComputeTaskCancelledException(e.getMessage(), e);
}
});
m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionRollbackException(e.getMessage(), e);
}
});
m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionHeuristicException(e.getMessage(), e);
}
});
m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
if (e.getCause() instanceof TransactionDeadlockException)
return new TransactionTimeoutException(e.getMessage(), e.getCause());
return new TransactionTimeoutException(e.getMessage(), e);
}
});
m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionOptimisticException(e.getMessage(), e);
}
});
m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
}
});
m.put(IgniteTxSerializationCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionSerializationException(e.getMessage(), e);
}
});
m.put(IgniteTxDuplicateKeyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionDuplicateKeyException(e.getMessage(), e);
}
});
m.put(IgniteTxAlreadyCompletedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {
@Override
public IgniteException apply(IgniteCheckedException e) {
return new TransactionAlreadyCompletedException(e.getMessage(), e);
}
});
return m;
}
Aggregations