use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class CacheContinuousQueryLostPartitionTest method beforeTest.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
super.beforeTest();
startGridsMultiThreaded(2);
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return grid(0).cluster().nodes().size() == 2;
}
}, 10000L);
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class CacheContinuousQueryLostPartitionTest method testEvent.
/**
* @param cacheName Cache name.
* @throws Exception If failed.
*/
public void testEvent(String cacheName, boolean client) throws Exception {
IgniteCache<Integer, String> cache1 = grid(0).getOrCreateCache(cacheName);
final AllEventListener<Integer, String> lsnr1 = registerCacheListener(cache1);
IgniteCache<Integer, String> cache2 = grid(1).getOrCreateCache(cacheName);
Integer key = primaryKey(cache1);
cache1.put(key, "1");
// Note the issue is only reproducible if the second registration is done right
// here, after the first put() above.
AllEventListener<Integer, String> lsnr20;
if (client) {
IgniteCache<Integer, String> clnCache = startGrid(3).getOrCreateCache(cacheName);
lsnr20 = registerCacheListener(clnCache);
} else
lsnr20 = registerCacheListener(cache2);
final AllEventListener<Integer, String> lsnr2 = lsnr20;
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return lsnr1.createdCnt.get() == 1;
}
}, 2000L) : "Unexpected number of events: " + lsnr1.createdCnt.get();
// Sanity check.
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return lsnr2.createdCnt.get() == 0;
}
}, 2000L) : "Expected no create events, but got: " + lsnr2.createdCnt.get();
// node2 now becomes the primary for the key.
stopGrid(0);
final int prevSize = grid(1).cluster().nodes().size();
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return prevSize - 1 == grid(1).cluster().nodes().size();
}
}, 5000L);
cache2.put(key, "2");
// Sanity check.
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return lsnr1.createdCnt.get() == 1;
}
}, 2000L) : "Expected no change here, but got: " + lsnr1.createdCnt.get();
// Sanity check.
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return lsnr2.updatedCnt.get() == 0;
}
}, 2000L) : "Expected no update events, but got: " + lsnr2.updatedCnt.get();
System.out.println(">>>>> " + lsnr2.createdCnt.get());
// This assertion fails: 0 events get delivered.
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return lsnr2.createdCnt.get() == 1;
}
}, 2000L) : "Expected a single event due to '2', but got: " + lsnr2.createdCnt.get();
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridMessageListenSelfTest method testNullTopicWithDeployment.
/**
* @throws Exception If failed.
*/
public void testNullTopicWithDeployment() throws Exception {
Class<?> cls = getExternalClassLoader().loadClass(LSNR_CLS_NAME);
grid(0).message().remoteListen(null, (IgniteBiPredicate<UUID, Object>) cls.newInstance());
send();
boolean s = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return checkDeployedListeners(GRID_CNT);
}
}, 2000);
assertTrue(s);
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridMessageListenSelfTest method testNonNullTopicWithDeployment.
/**
* @throws Exception If failed.
*/
public void testNonNullTopicWithDeployment() throws Exception {
ClassLoader ldr = getExternalClassLoader();
Class<?> topicCls = ldr.loadClass(TOPIC_CLS_NAME);
Class<?> lsnrCls = ldr.loadClass(LSNR_CLS_NAME);
Object topic = topicCls.newInstance();
grid(0).message().remoteListen(topic, (IgniteBiPredicate<UUID, Object>) lsnrCls.newInstance());
send(topic);
boolean s = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return checkDeployedListeners(GRID_CNT);
}
}, 2000);
assertTrue(s);
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridCacheContinuousQueryAbstractSelfTest method testRestartQuery.
/**
* @throws Exception If failed.
*/
public void testRestartQuery() throws Exception {
if (cacheMode() == LOCAL)
return;
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
final int parts = grid(0).affinity(DEFAULT_CACHE_NAME).partitions();
final int keyCnt = parts * 2;
for (int i = 0; i < parts / 2; i++) cache.put(i, i);
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
final AtomicInteger cntr = new AtomicInteger(0);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
for (CacheEntryEvent<? extends Integer, ? extends Integer> ignore : evts) cntr.incrementAndGet();
}
});
QueryCursor<Cache.Entry<Integer, Integer>> qryCur = cache.query(qry);
for (int key = 0; key < keyCnt; key++) cache.put(key, key);
try {
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cntr.get() == keyCnt;
}
}, 2000L);
} finally {
qryCur.close();
}
} else {
for (int key = 0; key < keyCnt; key++) cache.put(key, key);
}
}
}
Aggregations