Search in sources :

Example 21 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class IgniteClientReconnectApiExceptionTest method doTestIgniteOperationOnDisconnect.

/**
     * @param client Client.
     * @param ops Operations closures.
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
private void doTestIgniteOperationOnDisconnect(Ignite client, final List<T2<Callable, C1<Object, Boolean>>> ops) throws Exception {
    assertNotNull(client.cache(DEFAULT_CACHE_NAME));
    final TestTcpDiscoverySpi clientSpi = spi(client);
    Ignite srv = clientRouter(client);
    TestTcpDiscoverySpi srvSpi = spi(srv);
    final CountDownLatch disconnectLatch = new CountDownLatch(1);
    final CountDownLatch reconnectLatch = new CountDownLatch(1);
    log.info("Block reconnect.");
    clientSpi.writeLatch = new CountDownLatch(1);
    final List<IgniteInternalFuture> futs = new ArrayList<>();
    client.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
                info("Disconnected: " + evt);
                assertEquals(1, reconnectLatch.getCount());
                for (T2<Callable, C1<Object, Boolean>> op : ops) futs.add(GridTestUtils.runAsync(op.get1()));
                disconnectLatch.countDown();
            } else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
                info("Reconnected: " + evt);
                reconnectLatch.countDown();
            }
            return true;
        }
    }, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
    try {
        log.info("Fail client.");
        srvSpi.failNode(client.cluster().localNode().id(), null);
        waitReconnectEvent(disconnectLatch);
        assertEquals(ops.size(), futs.size());
        for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
        U.sleep(2000);
        for (IgniteInternalFuture<?> fut : futs) assertNotDone(fut);
        log.info("Allow reconnect.");
        clientSpi.writeLatch.countDown();
        waitReconnectEvent(reconnectLatch);
        // Check operation after reconnect working.
        for (int i = 0; i < futs.size(); i++) {
            final int i0 = i;
            try {
                final Object futRes = futs.get(i0).get(2, SECONDS);
                assertTrue(GridTestUtils.runAsync(new Callable<Boolean>() {

                    @Override
                    public Boolean call() throws Exception {
                        return ops.get(i0).get2().apply(futRes);
                    }
                }).get(2, SECONDS));
            } catch (IgniteFutureTimeoutCheckedException e) {
                e.printStackTrace();
                fail("Operation timeout. Iteration: " + i + ".");
            }
        }
    } finally {
        clientSpi.writeLatch.countDown();
        for (IgniteInternalFuture fut : futs) fut.cancel();
        stopAllGrids();
    }
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2)

Example 22 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class GridTestUtils method assertOneToOne.

/**
     * Asserts that each element in iterable has one-to-one correspondence with a
     * predicate from list.
     *
     * @param it Input iterable of elements.
     * @param ps Array of predicates (by number of elements in iterable).
     */
@SuppressWarnings("ConstantConditions")
public static <T> void assertOneToOne(Iterable<T> it, IgnitePredicate<T>... ps) {
    Collection<IgnitePredicate<T>> ps0 = new ArrayList<>(Arrays.asList(ps));
    Collection<T2<IgnitePredicate<T>, T>> passed = new ArrayList<>();
    for (T elem : it) {
        for (T2<IgnitePredicate<T>, T> p : passed) {
            if (p.get1().apply(elem))
                throw new AssertionError("Two elements match one predicate [elem1=" + p.get2() + ", elem2=" + elem + ", pred=" + p.get1() + ']');
        }
        IgnitePredicate<T> matched = null;
        for (IgnitePredicate<T> p : ps0) {
            if (p.apply(elem)) {
                if (matched != null)
                    throw new AssertionError("Element matches more than one predicate [elem=" + elem + ", pred1=" + p + ", pred2=" + matched + ']');
                matched = p;
            }
        }
        if (// None matched.
        matched == null)
            throw new AssertionError("The element does not match [elem=" + elem + ", numRemainingPreds=" + ps0.size() + ']');
        ps0.remove(matched);
        passed.add(new T2<>(matched, elem));
    }
}
Also used : LT(org.apache.ignite.internal.util.typedef.internal.LT) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ArrayList(java.util.ArrayList) T2(org.apache.ignite.internal.util.typedef.T2)

Example 23 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class IgniteCacheExpireAndUpdateConsistencyTest method checkEvents.

/**
     * @param updates Cache update.
     * @param evts Received events.
     * @throws Exception If failed.
     */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private void checkEvents(ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> updates, final ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> evts) throws Exception {
    for (final TestKey key : updates.keySet()) {
        final List<T2<TestValue, TestValue>> keyUpdates = updates.get(key);
        assert (!F.isEmpty(keyUpdates));
        GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
                if (keyEvts == null)
                    return false;
                synchronized (keyEvts) {
                    return keyEvts.size() == keyUpdates.size();
                }
            }
        }, 5000);
        List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
        assertNotNull(keyEvts);
        for (int i = 0; i < keyUpdates.size(); i++) {
            T2<TestValue, TestValue> update = keyUpdates.get(i);
            T2<TestValue, TestValue> evt = keyEvts.get(i);
            assertEquals(update.get1(), evt.get1());
            assertEquals(update.get2(), evt.get2());
        }
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) ArrayList(java.util.ArrayList) List(java.util.List) T2(org.apache.ignite.internal.util.typedef.T2)

Example 24 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class IgfsModeResolverSelfTest method testModesValidation.

/**
     * @throws Exception If failed.
     */
public void testModesValidation() throws Exception {
    // Another mode inside PRIMARY directory:
    try {
        IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/"), PRIMARY), new T2<>(new IgfsPath("/a/b/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
        fail("IgniteCheckedException expected");
    } catch (IgniteCheckedException ignored) {
    // No-op.
    }
    // PRIMARY default mode and non-primary subfolder:
    for (IgfsMode m : IgfsMode.values()) {
        if (m != IgfsMode.PRIMARY) {
            try {
                IgfsUtils.preparePathModes(PRIMARY, Arrays.asList(new T2<>(new IgfsPath("/a/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
                fail("IgniteCheckedException expected");
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
        }
    }
    // Duplicated sub-folders should be ignored:
    List<T2<IgfsPath, IgfsMode>> modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a"), PRIMARY), new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/c/d/e/f"), PRIMARY)), new HashSet<IgfsPath>());
    assertNotNull(modes);
    assertEquals(2, modes.size());
    assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/a"), PRIMARY)));
    // Non-duplicated sub-folders should not be ignored:
    modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC)), new HashSet<IgfsPath>());
    assertNotNull(modes);
    assertEquals(modes.size(), 3);
    assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC)));
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsMode(org.apache.ignite.igfs.IgfsMode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) T2(org.apache.ignite.internal.util.typedef.T2) HashSet(java.util.HashSet)

Example 25 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class IgfsModeResolverSelfTest method testDualParentsWithPrimaryChild.

/**
     * @throws Exception If failed.
     */
public void testDualParentsWithPrimaryChild() throws Exception {
    Set<IgfsPath> set = new HashSet<>();
    IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), PRIMARY), new T2<>(new IgfsPath("/a/b/x/y"), PRIMARY), new T2<>(new IgfsPath("/a/b/x/z"), PRIMARY), new T2<>(new IgfsPath("/m"), PRIMARY)), set);
    assertEquals(set, new HashSet<IgfsPath>() {

        {
            add(new IgfsPath("/a/b"));
            add(new IgfsPath("/a/b/x"));
            add(IgfsPath.ROOT);
        }
    });
    set = new HashSet<>();
    IgfsUtils.preparePathModes(DUAL_ASYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b/x/y/z"), PRIMARY), new T2<>(new IgfsPath("/a/b/c"), PRIMARY), new T2<>(new IgfsPath("/a/k"), PRIMARY), new T2<>(new IgfsPath("/a/z"), PRIMARY)), set);
    assertEquals(set, new HashSet<IgfsPath>() {

        {
            add(new IgfsPath("/a/b"));
            add(new IgfsPath("/a"));
            add(new IgfsPath("/a/b/x/y"));
        }
    });
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) T2(org.apache.ignite.internal.util.typedef.T2) HashSet(java.util.HashSet)

Aggregations

T2 (org.apache.ignite.internal.util.typedef.T2)64 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 Map (java.util.Map)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)14 UUID (java.util.UUID)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 Ignite (org.apache.ignite.Ignite)13 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)11 HashSet (java.util.HashSet)10 ConcurrentMap (java.util.concurrent.ConcurrentMap)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 CacheException (javax.cache.CacheException)7 CacheEntryEvent (javax.cache.event.CacheEntryEvent)7 Set (java.util.Set)5