use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCacheGroupsTest method continuousQuery.
/**
* @param cacheMode Cache mode.
* @param atomicityMode Cache atomicity mode.
* @throws Exception If failed.
*/
private void continuousQuery(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
final int keys = 10_000;
Integer[] data1 = generateData(keys);
Integer[] data2 = generateData(keys);
boolean loc = cacheMode == LOCAL;
if (loc)
startGrid(0);
else
startGridsMultiThreaded(4);
Ignite srv0 = ignite(0);
srv0.createCache(cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 2, false));
srv0.createCache(cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 2, false));
final AtomicInteger cntr1 = new AtomicInteger();
final AtomicInteger cntr2 = new AtomicInteger();
CacheEntryUpdatedListener lsnr1 = new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
for (CacheEntryEvent<? extends Integer, ? extends Integer> ignored : evts) cntr1.incrementAndGet();
}
};
CacheEntryUpdatedListener lsnr2 = new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
for (CacheEntryEvent<? extends Integer, ? extends Integer> ignored : evts) cntr2.incrementAndGet();
}
};
QueryCursor qry1 = ignite(loc ? 0 : 2).cache(CACHE1).query(new ContinuousQuery<>().setLocalListener(lsnr1));
QueryCursor qry2 = ignite(loc ? 0 : 3).cache(CACHE2).query(new ContinuousQuery<>().setLocalListener(lsnr2));
if (atomicityMode == TRANSACTIONAL) {
Ignite ignite = ignite(loc ? 0 : 1);
IgniteCache<Integer, Integer> cache1 = ignite.cache(CACHE1);
IgniteCache<Integer, Integer> cache2 = ignite.cache(CACHE2);
try (Transaction tx = ignite.transactions().txStart()) {
for (int i = 0; i < keys; i++) {
cache1.put(i, data1[i]);
cache2.put(i, data2[i]);
}
tx.commit();
}
} else {
int ldrs = 4;
List<Callable<?>> cls = new ArrayList<>(ldrs * 2);
for (int i = 0; i < ldrs; i++) {
cls.add(putOperation(loc ? 0 : 1, ldrs, i, CACHE1, data1));
cls.add(putOperation(loc ? 0 : 2, ldrs, i, CACHE2, data2));
}
GridTestUtils.runMultiThreaded(cls, "loaders");
}
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cntr1.get() == keys && cntr2.get() == keys;
}
}, 2000);
assertEquals(cntr1.get(), keys);
assertEquals(cntr2.get(), keys);
qry1.close();
Map<Integer, Integer> map = generateDataMap(10);
srv0.cache(CACHE1).putAll(map);
srv0.cache(CACHE2).putAll(map);
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cntr2.get() == keys + 10;
}
}, 2000);
assertEquals(keys + 10, cntr2.get());
assertEquals(keys, cntr1.get());
qry2.close();
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCacheReadThroughEvictionSelfTest method destroyCacheSafe.
/**
* @param ig Ignite.
* @param cacheName Cache name to destroy.
* @throws IgniteCheckedException If failed.
*/
private void destroyCacheSafe(Ignite ig, final String cacheName) throws IgniteCheckedException {
ig.destroyCache(cacheName);
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
for (Ignite g : G.allGrids()) {
IgniteInternalCache<Object, Object> cache = ((IgniteEx) g).context().cache().cache(cacheName);
if (cache != null)
return false;
}
return true;
}
}, getTestTimeout());
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCacheReadThroughEvictionSelfTest method testReadThroughEvictionPolicy.
/**
* @throws Exception if failed.
*/
public void testReadThroughEvictionPolicy() throws Exception {
Ignite ig = testedGrid();
CacheConfiguration<Object, Object> cc = variationConfig("eviction");
cc.setEvictionPolicy(new FifoEvictionPolicy(1));
cc.setOnheapCacheEnabled(true);
final IgniteCache<Object, Object> cache = ig.createCache(cc);
try {
for (int i = 0; i < KEYS; i++) cache.put(key(i), value(i));
assertTrue(GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
int size = cache.size(CachePeekMode.ONHEAP);
int offheapSize = cache.size(CachePeekMode.OFFHEAP);
System.out.println("Cache [onHeap=" + size + ", offHeap=" + offheapSize + ']');
return size <= testsCfg.gridCount();
}
}, 30_000));
for (int i = 0; i < KEYS; i++) assertEquals(value(i), cache.get(key(i)));
} finally {
destroyCacheSafe(ig, cc.getName());
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCacheReadThroughEvictionSelfTest method waitEmpty.
/**
* @throws Exception if failed.
*/
private void waitEmpty(final String name) throws Exception {
boolean success = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
for (Ignite g : G.allGrids()) {
GridCacheAdapter<Object, Object> cache = ((IgniteEx) g).context().cache().internalCache(name);
if (cache == null)
return true;
if (!cache.isEmpty())
return false;
}
return true;
}
}, getTestTimeout());
assertTrue("Failed to wait for the cache to be empty", success);
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridCacheNearEvictionSelfTest method testNearEnabledThreeNodes.
/**
* @throws Exception If failed.
*/
public void testNearEnabledThreeNodes() throws Exception {
gridCnt = 3;
startGridsMultiThreaded(gridCnt);
try {
final int cnt = 100;
grid(0).compute().broadcast(new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public Object call() throws Exception {
IgniteCache<Integer, String> c = ignite.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < cnt; i++) c.put(i, Integer.toString(i));
return true;
}
});
for (int i = 0; i < gridCnt; i++) {
final GridCacheAdapter cache = internalCache(i);
final GridCacheAdapter near = near(i);
// Repeatedly check cache sizes because of concurrent cache updates.
assertTrue(GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
// Every node contains either near, backup, or primary.
return cnt == cache.size() + near.nearSize();
}
}, getTestTimeout()));
int keySize = near(i).nearSize();
assert keySize < cnt : "Key size is not less than count [cnt=" + cnt + ", size=" + keySize + ']';
}
} finally {
stopAllGrids();
}
}
Aggregations