Search in sources :

Example 26 with IgniteAtomicSequence

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

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

the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectRemoved.

/**
     * @throws Exception If failed.
     */
public void testAtomicSeqReconnectRemoved() throws Exception {
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = clientRouter(client);
    final IgniteAtomicSequence clientAtomicSeq = client.atomicSequence("atomicSeqRmv", 0, true);
    clientAtomicSeq.batchSize(1);
    assertEquals(1L, clientAtomicSeq.incrementAndGet());
    final IgniteAtomicSequence srvAtomicSeq = srv.atomicSequence("atomicSeqRmv", 0, false);
    srvAtomicSeq.batchSize(1);
    assertEquals(1001L, srvAtomicSeq.incrementAndGet());
    reconnectClientNode(client, srv, new Runnable() {

        @Override
        public void run() {
            srvAtomicSeq.close();
            assert srvAtomicSeq.removed();
        }
    });
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (int i = 0; i < 2000; i++) clientAtomicSeq.incrementAndGet();
            return null;
        }
    }, IllegalStateException.class, null);
    IgniteAtomicSequence newClientAtomicSeq = client.atomicSequence("atomicSeqRmv", 0, true);
    assertEquals(0, newClientAtomicSeq.get());
    assertEquals(1, newClientAtomicSeq.incrementAndGet());
    newClientAtomicSeq.close();
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 28 with IgniteAtomicSequence

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

the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectInProgress.

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

Example 29 with IgniteAtomicSequence

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

the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testAddAndGet.

/** @throws Exception If failed. */
public void testAddAndGet() throws Exception {
    // Random sequence names.
    String seqName = UUID.randomUUID().toString();
    final IgniteAtomicSequence seq = grid(0).atomicSequence(seqName, 0L, true);
    runSequenceClosure(new GridInUnsafeClosure<IgniteAtomicSequence>() {

        @Override
        public void apply(IgniteAtomicSequence t) {
            t.addAndGet(5);
        }
    }, seq, ITERATION_NUM, THREAD_NUM);
    assertEquals(5 * ITERATION_NUM * THREAD_NUM, seq.get());
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 30 with IgniteAtomicSequence

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

the class GridCachePartitionedAtomicSequenceTxSelfTest method testIsolation.

/**
     * Tests isolation of system and user transactions.
     */
public void testIsolation() {
    IgniteAtomicSequence seq = ignite(0).atomicSequence(SEQ_NAME, 0, true);
    CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache(ccfg);
    try (Transaction tx = ignite(0).transactions().txStart()) {
        seq.getAndIncrement();
        cache.put(1, 1);
        tx.rollback();
    }
    assertEquals(0, cache.size());
    assertEquals(new Long(1L), U.field(seq, "locVal"));
    assertEquals(new Long(SEQ_CACHE_SIZE - 1), U.field(seq, "upBound"));
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)33 Ignite (org.apache.ignite.Ignite)8 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)2 IgniteException (org.apache.ignite.IgniteException)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteAtomicReference (org.apache.ignite.IgniteAtomicReference)1 IgniteAtomicStamped (org.apache.ignite.IgniteAtomicStamped)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 IgniteLock (org.apache.ignite.IgniteLock)1