use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongApiAbstractSelfTest method testGetAndSetInTx.
/**
* @throws Exception If failed.
*/
public void testGetAndSetInTx() throws Exception {
info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
Ignite ignite = grid(0);
IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
IgniteCache<Object, Object> cache = ignite.cache(TRANSACTIONAL_CACHE_NAME);
try (Transaction tx = ignite.transactions().txStart()) {
cache.put(1, 1);
long newVal = RND.nextLong();
long curAtomicVal = atomic.get();
assert curAtomicVal == atomic.getAndSet(newVal);
assert newVal == atomic.get();
}
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongApiAbstractSelfTest method testGetAndIncrement.
/**
* @throws Exception If failed.
*/
public void testGetAndIncrement() throws Exception {
info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
Ignite ignite = grid(0);
IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
long curAtomicVal = atomic.get();
assert curAtomicVal == atomic.getAndIncrement();
assert curAtomicVal + 1 == atomic.get();
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongApiAbstractSelfTest method testCompareAndSet.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "NullableProblems", "ConstantConditions" })
public void testCompareAndSet() throws Exception {
info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
Ignite ignite = grid(0);
IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
long newVal = RND.nextLong();
final long oldVal = atomic.get();
// Don't set new value.
assert !atomic.compareAndSet(oldVal - 1, newVal);
assert oldVal == atomic.get();
// Set new value.
assert atomic.compareAndSet(oldVal, newVal);
assert newVal == atomic.get();
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongApiAbstractSelfTest method testDecrementAndGet.
/**
* @throws Exception If failed.
*/
public void testDecrementAndGet() throws Exception {
info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
Ignite ignite = grid(0);
IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
long curAtomicVal = atomic.get();
assert curAtomicVal - 1 == atomic.decrementAndGet();
assert curAtomicVal - 1 == atomic.get();
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteClientDataStructuresAbstractTest method testAtomicLong.
/**
* @param creator Creator node.
* @param other Other node.
* @throws Exception If failed.
*/
private void testAtomicLong(Ignite creator, Ignite other) throws Exception {
assertNull(creator.atomicLong("long1", 1L, false));
assertNull(other.atomicLong("long1", 1L, false));
try (IgniteAtomicLong cntr = creator.atomicLong("long1", 1L, true)) {
assertNotNull(cntr);
assertEquals(1L, cntr.get());
assertEquals(1L, cntr.getAndAdd(1));
assertEquals(2L, cntr.get());
IgniteAtomicLong cntr0 = other.atomicLong("long1", 1L, false);
assertNotNull(cntr0);
assertEquals(2L, cntr0.get());
assertEquals(3L, cntr0.incrementAndGet());
assertEquals(3L, cntr.get());
}
assertNull(creator.atomicLong("long1", 1L, false));
assertNull(other.atomicLong("long1", 1L, false));
}
Aggregations