use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class GridRedisSetCommandHandler method asRestRequest.
/** {@inheritDoc} */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
assert msg != null;
if (msg.messageSize() < 3)
throw new GridRedisGenericException("Wrong number of arguments");
// check if an atomic long with the key exists (related to incr/decr).
IgniteAtomicLong l = ctx.grid().atomicLong(msg.key(), 0, false);
if (l != null) {
try {
l.close();
} catch (IgniteException ignored) {
U.warn(log, "Failed to remove atomic long for key: " + msg.key());
}
}
GridRestCacheRequest restReq = new GridRestCacheRequest();
restReq.clientId(msg.clientId());
restReq.key(msg.key());
restReq.command(CACHE_PUT);
restReq.cacheName(CACHE_NAME);
restReq.value(msg.aux(VAL_POS));
if (msg.messageSize() >= 4) {
List<String> params = msg.aux();
// get rid of SET value.
params.remove(0);
if (U.containsStringCollection(params, "nx", true))
restReq.command(CACHE_PUT_IF_ABSENT);
else if (U.containsStringCollection(params, "xx", true))
restReq.command(CACHE_REPLACE);
setExpire(restReq, params);
}
return restReq;
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class GridCacheAbstractDataStructuresFailoverSelfTest method testAtomicLongFailsWhenServersLeft.
/**
* @throws Exception If failed.
*/
public void testAtomicLongFailsWhenServersLeft() throws Exception {
client = true;
Ignite ignite = startGrid(gridCount());
new Timer().schedule(new TimerTask() {
@Override
public void run() {
for (int i = 0; i < gridCount(); i++) stopGrid(i);
}
}, 10_000);
long stopTime = U.currentTimeMillis() + TEST_TIMEOUT / 2;
IgniteAtomicLong atomic = ignite.atomicLong(STRUCTURE_NAME, 10, true);
try {
while (U.currentTimeMillis() < stopTime) assertEquals(10, atomic.get());
} catch (IgniteException ignore) {
// Test that client does not hang.
return;
}
fail();
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteCachePutRetryTransactionalSelfTest method testAtomicLongRetries.
/**
* @throws Exception If failed.
*/
public void testAtomicLongRetries() throws Exception {
final AtomicBoolean finished = new AtomicBoolean();
IgniteAtomicLong atomic = ignite(0).atomicLong("TestAtomic", 0, true);
IgniteInternalFuture<Object> fut = runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finished.get()) {
stopGrid(3);
U.sleep(300);
startGrid(3);
}
return null;
}
});
final int keysCnt = 20_000;
try {
for (int i = 0; i < keysCnt; i++) atomic.incrementAndGet();
finished.set(true);
fut.get();
} finally {
finished.set(true);
}
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicLongReconnectRemoved.
/**
* @throws Exception If failed.
*/
public void testAtomicLongReconnectRemoved() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = clientRouter(client);
final IgniteAtomicLong clientAtomicLong = client.atomicLong("atomicLongRmv", 0, true);
assertEquals(0L, clientAtomicLong.getAndAdd(1));
final IgniteAtomicLong srvAtomicLong = srv.atomicLong("atomicLongRmv", 0, false);
assertEquals(1L, srvAtomicLong.getAndAdd(1));
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
srvAtomicLong.close();
}
});
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
clientAtomicLong.getAndAdd(1);
return null;
}
}, IllegalStateException.class, null);
IgniteAtomicLong newClientAtomicLong = client.atomicLong("atomicLongRmv", 0, true);
assertEquals(0L, newClientAtomicLong.getAndAdd(1));
IgniteAtomicLong newSrvAtomicLong = srv.atomicLong("atomicLongRmv", 0, false);
assertEquals(1L, newSrvAtomicLong.getAndAdd(1));
}
use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicLongReconnect.
/**
* @throws Exception If failed.
*/
public void testAtomicLongReconnect() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = clientRouter(client);
IgniteAtomicLong clientAtomicLong = client.atomicLong("atomicLong", 0, true);
assertEquals(0L, clientAtomicLong.getAndAdd(1));
final IgniteAtomicLong srvAtomicLong = srv.atomicLong("atomicLong", 0, false);
assertEquals(1L, srvAtomicLong.getAndAdd(1));
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
assertEquals(2L, srvAtomicLong.getAndAdd(1));
}
});
assertEquals(3L, clientAtomicLong.getAndAdd(1));
assertEquals(4L, srvAtomicLong.getAndAdd(1));
assertEquals(5L, clientAtomicLong.getAndAdd(1));
}
Aggregations