Search in sources :

Example 1 with IgniteFutureTimeoutException

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());
}
Also used : IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) EventAdapter(org.apache.ignite.events.EventAdapter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with IgniteFutureTimeoutException

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);
    }
}
Also used : IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with IgniteFutureTimeoutException

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);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with IgniteFutureTimeoutException

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();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) GridCacheAbstractSelfTest(org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest)

Example 5 with IgniteFutureTimeoutException

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;
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) TransactionDuplicateKeyException(org.apache.ignite.transactions.TransactionDuplicateKeyException) TransactionSerializationException(org.apache.ignite.transactions.TransactionSerializationException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TransactionHeuristicException(org.apache.ignite.transactions.TransactionHeuristicException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) C1(org.apache.ignite.internal.util.typedef.C1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) TransactionAlreadyCompletedException(org.apache.ignite.transactions.TransactionAlreadyCompletedException) ComputeTaskCancelledException(org.apache.ignite.compute.ComputeTaskCancelledException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

IgniteFutureTimeoutException (org.apache.ignite.lang.IgniteFutureTimeoutException)7 Test (org.junit.Test)5 Ignite (org.apache.ignite.Ignite)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 IgniteException (org.apache.ignite.IgniteException)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Event (org.apache.ignite.events.Event)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 Transaction (org.apache.ignite.transactions.Transaction)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)1 CountDownLatch (java.util.concurrent.CountDownLatch)1