use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class GridCacheAbstractFullApiSelfTest method checkGetOutTx.
/**
* @throws Exception If failed.
*/
private void checkGetOutTx(boolean async) throws Exception {
final AtomicInteger lockEvtCnt = new AtomicInteger();
IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
lockEvtCnt.incrementAndGet();
return true;
}
};
try {
IgniteCache<String, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
List<String> keys = primaryKeysForCache(cache, 2);
assertEquals(2, keys.size());
cache.put(keys.get(0), 0);
cache.put(keys.get(1), 1);
grid(0).events().localListen(lsnr, EVT_CACHE_OBJECT_LOCKED, EVT_CACHE_OBJECT_UNLOCKED);
try (Transaction tx = transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
Integer val0;
if (async)
val0 = cache.getAsync(keys.get(0)).get();
else
val0 = cache.get(keys.get(0));
assertEquals(0, val0.intValue());
Map<String, Integer> allOutTx;
if (async)
allOutTx = cache.getAllOutTxAsync(F.asSet(keys.get(1))).get();
else
allOutTx = cache.getAllOutTx(F.asSet(keys.get(1)));
assertEquals(1, allOutTx.size());
assertTrue(allOutTx.containsKey(keys.get(1)));
assertEquals(1, allOutTx.get(keys.get(1)).intValue());
}
assertTrue(GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
info("Lock event count: " + lockEvtCnt.get());
if (atomicityMode() == ATOMIC)
return lockEvtCnt.get() == 0;
if (cacheMode() == PARTITIONED && nearEnabled()) {
if (!grid(0).configuration().isClientMode())
return lockEvtCnt.get() == 4;
}
return lockEvtCnt.get() == 2;
}
}, 15000));
} finally {
grid(0).events().stopLocalListen(lsnr, EVT_CACHE_OBJECT_LOCKED, EVT_CACHE_OBJECT_UNLOCKED);
}
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class IgniteCacheConfigVariationsQueryTest method registerEventListeners.
/**
* Registers event listeners.
* @param expMap Expected read events count.
* @param filterExp Scan query uses filter.
*/
private void registerEventListeners(Map<Object, Object> expMap, final boolean filterExp) {
this.expMap = expMap != null ? expMap : Collections.emptyMap();
Set<ClusterNode> affNodes = new HashSet<>();
if (cacheMode() != REPLICATED) {
Affinity<Object> aff = testedGrid().affinity(cacheName());
for (Object key : this.expMap.keySet()) affNodes.add(aff.mapKeyToNode(key));
}
int execEvtCnt = cacheMode() == REPLICATED || (cacheMode() == PARTITIONED && affNodes.isEmpty()) ? 1 : affNodes.size();
evtMap = new ConcurrentHashMap<>();
readEvtLatch = new CountDownLatch(this.expMap.size());
execEvtLatch = new CountDownLatch(execEvtCnt);
objReadLsnrs = new IgnitePredicate[gridCount()];
qryExecLsnrs = new IgnitePredicate[gridCount()];
for (int i = 0; i < gridCount(); i++) {
IgnitePredicate<Event> pred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assertTrue("Event: " + evt, evt instanceof CacheQueryReadEvent);
CacheQueryReadEvent<Object, Object> qe = (CacheQueryReadEvent<Object, Object>) evt;
assertEquals(SCAN.name(), qe.queryType());
assertEquals(cacheName(), qe.cacheName());
assertNull(qe.className());
assertNull(qe.clause());
assertEquals(filterExp, qe.scanQueryFilter() != null);
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
evtMap.put(qe.key(), qe.value());
assertFalse(readEvtLatch.getCount() == 0);
readEvtLatch.countDown();
return true;
}
};
grid(i).events().localListen(pred, EVT_CACHE_QUERY_OBJECT_READ);
objReadLsnrs[i] = pred;
IgnitePredicate<Event> execPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assertTrue("Event: " + evt, evt instanceof CacheQueryExecutedEvent);
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(SCAN.name(), qe.queryType());
assertEquals(cacheName(), qe.cacheName());
assertNull(qe.className());
assertNull(qe.clause());
assertEquals(filterExp, qe.scanQueryFilter() != null);
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
assertFalse("Too many events.", execEvtLatch.getCount() == 0);
execEvtLatch.countDown();
return true;
}
};
grid(i).events().localListen(execPred, EVT_CACHE_QUERY_EXECUTED);
qryExecLsnrs[i] = execPred;
}
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method testTextQueryEvents.
/**
* @throws Exception If failed.
*/
public void testTextQueryEvents() throws Exception {
final Map<UUID, Person> map = new ConcurrentHashMap8<>();
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount());
final IgniteCache<UUID, Person> cache = jcache(UUID.class, Person.class);
IgnitePredicate[] objReadLsnrs = new IgnitePredicate[gridCount()];
IgnitePredicate[] qryExecLsnrs = new IgnitePredicate[gridCount()];
for (int i = 0; i < gridCount(); i++) {
IgnitePredicate<Event> objReadPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryReadEvent;
CacheQueryReadEvent<UUID, Person> qe = (CacheQueryReadEvent<UUID, Person>) evt;
assertEquals(FULL_TEXT.name(), qe.queryType());
assertEquals(cache.getName(), qe.cacheName());
assertEquals("Person", qe.className());
assertEquals("White", qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
map.put(qe.key(), qe.value());
latch.countDown();
return true;
}
};
grid(i).events().localListen(objReadPred, EVT_CACHE_QUERY_OBJECT_READ);
objReadLsnrs[i] = objReadPred;
IgnitePredicate<Event> qryExecPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryExecutedEvent;
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(FULL_TEXT.name(), qe.queryType());
assertEquals(cache.getName(), qe.cacheName());
assertEquals("Person", qe.className());
assertEquals("White", qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
execLatch.countDown();
return true;
}
};
grid(i).events().localListen(qryExecPred, EVT_CACHE_QUERY_EXECUTED);
qryExecLsnrs[i] = qryExecPred;
}
try {
UUID k1 = UUID.randomUUID();
UUID k2 = UUID.randomUUID();
UUID k3 = UUID.randomUUID();
cache.put(k1, new Person("Bob White", 1000));
cache.put(k2, new Person("Tom White", 1000));
cache.put(k3, new Person("Mike Green", 1000));
QueryCursor<Cache.Entry<UUID, Person>> q = cache.query(new TextQuery<UUID, Person>(Person.class, "White"));
q.getAll();
assert latch.await(1000, MILLISECONDS);
assert execLatch.await(1000, MILLISECONDS);
assertEquals(2, map.size());
assertEquals("Bob White", map.get(k1).name());
assertEquals("Tom White", map.get(k2).name());
} finally {
for (int i = 0; i < gridCount(); i++) {
grid(i).events().stopLocalListen(objReadLsnrs[i]);
grid(i).events().stopLocalListen(qryExecLsnrs[i]);
}
}
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class GridEventStorageSelfTest method testGridInternalEvents.
/**
* @throws Exception In case of error.
*/
public void testGridInternalEvents() throws Exception {
IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
checkGridInternalEvent(evt);
return true;
}
};
ignite1.events().localListen(lsnr, EVTS_TASK_EXECUTION);
ignite1.events().localListen(lsnr, EVTS_JOB_EXECUTION);
ignite2.events().localListen(lsnr, EVTS_TASK_EXECUTION);
ignite2.events().localListen(lsnr, EVTS_JOB_EXECUTION);
executeGridInternalTask(ignite1);
Collection<Event> evts1 = ignite1.events().localQuery(F.<Event>alwaysTrue());
Collection<Event> evts2 = ignite2.events().localQuery(F.<Event>alwaysTrue());
assert evts1 != null;
assert evts2 != null;
for (Event evt : evts1) checkGridInternalEvent(evt);
for (Event evt : evts2) checkGridInternalEvent(evt);
assert ignite1.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION);
assert ignite1.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION);
assert ignite2.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION);
assert ignite2.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION);
}
use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class IgniteTopologyPrintFormatSelfTest method doServerLogTest.
/**
* @param log Logger.
* @throws Exception If failed.
*/
private void doServerLogTest(MockLogger log) throws Exception {
try {
Ignite server = startGrid("server");
setLogger(log, server);
Ignite server1 = startGrid("server1");
waitForDiscovery(server, server1);
} finally {
stopAllGrids();
}
assertTrue(F.forAny(log.logs(), new IgnitePredicate<String>() {
@Override
public boolean apply(String s) {
return s.contains("Topology snapshot [ver=2, servers=2, clients=0,") || (s.contains(">>> Number of server nodes: 2") && s.contains(">>> Number of client nodes: 0"));
}
}));
}
Aggregations