use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongChangingTopologySelfTest method testIncrementConsistency.
/**
* @throws Exception If failed.
*/
public void testIncrementConsistency() throws Exception {
startGrids(GRID_CNT);
final AtomicBoolean run = new AtomicBoolean(true);
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
/** {@inheritDoc} */
@Override
public Void call() throws Exception {
IgniteAtomicLong cntr = ignite(0).atomicLong(ATOMIC_LONG_NAME, 0, true);
while (run.get()) queue.add(cntr.getAndIncrement());
return null;
}
}, 4, "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();
info("Increments: " + queue.size());
checkQueue();
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongApiAbstractSelfTest method testCreateRemove.
/**
* @throws Exception If failed.
*/
public void testCreateRemove() throws Exception {
info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
Ignite ignite = grid(0);
String atomicName1 = "FIRST";
String atomicName2 = "SECOND";
IgniteAtomicLong atomic1 = ignite.atomicLong(atomicName1, 0, true);
IgniteAtomicLong atomic2 = ignite.atomicLong(atomicName2, 0, true);
IgniteAtomicLong atomic3 = ignite.atomicLong(atomicName1, 0, true);
assertNotNull(atomic1);
assertNotNull(atomic2);
assertNotNull(atomic3);
assert atomic1.equals(atomic3);
assert atomic3.equals(atomic1);
assert !atomic3.equals(atomic2);
atomic1.close();
atomic2.close();
atomic3.close();
assertNull(ignite.atomicLong(atomicName1, 0, false));
assertNull(ignite.atomicLong(atomicName2, 0, false));
try {
atomic1.get();
fail();
} catch (IllegalStateException | IgniteException e) {
info("Caught expected exception: " + e.getMessage());
}
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongApiAbstractSelfTest method testGetAndSet.
/**
* @throws Exception If failed.
*/
public void testGetAndSet() throws Exception {
info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
Ignite ignite = grid(0);
IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
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 testIsolation.
/**
* Implementation of ignite data structures internally uses special system caches, need make sure that
* transaction on these system caches do not intersect with transactions started by user.
*
* @throws Exception If failed.
*/
public void testIsolation() throws Exception {
Ignite ignite = grid(0);
IgniteCache<Object, Object> cache = ignite.cache(TRANSACTIONAL_CACHE_NAME);
IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
long curAtomicVal = atomic.get();
try (Transaction tx = ignite.transactions().txStart()) {
atomic.getAndIncrement();
cache.put(1, 1);
tx.rollback();
}
assertEquals(0, cache.size());
assertEquals(curAtomicVal + 1, atomic.get());
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongApiAbstractSelfTest method testGetAndAdd.
/**
* @throws Exception If failed.
*/
public void testGetAndAdd() throws Exception {
info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
Ignite ignite = grid(0);
IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
long delta = RND.nextLong();
long curAtomicVal = atomic.get();
assert curAtomicVal == atomic.getAndAdd(delta);
assert curAtomicVal + delta == atomic.get();
}
Aggregations