use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridMessagingSelfTest method testAsync.
/**
* @throws Exception If failed.
*/
public void testAsync() throws Exception {
final AtomicInteger msgCnt = new AtomicInteger();
TestTcpDiscoverySpi discoSpi = (TestTcpDiscoverySpi) ignite2.configuration().getDiscoverySpi();
discoSpi.blockCustomEvent();
final String topic = "topic";
IgniteFuture<UUID> starFut = ignite2.message().remoteListenAsync(topic, new P2<UUID, Object>() {
@Override
public boolean apply(UUID nodeId, Object msg) {
System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
msgCnt.incrementAndGet();
return true;
}
});
Assert.assertNotNull(starFut);
U.sleep(500);
Assert.assertFalse(starFut.isDone());
discoSpi.stopBlock();
UUID id = starFut.get();
Assert.assertNotNull(id);
Assert.assertTrue(starFut.isDone());
discoSpi.blockCustomEvent();
message(ignite1.cluster().forRemotes()).send(topic, "msg1");
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return msgCnt.get() > 0;
}
}, 5000);
assertEquals(1, msgCnt.get());
IgniteFuture<?> stopFut = ignite2.message().stopRemoteListenAsync(id);
Assert.assertNotNull(stopFut);
U.sleep(500);
Assert.assertFalse(stopFut.isDone());
discoSpi.stopBlock();
stopFut.get();
Assert.assertTrue(stopFut.isDone());
message(ignite1.cluster().forRemotes()).send(topic, "msg2");
U.sleep(1000);
assertEquals(1, msgCnt.get());
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCacheExpireAndUpdateConsistencyTest method checkEvents.
/**
* @param updates Cache update.
* @param evts Received events.
* @throws Exception If failed.
*/
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private void checkEvents(ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> updates, final ConcurrentMap<TestKey, List<T2<TestValue, TestValue>>> evts) throws Exception {
for (final TestKey key : updates.keySet()) {
final List<T2<TestValue, TestValue>> keyUpdates = updates.get(key);
assert (!F.isEmpty(keyUpdates));
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
if (keyEvts == null)
return false;
synchronized (keyEvts) {
return keyEvts.size() == keyUpdates.size();
}
}
}, 5000);
List<T2<TestValue, TestValue>> keyEvts = evts.get(key);
assertNotNull(keyEvts);
for (int i = 0; i < keyUpdates.size(); i++) {
T2<TestValue, TestValue> update = keyUpdates.get(i);
T2<TestValue, TestValue> evt = keyEvts.get(i);
assertEquals(update.get1(), evt.get1());
assertEquals(update.get2(), evt.get2());
}
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridCacheContinuousQueryMultiNodesFilteringTest method testWithNodeFilter.
/**
* @throws Exception If failed.
*/
public void testWithNodeFilter() throws Exception {
List<QueryCursor> qryCursors = new ArrayList<>();
final int nodesCnt = 3;
startGridsMultiThreaded(nodesCnt);
awaitPartitionMapExchange();
CacheConfiguration ccfg = cacheConfiguration(new NodeFilterByRegexp(".*(0|1)$"));
grid(0).createCache(ccfg);
final AtomicInteger cntr = new AtomicInteger();
final ConcurrentMap<ClusterNode, Set<Integer>> maps = new ConcurrentHashMap<>();
final AtomicBoolean doubleNtfFail = new AtomicBoolean(false);
CacheEntryUpdatedListener<Integer, Integer> lsnr = new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends Integer, ? extends Integer> e : evts) {
cntr.incrementAndGet();
ClusterNode node = ((Ignite) e.getSource().unwrap(Ignite.class)).cluster().localNode();
Set<Integer> set = maps.get(node);
if (set == null) {
set = new ConcurrentSkipListSet<>();
Set<Integer> oldVal = maps.putIfAbsent(node, set);
set = oldVal != null ? oldVal : set;
}
if (!set.add(e.getValue()))
doubleNtfFail.set(false);
}
}
};
for (int i = 0; i < nodesCnt; i++) {
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
Ignite ignite = grid(i);
log.info("Try to start CQ on node: " + ignite.cluster().localNode().id());
qryCursors.add(ignite.cache(ccfg.getName()).query(qry));
log.info("CQ started on node: " + ignite.cluster().localNode().id());
}
client = true;
startGrid(nodesCnt);
awaitPartitionMapExchange();
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
qryCursors.add(grid(nodesCnt).cache(ccfg.getName()).query(qry));
for (int i = 0; i <= nodesCnt; i++) {
for (int key = 0; key < KEYS; key++) {
int val = (i * KEYS) + key;
grid(i).cache(ccfg.getName()).put(val, val);
}
}
assertTrue(GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cntr.get() >= 2 * (nodesCnt + 1) * KEYS;
}
}, 5000L));
assertFalse("Got duplicate", doubleNtfFail.get());
for (int i = 0; i < (nodesCnt + 1) * KEYS; i++) {
for (Map.Entry<ClusterNode, Set<Integer>> e : maps.entrySet()) assertTrue("Lost event on node: " + e.getKey().id() + ", event: " + i, e.getValue().remove(i));
}
for (Map.Entry<ClusterNode, Set<Integer>> e : maps.entrySet()) assertTrue("Unexpected event on node: " + e.getKey(), e.getValue().isEmpty());
assertEquals("Not expected count of CQ", nodesCnt + 1, qryCursors.size());
for (QueryCursor cur : qryCursors) cur.close();
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridCacheContinuousQueryAbstractSelfTest method afterTest.
/** {@inheritDoc} */
@Override
protected void afterTest() throws Exception {
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
for (int i = 0; i < gridCount(); i++) {
if (grid(i).cluster().nodes().size() != gridCount())
return false;
}
return true;
}
}, 3000);
for (int i = 0; i < gridCount(); i++) assertEquals(gridCount(), grid(i).cluster().nodes().size());
for (int i = 0; i < gridCount(); i++) {
for (int j = 0; j < 5; j++) {
try {
IgniteCache<Object, Object> cache = grid(i).cache(DEFAULT_CACHE_NAME);
for (Cache.Entry<Object, Object> entry : cache.localEntries(new CachePeekMode[] { CachePeekMode.ALL })) cache.remove(entry.getKey());
break;
} catch (IgniteException e) {
if (j == 4)
throw new Exception("Failed to clear cache for grid: " + i, e);
U.warn(log, "Failed to clear cache for grid (will retry in 500 ms) [gridIdx=" + i + ", err=" + e.getMessage() + ']');
U.sleep(500);
}
}
}
// Wait for all routines are unregistered
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
for (int i = 0; i < gridCount(); i++) {
GridContinuousProcessor proc = grid(i).context().continuous();
if (((Map) U.field(proc, "rmtInfos")).size() > 0)
return false;
}
return true;
}
}, 3000);
for (int i = 0; i < gridCount(); i++) {
GridContinuousProcessor proc = grid(i).context().continuous();
assertEquals(String.valueOf(i), 1, ((Map) U.field(proc, "locInfos")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "rmtInfos")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "startFuts")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "stopFuts")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "bufCheckThreads")).size());
CacheContinuousQueryManager mgr = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME).context().continuousQueries();
assertEquals(0, ((Map) U.field(mgr, "lsnrs")).size());
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method checkRemovedLatch.
/**
* @param latch Latch.
* @throws Exception If failed.
*/
protected void checkRemovedLatch(final IgniteCountDownLatch latch) throws Exception {
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return latch.removed();
}
}, 5000);
assert latch.removed();
assert latch.count() == 0;
// Test await on removed future.
latch.await();
assert latch.await(10);
assert latch.await(10, SECONDS);
latch.await();
// Test countdown.
assert latch.countDown() == 0;
assert latch.countDown(5) == 0;
latch.countDownAll();
}
Aggregations