use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testMixed1.
/** @throws Exception If failed. */
public void testMixed1() 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.incrementAndGet();
t.getAndIncrement();
t.incrementAndGet();
t.getAndIncrement();
t.getAndAdd(3);
t.addAndGet(3);
}
}, seq, ITERATION_NUM, THREAD_NUM);
assertEquals(10 * ITERATION_NUM * THREAD_NUM, seq.get());
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testGetAndAdd.
/** @throws Exception If failed. */
public void testGetAndAdd() 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.getAndAdd(5);
}
}, seq, ITERATION_NUM, THREAD_NUM);
assertEquals(5 * ITERATION_NUM * THREAD_NUM, seq.get());
}
use of org.apache.ignite.IgniteAtomicSequence in project camel by apache.
the class IgniteIdGenEndpoint method createProducer.
@Override
public Producer createProducer() throws Exception {
IgniteAtomicSequence atomicSeq = ignite().atomicSequence(name, initialValue, false);
if (atomicSeq == null) {
atomicSeq = ignite().atomicSequence(name, initialValue, true);
LOG.info("Created AtomicSequence of ID Generator with name {}.", name);
}
if (batchSize != null) {
atomicSeq.batchSize(batchSize);
}
return new IgniteIdGenProducer(this, atomicSeq);
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCacheMultiNodeDataStructureTest method sample.
/**
*
* @param g Grid.
* @param cacheName Cache name.
*/
private static void sample(Ignite g, String cacheName) {
IgniteAtomicLong atomicLong = g.atomicLong("keygen", 0, true);
IgniteAtomicSequence seq = g.atomicSequence("keygen", 0, true);
seq.incrementAndGet();
seq.incrementAndGet();
seq.incrementAndGet();
seq.incrementAndGet();
atomicLong.incrementAndGet();
atomicLong.incrementAndGet();
atomicLong.incrementAndGet();
X.println(cacheName + ": Seq: " + seq.get() + " atomicLong " + atomicLong.get());
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCacheSequenceApiSelfAbstractTest method testPrepareSequence.
/**
* @throws Exception If failed.
*/
public void testPrepareSequence() throws Exception {
// Random sequence names.
String locSeqName1 = UUID.randomUUID().toString();
String locSeqName2 = UUID.randomUUID().toString();
IgniteAtomicSequence locSeq1 = grid().atomicSequence(locSeqName1, 0, true);
IgniteAtomicSequence locSeq2 = grid().atomicSequence(locSeqName2, 0, true);
IgniteAtomicSequence locSeq3 = grid().atomicSequence(locSeqName1, 0, true);
assertNotNull(locSeq1);
assertNotNull(locSeq2);
assertNotNull(locSeq3);
assert locSeq1.equals(locSeq3);
assert locSeq3.equals(locSeq1);
assert !locSeq3.equals(locSeq2);
removeSequence(locSeqName1);
removeSequence(locSeqName2);
}
Aggregations