Search in sources :

Example 26 with IgniteCountDownLatch

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

the class IgnitePersistentStoreDataStructuresTest method testLatchVolatility.

/**
 * @throws Exception If failed.
 */
@Test
public void testLatchVolatility() throws Exception {
    Ignite ignite = startGrids(4);
    ignite.active(true);
    IgniteCountDownLatch latch = ignite.countDownLatch("test", 10, false, true);
    assert latch != null;
    stopAllGrids();
    ignite = startGrids(4);
    ignite.active(true);
    latch = ignite.countDownLatch("test", 10, false, false);
    assert latch == null;
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 27 with IgniteCountDownLatch

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

the class IgniteClientReconnectAtomicsTest method testLatchReconnect.

/**
 * @throws Exception If failed.
 */
@Test
public void testLatchReconnect() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    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) Test(org.junit.Test)

Example 28 with IgniteCountDownLatch

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

the class IgniteClientReconnectAtomicsTest method testAtomicsReconnectClusterRestart.

/**
 * @throws Exception If failed.
 */
@Test
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;
        }
    }, IgniteException.class, null);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

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

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

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

Example 29 with IgniteCountDownLatch

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

the class AbstractDistributedMvccBenchmark method setUp.

/**
 * {@inheritDoc}
 */
@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
    super.setUp(cfg);
    memberId = cfg.memberId();
    if (memberId < 0)
        throw new IllegalStateException("Member id should be initialized with non-negative value");
    // We assume there is no client nodes in the cluster except clients that are yardstick drivers.
    driversNodesCnt = ignite().cluster().forClients().nodes().size();
    IgniteCountDownLatch dataIsReady = ignite().countDownLatch("fillDataLatch", 1, true, true);
    try {
        if (memberId == 0) {
            fillData(cfg, (IgniteEx) ignite(), args.range(), args.atomicMode());
            dataIsReady.countDown();
        } else {
            println(cfg, "No need to upload data for memberId=" + memberId + ". Just waiting");
            dataIsReady.await(DATA_WAIT_TIMEOUT_MIN, TimeUnit.MINUTES);
            println(cfg, "Data is ready.");
        }
    } catch (Throwable th) {
        dataIsReady.countDownAll();
        throw new RuntimeException("Fill Data failed.", th);
    }
    // Workaround for "Table TEST_LONG not found" on sql update.
    execute(new SqlFieldsQuery("SELECT COUNT(*) FROM test_long"));
}
Also used : IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)29 Ignite (org.apache.ignite.Ignite)20 Test (org.junit.Test)14 IgniteException (org.apache.ignite.IgniteException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 ArrayList (java.util.ArrayList)5 Callable (java.util.concurrent.Callable)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteLock (org.apache.ignite.IgniteLock)4 IgniteCallable (org.apache.ignite.lang.IgniteCallable)4 IOException (java.io.IOException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)3 IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 IgniteAtomicReference (org.apache.ignite.IgniteAtomicReference)2