use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteAtomicLongChangingTopologySelfTest method testQueueClose.
/**
* @throws Exception If failed.
*/
public void testQueueClose() throws Exception {
startGrids(GRID_CNT);
int threads = 4;
final AtomicBoolean run = new AtomicBoolean(true);
final AtomicInteger idx = new AtomicInteger();
final AtomicReferenceArray<Exception> arr = new AtomicReferenceArray<>(threads);
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
/** {@inheritDoc} */
@Override
public Void call() throws Exception {
int base = idx.getAndIncrement();
try {
int delta = 0;
while (run.get()) {
IgniteAtomicLong cntr = ignite(0).atomicLong(ATOMIC_LONG_NAME + "-" + base + "-" + delta, 0, true);
for (int i = 0; i < 5; i++) queue.add(cntr.getAndIncrement());
cntr.close();
delta++;
}
} catch (Exception e) {
arr.set(base, e);
throw e;
} finally {
info("RUNNER THREAD IS STOPPING");
}
return null;
}
}, threads, "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();
for (int i = 0; i < threads; i++) {
Exception err = arr.get(i);
if (err != null)
throw err;
}
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class GridCacheAbstractDataStructuresFailoverSelfTest method doTestAtomicLong.
/**
* Tests IgniteAtomicLong.
*
* @param topWorker Topology change worker.
* @throws Exception If failed.
*/
private void doTestAtomicLong(ConstantTopologyChangeWorker topWorker) throws Exception {
try (IgniteAtomicLong s = grid(0).atomicLong(STRUCTURE_NAME, 1, true)) {
IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Object>() {
@Override
public Object apply(Ignite ignite) {
assert ignite.atomicLong(STRUCTURE_NAME, 1, true).get() > 0;
return null;
}
});
long val = s.get();
while (!fut.isDone()) {
assertEquals(val, s.get());
assertEquals(++val, s.incrementAndGet());
}
fut.get();
for (Ignite g : G.allGrids()) assertEquals(val, g.atomicLong(STRUCTURE_NAME, 1, false).get());
}
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class GridCacheAbstractDataStructuresFailoverSelfTest method testAtomicLongTopologyChange.
/**
* @throws Exception If failed.
*/
public void testAtomicLongTopologyChange() throws Exception {
try (IgniteAtomicLong atomic = grid(0).atomicLong(STRUCTURE_NAME, 10, true)) {
Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
assertEquals(10, g.atomicLong(STRUCTURE_NAME, 10, false).get());
assertEquals(20, g.atomicLong(STRUCTURE_NAME, 10, false).addAndGet(10));
stopGrid(NEW_IGNITE_INSTANCE_NAME);
assertEquals(20, grid(0).atomicLong(STRUCTURE_NAME, 10, true).get());
}
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteClientReconnectApiExceptionTest method dataStructureOperationsTest.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
public void dataStructureOperationsTest() throws Exception {
clientMode = true;
final Ignite client = startGrid(serverCount());
doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check atomic long.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.atomicLong("testAtomic", 41, true);
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.atomicLong("testAtomic", 41, true);
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteAtomicLong atomicLong = (IgniteAtomicLong) o;
assertEquals(42, atomicLong.incrementAndGet());
return true;
}
}), // Check set.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.set("testSet", new CollectionConfiguration());
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.set("testSet", new CollectionConfiguration());
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteSet set = (IgniteSet) o;
String val = "testVal";
set.add(val);
assertEquals(1, set.size());
assertTrue(set.contains(val));
return true;
}
}), // Check ignite queue.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.queue("TestQueue", 10, new CollectionConfiguration());
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.queue("TestQueue", 10, new CollectionConfiguration());
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteQueue queue = (IgniteQueue) o;
String val = "Test";
queue.add(val);
assertEquals(val, queue.poll());
return true;
}
})));
clientMode = false;
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicsReconnectClusterRestart.
/**
* @throws Exception If failed.
*/
public void testAtomicsReconnectClusterRestart() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
final IgniteAtomicLong atomicLong = client.atomicLong("atomicLong", 1L, true);
final IgniteAtomicReference<Integer> atomicRef = client.atomicReference("atomicRef", 1, true);
final IgniteAtomicStamped<Integer, Integer> atomicStamped = client.atomicStamped("atomicStamped", 1, 1, true);
final IgniteCountDownLatch latch = client.countDownLatch("latch", 1, true, true);
final IgniteAtomicSequence seq = client.atomicSequence("seq", 1L, true);
Ignite srv = grid(0);
reconnectServersRestart(log, client, Collections.singleton(srv), new Callable<Collection<Ignite>>() {
@Override
public Collection<Ignite> call() throws Exception {
return Collections.singleton((Ignite) startGrid(0));
}
});
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
atomicStamped.compareAndSet(1, 1, 2, 2);
return null;
}
}, IllegalStateException.class, null);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
atomicRef.compareAndSet(1, 2);
return null;
}
}, IllegalStateException.class, null);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
atomicLong.incrementAndGet();
return null;
}
}, IllegalStateException.class, null);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
seq.getAndAdd(1L);
return null;
}
}, IllegalStateException.class, null);
}
Aggregations