use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteTxExceptionAbstractSelfTest method checkUnlocked.
/**
* @param key Key.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void checkUnlocked(final Integer key) throws Exception {
TestIndexingSpi.forceFail(false);
awaitPartitionMapExchange();
info("Check key: " + key);
for (int i = 0; i < gridCount(); i++) {
final int idx = i;
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
IgniteKernal grid = (IgniteKernal) grid(idx);
GridCacheAdapter cache = grid.internalCache(DEFAULT_CACHE_NAME);
GridCacheEntryEx entry = cache.peekEx(key);
log.info("Entry: " + entry);
if (entry != null) {
try {
boolean locked = entry.lockedByAny();
if (locked) {
info("Unexpected entry for grid [i=" + idx + ", entry=" + entry + ']');
return false;
}
} catch (GridCacheEntryRemovedException ignore) {
// Obsolete entry cannot be locked.
}
}
if (cache.isNear()) {
entry = ((GridNearCacheAdapter) cache).dht().peekEx(key);
log.info("Dht entry: " + entry);
if (entry != null) {
try {
boolean locked = entry.lockedByAny();
if (locked) {
info("Unexpected entry for grid [i=" + idx + ", entry=" + entry + ']');
return false;
}
} catch (GridCacheEntryRemovedException ignore) {
// Obsolete entry cannot be locked.
}
}
}
return true;
}
}, getTestTimeout());
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCacheLoadRebalanceEvictionSelfTest method testStartRebalancing.
/**
* @throws Exception If failed.
*/
public void testStartRebalancing() throws Exception {
List<IgniteInternalFuture<Object>> futs = new ArrayList<>();
int gridCnt = 4;
for (int i = 0; i < gridCnt; i++) {
final IgniteEx ig = startGrid(i);
futs.add(GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
ig.cache(DEFAULT_CACHE_NAME).localLoadCache(null);
return null;
}
}));
}
try {
for (IgniteInternalFuture<Object> fut : futs) fut.get();
for (int i = 0; i < gridCnt; i++) {
IgniteEx grid = grid(i);
final IgniteCache<Object, Object> cache = grid.cache(DEFAULT_CACHE_NAME);
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cache.localSize(CachePeekMode.ONHEAP) <= 10;
}
}, getTestTimeout());
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCachePartitionedBackupNodeFailureRecoveryTest method testBackUpFail.
/**
* Test stops and restarts backup node.
*
* @throws Exception If failed.
*/
public void testBackUpFail() throws Exception {
final IgniteEx node1 = grid(0);
final IgniteEx node2 = grid(1);
final IgniteEx node3 = grid(2);
awaitPartitionMapExchange();
final IgniteCache<Integer, Integer> cache1 = node1.cache(DEFAULT_CACHE_NAME);
Affinity<Integer> aff = node1.affinity(DEFAULT_CACHE_NAME);
Integer key0 = null;
for (int key = 0; key < 10_000; key++) {
if (aff.isPrimary(node2.cluster().localNode(), key) && aff.isBackup(node3.cluster().localNode(), key)) {
key0 = key;
break;
}
}
assertNotNull(key0);
cache1.put(key0, 0);
final AtomicBoolean finished = new AtomicBoolean();
final ReentrantLock lock = new ReentrantLock();
final AtomicInteger cntr = new AtomicInteger();
final Integer finalKey = key0;
IgniteInternalFuture<Void> primaryFut;
IgniteInternalFuture<Void> backupFut;
try {
primaryFut = runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!finished.get()) {
lock.lock();
try {
cache1.invoke(finalKey, new TestEntryProcessor());
cntr.getAndIncrement();
} finally {
lock.unlock();
}
}
return null;
}
});
backupFut = runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!finished.get()) {
stopGrid(2);
IgniteEx backUp = startGrid(2);
final IgniteCache<Integer, Integer> cache3 = backUp.cache(DEFAULT_CACHE_NAME);
lock.lock();
try {
boolean res = waitForCondition(new PA() {
@Override
public boolean apply() {
Integer actl = cache3.localPeek(finalKey);
Integer exp = cntr.get();
return exp.equals(actl);
}
}, 1000);
assertTrue(res);
} finally {
lock.unlock();
}
}
return null;
}
});
Thread.sleep(30_000);
} finally {
finished.set(true);
}
primaryFut.get();
backupFut.get();
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridCacheRebalancingSyncSelfTest method checkSupplyContextMapIsEmpty.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
protected void checkSupplyContextMapIsEmpty() throws Exception {
for (Ignite g : G.allGrids()) {
for (GridCacheAdapter c : ((IgniteEx) g).context().cache().internalCaches()) {
Object supplier = U.field(c.preloader(), "supplier");
final Map map = U.field(supplier, "scMap");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
synchronized (map) {
return map.isEmpty();
}
}
}, 15_000);
synchronized (map) {
assertTrue("Map is not empty [cache=" + c.name() + ", node=" + g.name() + ", map=" + map + ']', map.isEmpty());
}
}
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class CacheContinuousQueryOrderingEventTest method doOrderingTest.
/**
* @param ccfg Cache configuration.
* @param async Async filter.
* @throws Exception If failed.
*/
protected void doOrderingTest(final CacheConfiguration ccfg, final boolean async) throws Exception {
ignite(0).createCache(ccfg);
List<QueryCursor<?>> qries = new ArrayList<>();
try {
List<BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>>> rcvdEvts = new ArrayList<>(LISTENER_CNT * NODES);
final AtomicInteger qryCntr = new AtomicInteger(0);
final int threadCnt = 20;
for (int idx = 0; idx < NODES; idx++) {
for (int i = 0; i < LISTENER_CNT; i++) {
BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue = new ArrayBlockingQueue<>(ITERATION_CNT * threadCnt);
ContinuousQuery qry = new ContinuousQuery();
if (async) {
qry.setLocalListener(new TestCacheAsyncEventListener(queue, qryCntr));
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheTestRemoteFilterAsync(ccfg.getName())));
} else {
qry.setLocalListener(new TestCacheEventListener(queue, qryCntr));
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheTestRemoteFilter(ccfg.getName())));
}
rcvdEvts.add(queue);
IgniteCache<Object, Object> cache = grid(idx).cache(ccfg.getName());
QueryCursor qryCursor = cache.query(qry);
qries.add(qryCursor);
}
}
IgniteInternalFuture<Long> f = GridTestUtils.runMultiThreadedAsync(new Runnable() {
@Override
public void run() {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < ITERATION_CNT; i++) {
IgniteCache<QueryTestKey, QueryTestValue> cache = grid(rnd.nextInt(NODES)).cache(ccfg.getName());
QueryTestKey key = new QueryTestKey(rnd.nextInt(KEYS));
boolean startTx = cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL && rnd.nextBoolean();
Transaction tx = null;
if (startTx)
tx = cache.unwrap(Ignite.class).transactions().txStart();
try {
if ((cache.get(key) == null) || rnd.nextBoolean()) {
cache.invoke(key, new CacheEntryProcessor<QueryTestKey, QueryTestValue, Object>() {
@Override
public Object process(MutableEntry<QueryTestKey, QueryTestValue> entry, Object... arguments) throws EntryProcessorException {
if (entry.exists())
entry.setValue(new QueryTestValue(entry.getValue().val1 + 1));
else
entry.setValue(new QueryTestValue(0));
return null;
}
});
} else {
QueryTestValue val;
QueryTestValue newVal;
do {
val = cache.get(key);
newVal = val == null ? new QueryTestValue(0) : new QueryTestValue(val.val1 + 1);
} while (!cache.replace(key, val, newVal));
}
} finally {
if (tx != null)
tx.commit();
}
}
}
}, threadCnt, "put-thread");
f.get(15, TimeUnit.SECONDS);
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return qryCntr.get() >= ITERATION_CNT * threadCnt * LISTENER_CNT * NODES;
}
}, 1000L);
for (BlockingQueue<CacheEntryEvent<QueryTestKey, QueryTestValue>> queue : rcvdEvts) checkEvents(queue, ITERATION_CNT * threadCnt);
assertFalse("Ordering invocations of filter broken.", fail);
} finally {
for (QueryCursor<?> qry : qries) qry.close();
ignite(0).destroyCache(ccfg.getName());
}
}
Aggregations