Search in sources :

Example 1 with IgniteAtomicSequence

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

the class IgniteIdGenTest method deleteSets.

@After
public void deleteSets() {
    for (String name : ImmutableSet.<String>of("abc")) {
        IgniteAtomicSequence seq = ignite().atomicSequence(name, 0, false);
        if (seq == null) {
            continue;
        }
        seq.close();
    }
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) After(org.junit.After)

Example 2 with IgniteAtomicSequence

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

the class GridCacheAbstractDataStructuresFailoverSelfTest method testAtomicSequenceInitialization.

/**
 * @throws Exception If failed.
 */
public void testAtomicSequenceInitialization() throws Exception {
    int threadCnt = 3;
    final AtomicInteger idx = new AtomicInteger(gridCount());
    IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new CA() {

        @Override
        public void apply() {
            int id = idx.getAndIncrement();
            try {
                log.info("Start node: " + id);
                startGrid(id);
                Thread.sleep(1000);
            } catch (Exception e) {
                throw F.wrap(e);
            } finally {
                stopGrid(id);
                info("Thread finished.");
            }
        }
    }, threadCnt, "test-thread");
    while (!fut.isDone()) {
        grid(0).compute().call(new IgniteCallable<Object>() {

            /**
             */
            @IgniteInstanceResource
            private Ignite g;

            @Override
            public Object call() throws Exception {
                IgniteAtomicSequence seq = g.atomicSequence(STRUCTURE_NAME, 1, true);
                assert seq != null;
                for (int i = 0; i < 1000; i++) seq.getAndIncrement();
                return null;
            }
        });
    }
    fut.get();
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite) CA(org.apache.ignite.internal.util.typedef.CA) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Example 3 with IgniteAtomicSequence

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

the class SystemViewSelfTest method testAtomicSequence.

/**
 */
@Test
public void testAtomicSequence() throws Exception {
    try (IgniteEx g0 = startGrid(0);
        IgniteEx g1 = startGrid(1)) {
        IgniteAtomicSequence s1 = g0.atomicSequence("seq-1", 42, true);
        IgniteAtomicSequence s2 = g0.atomicSequence("seq-2", new AtomicConfiguration().setBackups(1).setGroupName("my-group"), 43, true);
        s1.batchSize(42);
        SystemView<AtomicSequenceView> seqs0 = g0.context().systemView().view(SEQUENCES_VIEW);
        SystemView<AtomicSequenceView> seqs1 = g1.context().systemView().view(SEQUENCES_VIEW);
        assertEquals(2, seqs0.size());
        assertEquals(0, seqs1.size());
        for (AtomicSequenceView s : seqs0) {
            if ("seq-1".equals(s.name())) {
                assertEquals(42, s.value());
                assertEquals(42, s.batchSize());
                assertEquals(DEFAULT_DS_GROUP_NAME, s.groupName());
                assertEquals(CU.cacheId(DEFAULT_DS_GROUP_NAME), s.groupId());
                long val = s1.addAndGet(42);
                assertEquals(val, s.value());
                assertFalse(s.removed());
            } else {
                assertEquals("seq-2", s.name());
                assertEquals(DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE, s.batchSize());
                assertEquals(43, s.value());
                assertEquals("my-group", s.groupName());
                assertEquals(CU.cacheId("my-group"), s.groupId());
                assertFalse(s.removed());
                s2.close();
                assertTrue(waitForCondition(s::removed, getTestTimeout()));
            }
        }
        g1.atomicSequence("seq-1", 42, true);
        assertEquals(1, seqs1.size());
        AtomicSequenceView s = seqs1.iterator().next();
        assertEquals(DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE + 42, s.value());
        assertEquals(DFLT_ATOMIC_SEQUENCE_RESERVE_SIZE, s.batchSize());
        assertEquals(DEFAULT_DS_GROUP_NAME, s.groupName());
        assertEquals(CU.cacheId(DEFAULT_DS_GROUP_NAME), s.groupId());
        assertFalse(s.removed());
        s1.close();
        assertTrue(waitForCondition(s::removed, getTestTimeout()));
        assertEquals(0, seqs0.size());
        assertEquals(0, seqs1.size());
    }
}
Also used : AtomicSequenceView(org.apache.ignite.spi.systemview.view.datastructures.AtomicSequenceView) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 4 with IgniteAtomicSequence

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

the class IgniteDataStructureUniqueNameTest method testUniqueNamePerGroup.

/**
 * @throws Exception If failed.
 */
@Test
public void testUniqueNamePerGroup() throws Exception {
    Ignite ignite = ignite(0);
    IgniteAtomicLong atomicLong = ignite.atomicLong("testName", new AtomicConfiguration().setGroupName("group1"), 0, true);
    IgniteAtomicSequence atomicSeq = ignite.atomicSequence("testName", new AtomicConfiguration().setGroupName("group2"), 0, true);
    assert atomicLong != null;
    assert atomicSeq != null;
    atomicLong = ignite.atomicLong("testName", new AtomicConfiguration().setGroupName("group1"), 0, false);
    atomicSeq = ignite.atomicSequence("testName", new AtomicConfiguration().setGroupName("group2"), 0, false);
    assert atomicLong != null;
    assert atomicSeq != null;
    atomicLong.close();
    atomicSeq.close();
}
Also used : IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) Test(org.junit.Test)

Example 5 with IgniteAtomicSequence

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

the class IgniteClientDataStructuresAbstractTest method testSequence.

/**
 * @param creator Creator node.
 * @param other Other node.
 * @throws Exception If failed.
 */
private void testSequence(Ignite creator, Ignite other) throws Exception {
    assertNull(creator.atomicSequence("seq1", 1L, false));
    assertNull(other.atomicSequence("seq1", 1L, false));
    List<IgniteAtomicSequence> sequences = new ArrayList<>(2);
    try (IgniteAtomicSequence seq = creator.atomicSequence("seq1", 1L, true)) {
        sequences.add(seq);
        assertNotNull(seq);
        assertEquals(1L, seq.get());
        assertEquals(1L, seq.getAndAdd(1));
        assertEquals(2L, seq.get());
        IgniteAtomicSequence seq0 = other.atomicSequence("seq1", 1L, false);
        sequences.add(seq0);
        assertNotNull(seq0);
    }
    for (IgniteAtomicSequence seq : sequences) {
        try {
            seq.getAndAdd(seq.batchSize());
            fail("Operations with closed sequence must fail");
        } catch (Throwable ignore) {
        // No-op.
        }
    }
    for (Ignite ignite : F.asList(creator, other)) {
        assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return ignite.atomicSequence("seq1", 1L, false) == null;
            }
        }, 3_000L));
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite)

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