Search in sources :

Example 16 with IgniteCountDownLatch

use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.

the class IgniteCountDownLatchAbstractSelfTest method checkCountDown.

/**
     * @throws Exception Exception.
     */
private void checkCountDown() throws Exception {
    IgniteCountDownLatch latch = createLatch("cnt", 10, true);
    assert latch.countDown() == 9;
    assert latch.countDown(2) == 7;
    latch.countDownAll();
    assert latch.count() == 0;
    checkRemovedLatch(latch);
    IgniteCountDownLatch latch1 = createLatch("cnt1", 10, true);
    assert latch1.countDown() == 9;
    assert latch1.countDown(2) == 7;
    latch1.countDownAll();
    assert latch1.count() == 0;
    checkRemovedLatch(latch1);
}
Also used : IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch)

Example 17 with IgniteCountDownLatch

use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.

the class GridCacheAbstractDataStructuresFailoverSelfTest method doTestCountDownLatch.

/**
     * Tests distributed count down latch.
     *
     * @param topWorker Topology change worker.
     * @throws Exception If failed.
     */
private void doTestCountDownLatch(ConstantTopologyChangeWorker topWorker) throws Exception {
    try (IgniteCountDownLatch s = grid(0).countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, true)) {
        try {
            IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Object>() {

                @Override
                public Object apply(Ignite ignite) {
                    assert ignite.countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, false).count() > 0;
                    return null;
                }
            });
            int val = s.count();
            while (!fut.isDone()) {
                assertEquals(val, s.count());
                assertEquals(--val, s.countDown());
            }
            fut.get();
            for (Ignite g : G.allGrids()) assertEquals(val, g.countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, true).count());
        } finally {
            grid(0).countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, false).countDownAll();
        }
    }
}
Also used : IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) Ignite(org.apache.ignite.Ignite)

Example 18 with IgniteCountDownLatch

use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.

the class GridCacheAbstractDataStructuresFailoverSelfTest method testCountDownLatchTopologyChange.

/**
     * @throws Exception If failed.
     */
public void testCountDownLatchTopologyChange() throws Exception {
    try (IgniteCountDownLatch latch = grid(0).countDownLatch(STRUCTURE_NAME, 20, true, true)) {
        try {
            Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
            assertEquals(20, g.countDownLatch(STRUCTURE_NAME, 20, true, false).count());
            g.countDownLatch(STRUCTURE_NAME, 20, true, false).countDown(10);
            stopGrid(NEW_IGNITE_INSTANCE_NAME);
            assertEquals(10, grid(0).countDownLatch(STRUCTURE_NAME, 20, true, false).count());
        } finally {
            grid(0).countDownLatch(STRUCTURE_NAME, 20, true, false).countDownAll();
        }
    }
}
Also used : IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) Ignite(org.apache.ignite.Ignite)

Example 19 with IgniteCountDownLatch

use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.

the class IgniteClientReconnectAtomicsTest method testAtomicsReconnectClusterRestart.

/**
     * @throws Exception If failed.
     */
public void testAtomicsReconnectClusterRestart() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    final IgniteAtomicLong atomicLong = client.atomicLong("atomicLong", 1L, true);
    final IgniteAtomicReference<Integer> atomicRef = client.atomicReference("atomicRef", 1, true);
    final IgniteAtomicStamped<Integer, Integer> atomicStamped = client.atomicStamped("atomicStamped", 1, 1, true);
    final IgniteCountDownLatch latch = client.countDownLatch("latch", 1, true, true);
    final IgniteAtomicSequence seq = client.atomicSequence("seq", 1L, true);
    Ignite srv = grid(0);
    reconnectServersRestart(log, client, Collections.singleton(srv), new Callable<Collection<Ignite>>() {

        @Override
        public Collection<Ignite> call() throws Exception {
            return Collections.singleton((Ignite) startGrid(0));
        }
    });
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            atomicStamped.compareAndSet(1, 1, 2, 2);
            return null;
        }
    }, IllegalStateException.class, null);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            atomicRef.compareAndSet(1, 2);
            return null;
        }
    }, IllegalStateException.class, null);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            atomicLong.incrementAndGet();
            return null;
        }
    }, IllegalStateException.class, null);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            seq.getAndAdd(1L);
            return null;
        }
    }, IllegalStateException.class, null);
}
Also used : IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite)

Example 20 with IgniteCountDownLatch

use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.

the class IgniteClientReconnectAtomicsTest method testLatchReconnect.

/**
     * @throws Exception If failed.
     */
public void testLatchReconnect() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = clientRouter(client);
    IgniteCountDownLatch clientLatch = client.countDownLatch("latch1", 3, false, true);
    assertEquals(3, clientLatch.count());
    final IgniteCountDownLatch srvLatch = srv.countDownLatch("latch1", 3, false, false);
    assertEquals(3, srvLatch.count());
    reconnectClientNode(client, srv, new Runnable() {

        @Override
        public void run() {
            srvLatch.countDown();
        }
    });
    assertEquals(2, srvLatch.count());
    assertEquals(2, clientLatch.count());
    srvLatch.countDown();
    assertEquals(1, srvLatch.count());
    assertEquals(1, clientLatch.count());
    clientLatch.countDown();
    assertEquals(0, srvLatch.count());
    assertEquals(0, clientLatch.count());
    assertTrue(srvLatch.await(1000));
    assertTrue(clientLatch.await(1000));
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch)

Aggregations

IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)20 Ignite (org.apache.ignite.Ignite)14 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 Callable (java.util.concurrent.Callable)4 IgniteCallable (org.apache.ignite.lang.IgniteCallable)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteLock (org.apache.ignite.IgniteLock)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)2 IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)2 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)2 IgniteClosure (org.apache.ignite.lang.IgniteClosure)2 Nullable (org.jetbrains.annotations.Nullable)2 ExpectedException (org.junit.rules.ExpectedException)2 Closeable (java.io.Closeable)1