Search in sources :

Example 66 with IgniteFutureTimeoutCheckedException

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());
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) CacheException(javax.cache.CacheException) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) CacheException(javax.cache.CacheException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) LongAdder(java.util.concurrent.atomic.LongAdder) Transaction(org.apache.ignite.transactions.Transaction) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 67 with IgniteFutureTimeoutCheckedException

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());
    }
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteCluster(org.apache.ignite.IgniteCluster) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 68 with IgniteFutureTimeoutCheckedException

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);
}
Also used : IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 69 with IgniteFutureTimeoutCheckedException

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();
}
Also used : LT(org.apache.ignite.internal.util.typedef.internal.LT) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Nullable(org.jetbrains.annotations.Nullable)

Example 70 with IgniteFutureTimeoutCheckedException

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();
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Test(org.junit.Test)

Aggregations

IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)74 Test (org.junit.Test)38 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)34 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)31 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)29 Ignite (org.apache.ignite.Ignite)18 IgniteEx (org.apache.ignite.internal.IgniteEx)17 IgniteException (org.apache.ignite.IgniteException)16 ArrayList (java.util.ArrayList)14 Transaction (org.apache.ignite.transactions.Transaction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Map (java.util.Map)10 CacheException (javax.cache.CacheException)10 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7