use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteClientReconnectFailoverTest method testReconnectStreamerApi.
/**
* @throws Exception If failed.
*/
public void testReconnectStreamerApi() throws Exception {
final Ignite client = grid(serverCount());
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
stream(ATOMIC_CACHE);
stream(TX_CACHE);
return null;
}
private void stream(String cacheName) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
try (IgniteDataStreamer<Integer, Integer> streamer = client.dataStreamer(cacheName)) {
streamer.allowOverwrite(true);
streamer.perNodeBufferSize(10);
for (int i = 0; i < 100; i++) streamer.addData(rnd.nextInt(100_000), 0);
}
}
});
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteClientReconnectFailoverTest method testReconnectAtomicCache.
/**
* @throws Exception If failed.
*/
public void testReconnectAtomicCache() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCache<Integer, Integer> cache = client.cache(ATOMIC_CACHE);
assertNotNull(cache);
assertEquals(ATOMIC, cache.getConfiguration(CacheConfiguration.class).getAtomicityMode());
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
TreeMap<Integer, Integer> map = new TreeMap<>();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 10; i++) {
Integer key = rnd.nextInt(0, 100_000);
cache.put(key, key);
assertEquals(key, cache.get(key));
map.put(key, key);
}
cache.putAll(map);
Map<Integer, Integer> res = cache.getAll(map.keySet());
assertEquals(map, res);
return null;
}
});
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteClientReconnectFailoverTest method testReconnectTxCache.
/**
* @throws Exception If failed.
*/
public void testReconnectTxCache() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCache<Integer, Integer> cache = client.cache(TX_CACHE);
assertNotNull(cache);
assertEquals(TRANSACTIONAL, cache.getConfiguration(CacheConfiguration.class).getAtomicityMode());
final IgniteTransactions txs = client.transactions();
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
TreeMap<Integer, Integer> map = new TreeMap<>();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 5; i++) {
Integer key = rnd.nextInt(0, 100_000);
cache.put(key, key);
assertEquals(key, cache.get(key));
map.put(key, key);
}
for (TransactionConcurrency txConcurrency : TransactionConcurrency.values()) {
try (Transaction tx = txs.txStart(txConcurrency, REPEATABLE_READ)) {
for (Map.Entry<Integer, Integer> e : map.entrySet()) {
cache.put(e.getKey(), e.getValue());
assertNotNull(cache.get(e.getKey()));
}
tx.commit();
}
}
cache.putAll(map);
Map<Integer, Integer> res = cache.getAll(map.keySet());
assertEquals(map, res);
} catch (IgniteClientDisconnectedException e) {
throw e;
} catch (IgniteException e) {
log.info("Ignore error: " + e);
} catch (CacheException e) {
if (e.getCause() instanceof IgniteClientDisconnectedException)
throw e;
else
log.info("Ignore error: " + e);
}
return null;
}
});
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class BinaryFieldExtractionSelfTest method testPrimitiveMarshalling.
/**
* @throws Exception If failed.
*/
public void testPrimitiveMarshalling() throws Exception {
BinaryMarshaller marsh = createMarshaller();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
TestObject obj = new TestObject(0);
BinaryObjectImpl binObj = toBinary(obj, marsh);
BinaryFieldEx[] fields = new BinaryFieldEx[] { (BinaryFieldEx) binObj.type().field("bVal"), (BinaryFieldEx) binObj.type().field("cVal"), (BinaryFieldEx) binObj.type().field("sVal"), (BinaryFieldEx) binObj.type().field("iVal"), (BinaryFieldEx) binObj.type().field("lVal"), (BinaryFieldEx) binObj.type().field("fVal"), (BinaryFieldEx) binObj.type().field("dVal") };
ByteBuffer buf = ByteBuffer.allocate(1024 * 1024);
for (int i = 0; i < 100; i++) {
TestObject to = new TestObject(rnd.nextLong());
BinaryObjectImpl bObj = toBinary(to, marsh);
for (BinaryFieldEx field : fields) field.writeField(bObj, buf);
buf.flip();
for (BinaryFieldEx field : fields) assertEquals(field.value(bObj), field.readField(buf));
buf.flip();
}
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class CachePutIfAbsentTest method testTxConflictGetAndPutIfAbsent.
/**
* @throws Exception If failed.
*/
public void testTxConflictGetAndPutIfAbsent() throws Exception {
Ignite ignite0 = ignite(0);
final IgniteTransactions txs = ignite0.transactions();
for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
try {
IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 10; i++) {
Integer key = rnd.nextInt(10_000);
cache.put(key, 2);
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : TransactionIsolation.values()) {
try (Transaction tx = txs.txStart(concurrency, isolation)) {
Object old = cache.getAndPutIfAbsent(key, 3);
assertEquals(2, old);
Object val = cache.get(key);
assertEquals(2, val);
tx.commit();
}
assertEquals((Integer) 2, cache.get(key));
}
}
}
} finally {
ignite0.destroyCache(ccfg.getName());
}
}
}
Aggregations