Search in sources :

Example 46 with IgniteAtomicSequence

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

the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectInProgress.

/**
 * @throws Exception If failed.
 */
@Test
public void testAtomicSeqReconnectInProgress() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = ignite(0);
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    final IgniteAtomicSequence clientAtomicSeq = client.atomicSequence("atomicSeqInProg", 0, true);
    clientAtomicSeq.batchSize(1);
    final IgniteAtomicSequence srvAtomicSeq = srv.atomicSequence("atomicSeqInProg", 0, false);
    srvAtomicSeq.batchSize(1);
    commSpi.blockMessage(GridNearLockResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (int i = 0; i < 3000; i++) {
                try {
                    clientAtomicSeq.incrementAndGet();
                } catch (IgniteClientDisconnectedException e) {
                    checkAndWait(e);
                    return true;
                }
            }
            return false;
        }
    });
    // Check that client waiting operation.
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return fut.get(200);
        }
    }, IgniteFutureTimeoutCheckedException.class, null);
    assertNotDone(fut);
    commSpi.unblockMessage();
    reconnectClientNode(client, srv, null);
    assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
    // Check that after reconnect working.
    assert clientAtomicSeq.incrementAndGet() >= 0;
    assert srvAtomicSeq.incrementAndGet() >= 0;
    clientAtomicSeq.close();
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test)

Example 47 with IgniteAtomicSequence

use of org.apache.ignite.IgniteAtomicSequence 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)

Aggregations

IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)47 Test (org.junit.Test)29 Ignite (org.apache.ignite.Ignite)20 IgniteException (org.apache.ignite.IgniteException)10 IgniteAtomicsAbstractTest (org.apache.ignite.internal.processors.cache.datastructures.IgniteAtomicsAbstractTest)9 AtomicConfiguration (org.apache.ignite.configuration.AtomicConfiguration)6 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)5 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IOException (java.io.IOException)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 HashSet (java.util.HashSet)2 Random (java.util.Random)2 UUID (java.util.UUID)2 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 Callable (java.util.concurrent.Callable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IgniteAtomicReference (org.apache.ignite.IgniteAtomicReference)2