use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class TxRollbackOnTimeoutTest method testRandomMixedTxConfigurations.
/**
* Test timeouts with random values and different tx configurations.
*/
@Test
public void testRandomMixedTxConfigurations() throws Exception {
final Ignite client = startClient();
final AtomicBoolean stop = new AtomicBoolean();
final long seed = System.currentTimeMillis();
final Random r = new Random(seed);
log.info("Using seed: " + seed);
final int threadsCnt = Runtime.getRuntime().availableProcessors() * 2;
for (int k = 0; k < threadsCnt; k++) grid(0).cache(CACHE_NAME).put(k, (long) 0);
final TransactionConcurrency[] TC_VALS = TransactionConcurrency.values();
final TransactionIsolation[] TI_VALS = TransactionIsolation.values();
final LongAdder cntr0 = new LongAdder();
final LongAdder cntr1 = new LongAdder();
final LongAdder cntr2 = new LongAdder();
final LongAdder cntr3 = new LongAdder();
final IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
while (!stop.get()) {
int nodeId = r.nextInt(GRID_CNT + 1);
Ignite node = nodeId == GRID_CNT || nearCacheEnabled() ? client : grid(nodeId);
TransactionConcurrency conc = TC_VALS[r.nextInt(TC_VALS.length)];
TransactionIsolation isolation = TI_VALS[r.nextInt(TI_VALS.length)];
int k = r.nextInt(threadsCnt);
long timeout = r.nextInt(200) + 50;
// Roughly 50% of transactions should time out.
try (Transaction tx = node.transactions().txStart(conc, isolation, timeout, 1)) {
cntr0.add(1);
final Long v = (Long) node.cache(CACHE_NAME).get(k);
assertNotNull("Expecting not null value: " + tx, v);
final int delay = r.nextInt(400);
if (delay > 0)
sleep(delay);
node.cache(CACHE_NAME).put(k, v + 1);
tx.commit();
cntr1.add(1);
} catch (TransactionTimeoutException e) {
cntr2.add(1);
} catch (CacheException e) {
assertEquals(TransactionTimeoutException.class, X.getCause(e).getClass());
cntr2.add(1);
} catch (Exception e) {
cntr3.add(1);
}
}
}
}, threadsCnt, "tx-async-thread");
sleep(DURATION);
stop.set(true);
try {
fut.get(30_000);
} catch (IgniteFutureTimeoutCheckedException e) {
error("Transactions hang", e);
for (Ignite node : G.allGrids()) ((IgniteKernal) node).dumpDebugInfo();
// Try to interrupt hanging threads.
fut.cancel();
throw e;
}
log.info("Tx test stats: started=" + cntr0.sum() + ", completed=" + cntr1.sum() + ", failed=" + cntr3.sum() + ", timedOut=" + cntr2.sum());
assertEquals("Expected finished count same as started count", cntr0.sum(), cntr1.sum() + cntr2.sum() + cntr3.sum());
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class ServiceDeploymentOutsideBaselineTest method checkDeployFromEachNodes.
/**
* @param persistence If {@code true}, then persistence will be enabled.
* @param staticDeploy If {@code true}, then static deployment will be used instead of a dynamic one.
* @throws Exception If failed.
*/
private void checkDeployFromEachNodes(boolean persistence, boolean staticDeploy) throws Exception {
this.persistence = persistence;
CountDownLatch exeLatch = new CountDownLatch(1);
DummyService.exeLatch(SERVICE_NAME, exeLatch);
Ignite ignite0 = deployServiceFromNewNode(staticDeploy, 0);
if (!staticDeploy) {
IgniteCluster cluster = ignite0.cluster();
cluster.setBaselineTopology(cluster.topologyVersion());
}
assertTrue(exeLatch.await(10, TimeUnit.SECONDS));
IgniteInternalFuture startFut = GridTestUtils.runAsync(() -> {
try {
deployServiceFromNewNode(staticDeploy);
} catch (Exception e) {
fail(e.getMessage());
}
});
try {
startFut.get(10, TimeUnit.SECONDS);
} catch (IgniteFutureTimeoutCheckedException e) {
GridStringBuilder sb = new SB().a("Node can not start out of baseline till ").a(10_000L).a("ms").a(U.nl());
for (Thread t : Thread.getAllStackTraces().keySet()) if (t.getName().startsWith("async-runnable-runner"))
U.printStackTrace(t.getId(), sb);
fail(sb.toString());
}
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class BlockedEvictionsTest method testStopNodeDuringEviction.
/**
* @throws Exception If failed.
*/
@Test
public void testStopNodeDuringEviction() throws Exception {
AtomicReference<IgniteInternalFuture> ref = new AtomicReference<>();
testOperationDuringEviction(false, 1, p -> {
IgniteInternalFuture fut = runAsync(new Runnable() {
@Override
public void run() {
grid(0).close();
}
});
doSleep(500);
// Cache stop should be blocked by concurrent unfinished eviction.
assertFalse(fut.isDone());
ref.set(fut);
}, this::preload);
try {
ref.get().get(10_000);
} catch (IgniteFutureTimeoutCheckedException e) {
fail(X.getFullStackTrace(e));
}
waitForTopology(2);
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class GridFunc method awaitAll.
/**
* Awaits for all futures to complete and optionally reduces all results into one.
*
* @param timeout Timeout for waiting ({@code 0} for forever).
* @param rdc Optional reducer. If not {@code null}, then results will be reduced into one.
* @param futs List of futures to wait for.
* @param <T> Return type of the futures.
* @param <R> Return type of the reducer.
* @return Reduced result if reducer is provided, {@code null} otherwise.
* @throws IgniteCheckedException If any of the futures failed.
*/
@Deprecated
@Nullable
public static <T, R> R awaitAll(long timeout, @Nullable IgniteReducer<T, R> rdc, @Nullable Collection<IgniteInternalFuture<T>> futs) throws IgniteCheckedException {
if (futs == null || futs.isEmpty())
return null;
long end = timeout == 0 ? Long.MAX_VALUE : U.currentTimeMillis() + timeout;
// Overflow.
if (end < 0)
end = Long.MAX_VALUE;
// concurrently while this method is in progress.
for (IgniteInternalFuture<T> fut : futs) {
T t;
if (timeout > 0) {
long left = end - U.currentTimeMillis();
if (left <= 0 && !fut.isDone())
throw new IgniteFutureTimeoutCheckedException("Timed out waiting for all futures: " + futs);
if (fut.isDone() && left < 0)
left = 0;
t = fut.get(left);
} else
t = fut.get();
if (rdc != null)
rdc.collect(t);
}
return rdc == null ? null : rdc.reduce();
}
use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.
the class ClientSlowDiscoveryTransactionRemapTest method testTransactionRemap.
/**
*/
@Test
public void testTransactionRemap() throws Exception {
TestTransactionEngine engine = new TestTransactionEngine<>(clnt.cache(CACHE_NAME));
IgniteInternalFuture<?> txFut = GridTestUtils.runAsync(() -> {
try (Transaction tx = clnt.transactions().txStart(concurrency, isolation)) {
operation.apply(engine);
tx.commit();
}
});
try {
txFut.get(1, TimeUnit.SECONDS);
} catch (IgniteFutureTimeoutCheckedException te) {
// Expected.
} finally {
clientDiscoSpiBlock.countDown();
}
// After resume second client join, transaction should succesfully await new affinity and commit.
txFut.get();
// Check consistency after transaction commit.
engine.consistencyCheck();
}
Aggregations