use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheStoreUsageMultinodeAbstractTest method testStoreUpdate.
/**
* @param cache Cache.
* @param key Key.
* @param tc Transaction concurrency mode.
* @throws Exception If failed.
*/
protected void testStoreUpdate(IgniteCache<Object, Object> cache, Object key, @Nullable TransactionConcurrency tc) throws Exception {
boolean storeOnPrimary = atomicityMode() == ATOMIC || locStore || writeBehind;
assertTrue(writeMap.isEmpty());
Ignite ignite = cache.unwrap(Ignite.class);
Affinity<Object> obj = ignite.affinity(cache.getName());
ClusterNode node = obj.mapKeyToNode(key);
assertNotNull(node);
String expNode = storeOnPrimary ? (String) node.attribute(ATTR_IGNITE_INSTANCE_NAME) : ignite.name();
assertNotNull(expNode);
log.info("Put [node=" + ignite.name() + ", key=" + key + ", primary=" + node.attribute(ATTR_IGNITE_INSTANCE_NAME) + ", tx=" + tc + ", nearCache=" + (cache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null) + ", storeOnPrimary=" + storeOnPrimary + ']');
Transaction tx = tc != null ? ignite.transactions().txStart(tc, REPEATABLE_READ) : null;
try {
cache.put(key, key);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return writeMap.size() > 0;
}
}, 1000);
assertTrue("Store is not updated", wait);
assertEquals("Write on wrong node: " + writeMap, locStore ? 2 : 1, writeMap.size());
if (!locStore)
assertEquals(expNode, writeMap.keySet().iterator().next());
writeMap.clear();
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridCacheP2PUndeploySelfTest method checkP2PUndeploy.
/**
* @param cacheName Cache name.
* @throws Exception If failed.
*/
private void checkP2PUndeploy(final String cacheName) throws Exception {
assert !F.isEmpty(cacheName);
ClassLoader ldr = getExternalClassLoader();
Class valCls = ldr.loadClass(TEST_VALUE);
try {
Ignite ignite1 = startGrid(1);
final IgniteKernal grid2 = (IgniteKernal) startGrid(2);
IgniteCache<Integer, Object> cache1 = ignite1.cache(cacheName);
IgniteCache<Integer, Object> cache2 = grid2.cache(cacheName);
Object v1 = valCls.newInstance();
cache1.put(1, v1);
cache1.put(2, valCls.newInstance());
cache1.put(3, valCls.newInstance());
cache1.put(4, valCls.newInstance());
info("Stored value in cache1 [v=" + v1 + ", ldr=" + v1.getClass().getClassLoader() + ']');
Object v2 = cache2.get(1);
assert v2 != null;
info("Read value from cache2 [v=" + v2 + ", ldr=" + v2.getClass().getClassLoader() + ']');
assert v2 != null;
assert v2.toString().equals(v1.toString());
assert !v2.getClass().getClassLoader().equals(getClass().getClassLoader());
assert v2.getClass().getClassLoader().getClass().getName().contains("GridDeploymentClassLoader");
cache2.localEvict(ImmutableSet.of(2, 3, 4));
//Wait until entries stored to disk.
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return size(cacheName, grid2) > 0;
} catch (IgniteCheckedException e) {
throw new AssertionError(e);
}
}
}, 5000);
stopGrid(1);
assert waitCacheEmpty(cache2, 10000);
for (int i = 0; i < 3; i++) {
long swapSize = size(cacheName, grid2);
if (swapSize > 0) {
if (i < 2) {
U.warn(log, "Swap size check failed (will retry in 1000 ms): " + swapSize);
U.sleep(1000);
continue;
}
fail("Swap size check failed: " + swapSize);
} else if (swapSize == 0)
break;
else
assert false : "Negative swap size: " + swapSize;
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridCacheSetAbstractSelfTest method testCreateRemove.
/**
* @param collocated Collocation flag.
* @throws Exception If failed.
*/
private void testCreateRemove(boolean collocated) throws Exception {
for (int i = 0; i < gridCount(); i++) assertNull(grid(i).set(SET_NAME, null));
CollectionConfiguration colCfg0 = config(collocated);
IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg0);
assertNotNull(set0);
for (int i = 0; i < gridCount(); i++) {
CollectionConfiguration colCfg = config(collocated);
IgniteSet<Integer> set = grid(i).set(SET_NAME, colCfg);
assertNotNull(set);
assertTrue(set.isEmpty());
assertEquals(0, set.size());
assertEquals(SET_NAME, set.name());
if (collectionCacheMode() == PARTITIONED)
assertEquals(collocated, set.collocated());
}
set0.close();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
for (int i = 0; i < gridCount(); i++) {
if (grid(i).set(SET_NAME, null) != null)
return false;
}
return true;
} catch (Exception e) {
fail("Unexpected exception: " + e);
return true;
}
}
}, 1000);
for (int i = 0; i < gridCount(); i++) assertNull(grid(i).set(SET_NAME, null));
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheLockReleaseNodeLeaveTest method testTxLockRelease2.
/**
* @throws Exception If failed.
*/
public void testTxLockRelease2() throws Exception {
final Ignite ignite0 = startGrid(0);
Ignite ignite1 = startGrid(1);
IgniteCache cache = ignite1.cache(DEFAULT_CACHE_NAME);
ignite1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
cache.get(1);
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(2);
return null;
}
});
final AffinityTopologyVersion topVer = new AffinityTopologyVersion(2, 0);
// Wait when affinity change exchange start.
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
AffinityTopologyVersion topVer0 = ((IgniteKernal) ignite0).context().cache().context().exchange().topologyVersion();
return topVer.compareTo(topVer0) < 0;
}
}, 10_000);
assertTrue(wait);
assertFalse(fut.isDone());
ignite1.close();
fut.get(10_000);
Ignite ignite2 = ignite(2);
cache = ignite2.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = ignite2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.get(1);
tx.commit();
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class CacheLockReleaseNodeLeaveTest method testLockRelease2.
/**
* @throws Exception If failed.
*/
public void testLockRelease2() throws Exception {
final Ignite ignite0 = startGrid(0);
Ignite ignite1 = startGrid(1);
Lock lock = ignite1.cache(DEFAULT_CACHE_NAME).lock("key");
lock.lock();
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(2);
return null;
}
});
final AffinityTopologyVersion topVer = new AffinityTopologyVersion(2, 0);
// Wait when affinity change exchange start.
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
AffinityTopologyVersion topVer0 = ((IgniteKernal) ignite0).context().cache().context().exchange().topologyVersion();
return topVer.compareTo(topVer0) < 0;
}
}, 10_000);
assertTrue(wait);
assertFalse(fut.isDone());
ignite1.close();
fut.get(10_000);
Ignite ignite2 = ignite(2);
lock = ignite2.cache(DEFAULT_CACHE_NAME).lock("key");
lock.lock();
lock.unlock();
}
Aggregations