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 CacheDeferredDeleteQueueTest method testQueue.
/**
* @param atomicityMode Cache atomicity mode.
* @param nearCache {@code True} if need create near cache.
*
* @throws Exception If failed.
*/
private void testQueue(CacheAtomicityMode atomicityMode, boolean nearCache) throws Exception {
CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(PARTITIONED);
ccfg.setAtomicityMode(atomicityMode);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setBackups(1);
if (nearCache)
ccfg.setNearConfiguration(new NearCacheConfiguration<Integer, Integer>());
IgniteCache<Integer, Integer> cache = ignite(0).createCache(ccfg);
try {
final int KEYS = cache.getConfiguration(CacheConfiguration.class).getAffinity().partitions() * 3;
for (int i = 0; i < KEYS; i++) cache.put(i, i);
for (int i = 0; i < KEYS; i++) cache.remove(i);
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int i = 0; i < NODES; i++) {
final GridDhtPartitionTopology top = ((IgniteKernal) ignite(i)).context().cache().cache(DEFAULT_CACHE_NAME).context().topology();
for (GridDhtLocalPartition p : top.currentLocalPartitions()) {
Collection<Object> rmvQueue = GridTestUtils.getFieldValue(p, "rmvQueue");
if (!rmvQueue.isEmpty() || p.dataStore().fullSize() != 0)
return false;
}
}
return true;
}
}, 5000);
assertTrue("Failed to wait for rmvQueue cleanup.", wait);
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridNonHistoryMetricsSelfTest method testSingleTaskMetrics.
/**
* @throws Exception If failed.
*/
public void testSingleTaskMetrics() throws Exception {
final Ignite ignite = grid();
ignite.compute().execute(new TestTask(), "testArg");
// Let metrics update twice.
final CountDownLatch latch = new CountDownLatch(2);
ignite.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt.type() == EVT_NODE_METRICS_UPDATED;
latch.countDown();
return true;
}
}, EVT_NODE_METRICS_UPDATED);
latch.await();
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
ClusterMetrics metrics = ignite.cluster().localNode().metrics();
return metrics.getTotalExecutedJobs() == 5;
}
}, 5000);
ClusterMetrics metrics = ignite.cluster().localNode().metrics();
info("Node metrics: " + metrics);
assertEquals(5, metrics.getTotalExecutedJobs());
assertEquals(0, metrics.getTotalCancelledJobs());
assertEquals(0, metrics.getTotalRejectedJobs());
}
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 ClusterStateAbstractTest method testActivationFromClient.
/**
* @throws Exception if failed.
*/
public void testActivationFromClient() throws Exception {
forbidden.add(GridDhtPartitionSupplyMessage.class);
forbidden.add(GridDhtPartitionDemandMessage.class);
activeOnStart = false;
startGrids(GRID_CNT);
client = true;
startGrid(GRID_CNT);
checkInactive(GRID_CNT + 1);
Ignite cl = grid(GRID_CNT);
forbidden.clear();
cl.active(true);
awaitPartitionMapExchange();
IgniteCache<Object, Object> cache = cl.cache(CACHE_NAME);
for (int k = 0; k < ENTRY_CNT; k++) cache.put(k, k);
for (int g = 0; g < GRID_CNT + 1; g++) {
// Tests that state changes are propagated to existing and new nodes.
assertTrue(grid(g).active());
IgniteCache<Object, Object> cache0 = grid(g).cache(CACHE_NAME);
for (int k = 0; k < ENTRY_CNT; k++) assertEquals(k, cache0.get(k));
}
cl.active(false);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int g = 0; g < GRID_CNT + 1; g++) {
if (grid(g).active())
return false;
}
return true;
}
}, 5000);
checkInactive(GRID_CNT + 1);
}
Aggregations