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();
}
}
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();
}
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());
}
}
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();
}
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));
}
}
Aggregations