use of org.apache.ignite.IgniteCache in project ignite by apache.
the class IgniteCacheNearOnlyTxTest method testConcurrentTx.
/**
* @throws Exception If failed.
*/
public void testConcurrentTx() throws Exception {
final Ignite ignite1 = ignite(1);
assertTrue(ignite1.configuration().isClientMode());
ignite1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());
final Integer key = 1;
IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteCache<Integer, Integer> cache = ignite1.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 100; i++) cache.put(key, 1);
return null;
}
}, 5, "put1-thread");
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
IgniteCache<Integer, Integer> cache = ignite1.cache(DEFAULT_CACHE_NAME);
IgniteTransactions txs = ignite1.transactions();
for (int i = 0; i < 100; i++) {
try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.get(key);
cache.put(key, 1);
tx.commit();
}
}
return null;
}
}, 5, "put2-thread");
fut1.get();
fut2.get();
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class NearCachePutAllMultinodeTest method testMultithreadedPutAll.
/**
* @throws Exception If failed.
*/
public void testMultithreadedPutAll() throws Exception {
final AtomicInteger idx = new AtomicInteger();
runMultiThreaded(new Callable<Object>() {
private final Random rnd = new Random();
@Override
public Object call() throws Exception {
int threadIdx = idx.getAndIncrement();
int node = threadIdx % 2 + (GRID_CNT - 2);
IgniteCache<Object, Object> cache = jcache(node);
for (int i = 0; i < TX_CNT; i++) {
Map<Integer, String> map = new TreeMap<>();
for (int j = 0; j < 3; j++) map.put(rnd.nextInt(10), "value");
cache.putAll(map);
if (i % 100 == 0)
log.info("Iteration: " + i + " " + node);
}
return null;
}
}, 8, "putAll");
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class WalModeChangeAdvancedSelfTest method testCacheCleanup.
/**
* Test cache cleanup on restart.
*
* @throws Exception If failed.
*/
public void testCacheCleanup() throws Exception {
Ignite srv = startGrid(config(SRV_1, false, false));
srv.cluster().active(true);
IgniteCache cache1 = srv.getOrCreateCache(cacheConfig(CACHE_NAME, PARTITIONED, TRANSACTIONAL));
IgniteCache cache2 = srv.getOrCreateCache(cacheConfig(CACHE_NAME_2, PARTITIONED, TRANSACTIONAL));
assertForAllNodes(CACHE_NAME, true);
assertForAllNodes(CACHE_NAME_2, true);
for (int i = 0; i < 10; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
srv.cluster().disableWal(CACHE_NAME);
assertForAllNodes(CACHE_NAME, false);
assertForAllNodes(CACHE_NAME_2, true);
for (int i = 10; i < 20; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
srv.cluster().disableWal(CACHE_NAME_2);
assertForAllNodes(CACHE_NAME, false);
assertForAllNodes(CACHE_NAME_2, false);
for (int i = 20; i < 30; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
assertEquals(cache1.size(), 30);
assertEquals(cache2.size(), 30);
srv.cluster().enableWal(CACHE_NAME);
assertForAllNodes(CACHE_NAME, true);
assertForAllNodes(CACHE_NAME_2, false);
assertEquals(cache1.size(), 30);
assertEquals(cache2.size(), 30);
stopAllGrids(true);
srv = startGrid(config(SRV_1, false, false));
srv.cluster().active(true);
cache1 = srv.cache(CACHE_NAME);
cache2 = srv.cache(CACHE_NAME_2);
assertForAllNodes(CACHE_NAME, true);
assertForAllNodes(CACHE_NAME_2, false);
assertEquals(30, cache1.size());
assertEquals(0, cache2.size());
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class WalModeChangeAdvancedSelfTest method testConcurrentOperations.
/**
* Test that concurrent enable/disable events doesn't leave to hangs.
*
* @throws Exception If failed.
*/
public void testConcurrentOperations() throws Exception {
final Ignite srv1 = startGrid(config(SRV_1, false, false));
final Ignite srv2 = startGrid(config(SRV_2, false, false));
final Ignite srv3 = startGrid(config(SRV_3, false, true));
final Ignite cli = startGrid(config(CLI, true, false));
final Ignite cacheCli = startGrid(config(CLI_2, true, false));
cacheCli.cluster().active(true);
final IgniteCache cache = cacheCli.getOrCreateCache(cacheConfig(PARTITIONED));
for (int i = 1; i <= 3; i++) {
// Start pushing requests.
Collection<Ignite> walNodes = new ArrayList<>();
walNodes.add(srv1);
walNodes.add(srv2);
walNodes.add(srv3);
walNodes.add(cli);
final AtomicBoolean done = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(5);
for (Ignite node : walNodes) {
final Ignite node0 = node;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
checkConcurrentOperations(done, node0);
latch.countDown();
}
});
t.setName("wal-load-" + node0.name());
t.start();
}
// Do some cache loading in the mean time.
Thread t = new Thread(new Runnable() {
@Override
public void run() {
int i = 0;
while (!done.get()) cache.put(i, i++);
latch.countDown();
}
});
t.setName("cache-load");
t.start();
Thread.sleep(20_000);
done.set(true);
X.println(">>> Stopping iteration: " + i);
latch.await();
X.println(">>> Iteration finished: " + i);
}
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalFiltered.
/**
* @throws Exception If failed.
*/
public void testLocalFiltered() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteBiPredicate<Integer, Value> filter = new IgniteBiPredicate<Integer, Value>() {
@Override
public boolean apply(Integer k, Value v) {
return v.idx % 1000 == 0;
}
};
IgniteClosure<Cache.Entry<Integer, Value>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, Value>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, Value> e) {
return e.getValue().idx;
}
};
return ignite.cache("test-cache").query(new ScanQuery<>(filter).setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(5, res.size());
Collections.sort(res);
for (int i = 0; i < 5; i++) assertEquals(i * 1000, res.get(i).intValue());
} finally {
cache.destroy();
}
}
Aggregations