Search in sources :

Example 26 with IgniteAtomicLong

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

the class IgniteAtomicLongChangingTopologySelfTest method testQueueClose.

/**
     * @throws Exception If failed.
     */
public void testQueueClose() throws Exception {
    startGrids(GRID_CNT);
    int threads = 4;
    final AtomicBoolean run = new AtomicBoolean(true);
    final AtomicInteger idx = new AtomicInteger();
    final AtomicReferenceArray<Exception> arr = new AtomicReferenceArray<>(threads);
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        /** {@inheritDoc} */
        @Override
        public Void call() throws Exception {
            int base = idx.getAndIncrement();
            try {
                int delta = 0;
                while (run.get()) {
                    IgniteAtomicLong cntr = ignite(0).atomicLong(ATOMIC_LONG_NAME + "-" + base + "-" + delta, 0, true);
                    for (int i = 0; i < 5; i++) queue.add(cntr.getAndIncrement());
                    cntr.close();
                    delta++;
                }
            } catch (Exception e) {
                arr.set(base, e);
                throw e;
            } finally {
                info("RUNNER THREAD IS STOPPING");
            }
            return null;
        }
    }, threads, "increment-runner");
    for (int i = 0; i < RESTART_CNT; i++) {
        int restartIdx = ThreadLocalRandom.current().nextInt(GRID_CNT - 1) + 1;
        stopGrid(restartIdx);
        U.sleep(500);
        startGrid(restartIdx);
    }
    run.set(false);
    fut.get();
    for (int i = 0; i < threads; i++) {
        Exception err = arr.get(i);
        if (err != null)
            throw err;
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 27 with IgniteAtomicLong

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

the class GridCacheAbstractDataStructuresFailoverSelfTest method doTestAtomicLong.

/**
     * Tests IgniteAtomicLong.
     *
     * @param topWorker Topology change worker.
     * @throws Exception If failed.
     */
private void doTestAtomicLong(ConstantTopologyChangeWorker topWorker) throws Exception {
    try (IgniteAtomicLong s = grid(0).atomicLong(STRUCTURE_NAME, 1, true)) {
        IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Object>() {

            @Override
            public Object apply(Ignite ignite) {
                assert ignite.atomicLong(STRUCTURE_NAME, 1, true).get() > 0;
                return null;
            }
        });
        long val = s.get();
        while (!fut.isDone()) {
            assertEquals(val, s.get());
            assertEquals(++val, s.incrementAndGet());
        }
        fut.get();
        for (Ignite g : G.allGrids()) assertEquals(val, g.atomicLong(STRUCTURE_NAME, 1, false).get());
    }
}
Also used : IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Ignite(org.apache.ignite.Ignite)

Example 28 with IgniteAtomicLong

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

the class GridCacheAbstractDataStructuresFailoverSelfTest method testAtomicLongTopologyChange.

/**
     * @throws Exception If failed.
     */
public void testAtomicLongTopologyChange() throws Exception {
    try (IgniteAtomicLong atomic = grid(0).atomicLong(STRUCTURE_NAME, 10, true)) {
        Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
        assertEquals(10, g.atomicLong(STRUCTURE_NAME, 10, false).get());
        assertEquals(20, g.atomicLong(STRUCTURE_NAME, 10, false).addAndGet(10));
        stopGrid(NEW_IGNITE_INSTANCE_NAME);
        assertEquals(20, grid(0).atomicLong(STRUCTURE_NAME, 10, true).get());
    }
}
Also used : IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Ignite(org.apache.ignite.Ignite)

Example 29 with IgniteAtomicLong

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

the class IgniteClientReconnectApiExceptionTest method dataStructureOperationsTest.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
public void dataStructureOperationsTest() throws Exception {
    clientMode = true;
    final Ignite client = startGrid(serverCount());
    doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check atomic long.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.atomicLong("testAtomic", 41, true);
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.atomicLong("testAtomic", 41, true);
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            IgniteAtomicLong atomicLong = (IgniteAtomicLong) o;
            assertEquals(42, atomicLong.incrementAndGet());
            return true;
        }
    }), // Check set.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.set("testSet", new CollectionConfiguration());
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.set("testSet", new CollectionConfiguration());
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            IgniteSet set = (IgniteSet) o;
            String val = "testVal";
            set.add(val);
            assertEquals(1, set.size());
            assertTrue(set.contains(val));
            return true;
        }
    }), // Check ignite queue.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.queue("TestQueue", 10, new CollectionConfiguration());
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.queue("TestQueue", 10, new CollectionConfiguration());
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            IgniteQueue queue = (IgniteQueue) o;
            String val = "Test";
            queue.add(val);
            assertEquals(val, queue.poll());
            return true;
        }
    })));
    clientMode = false;
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteSet(org.apache.ignite.IgniteSet) IgniteQueue(org.apache.ignite.IgniteQueue) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2)

Example 30 with IgniteAtomicLong

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

Aggregations

IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)31 Ignite (org.apache.ignite.Ignite)23 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)6 IgniteException (org.apache.ignite.IgniteException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)2 IgniteQueue (org.apache.ignite.IgniteQueue)2 IgniteSet (org.apache.ignite.IgniteSet)2 Transaction (org.apache.ignite.transactions.Transaction)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1