use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class CacheContinuousQueryFailoverAbstractSelfTest method checkEvents.
/**
* @param logAll If {@code true} logs all unexpected values.
* @param expEvts Expected values.
* @param lsnr Listener.
* @return Check status.
*/
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private boolean checkEvents(boolean logAll, Map<Integer, List<T2<Integer, Integer>>> expEvts, CacheEventListener2 lsnr) {
assertTrue(!expEvts.isEmpty());
boolean pass = true;
for (Map.Entry<Integer, List<T2<Integer, Integer>>> e : expEvts.entrySet()) {
Integer key = e.getKey();
List<T2<Integer, Integer>> exp = e.getValue();
List<CacheEntryEvent<?, ?>> rcvdEvts = lsnr.evts.get(key);
if (rcvdEvts == null) {
pass = false;
log.info("No events for key [key=" + key + ", exp=" + e.getValue() + ']');
if (!logAll)
return false;
} else {
synchronized (rcvdEvts) {
if (rcvdEvts.size() != exp.size()) {
pass = false;
log.info("Missed or extra events for key [key=" + key + ", exp=" + e.getValue() + ", rcvd=" + rcvdEvts + ']');
if (!logAll)
return false;
}
int cnt = Math.min(rcvdEvts.size(), exp.size());
for (int i = 0; i < cnt; i++) {
T2<Integer, Integer> expEvt = exp.get(i);
CacheEntryEvent<?, ?> rcvdEvt = rcvdEvts.get(i);
if (pass) {
assertEquals(key, rcvdEvt.getKey());
assertEquals(expEvt.get1(), rcvdEvt.getValue());
} else {
if (!key.equals(rcvdEvt.getKey()) || !expEvt.get1().equals(rcvdEvt.getValue()))
log.warning("Missed events. [key=" + key + ", actKey=" + rcvdEvt.getKey() + ", expVal=" + expEvt.get1() + ", actVal=" + rcvdEvt.getValue() + "]");
}
}
if (!pass) {
for (int i = cnt; i < exp.size(); i++) {
T2<Integer, Integer> val = exp.get(i);
log.warning("Missed events. [key=" + key + ", expVal=" + val.get1() + ", prevVal=" + val.get2() + "]");
}
}
}
}
}
if (pass) {
expEvts.clear();
lsnr.evts.clear();
}
return pass;
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class IgfsServerManagerIpcEndpointRegistrationAbstractSelfTest method checkRegisteredIpcEndpoints.
/**
* Counts all registered IPC endpoints.
*
* @return Tuple2 where (tcp endpoints count, shmem endpoints count).
* @throws Exception If failed.
*/
protected T2<Integer, Integer> checkRegisteredIpcEndpoints() throws Exception {
GridKernalContext ctx = ((IgniteKernal) grid()).context();
int tcp = 0;
int shmem = 0;
for (GridPortRecord record : ctx.ports().records()) {
if (record.clazz() == IpcSharedMemoryServerEndpoint.class)
shmem++;
else if (record.clazz() == IpcServerTcpEndpoint.class)
tcp++;
}
return new T2<>(tcp, shmem);
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class CacheContinuousQueryFailoverAbstractSelfTest method testRemoteFilter.
/**
* @throws Exception If failed.
*/
public void testRemoteFilter() throws Exception {
this.backups = 2;
final int SRV_NODES = 4;
startGridsMultiThreaded(SRV_NODES);
client = true;
Ignite qryClient = startGrid(SRV_NODES);
client = false;
IgniteCache<Object, Object> qryClientCache = qryClient.cache(DEFAULT_CACHE_NAME);
if (cacheMode() != REPLICATED)
assertEquals(backups, qryClientCache.getConfiguration(CacheConfiguration.class).getBackups());
Affinity<Object> aff = qryClient.affinity(DEFAULT_CACHE_NAME);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
final CacheEventListener3 lsnr = asyncCallback() ? new CacheEventAsyncListener3() : new CacheEventListener3();
qry.setLocalListener(lsnr);
qry.setRemoteFilter(lsnr);
int PARTS = 10;
QueryCursor<?> cur = qryClientCache.query(qry);
Map<Object, T2<Object, Object>> updates = new HashMap<>();
final List<T3<Object, Object, Object>> expEvts = new ArrayList<>();
for (int i = 0; i < (atomicityMode() == CacheAtomicityMode.ATOMIC ? SRV_NODES - 1 : SRV_NODES - 2); i++) {
log.info("Stop iteration: " + i);
TestCommunicationSpi spi = (TestCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
Ignite ignite = ignite(i);
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
List<Integer> keys = testKeys(cache, PARTS);
boolean first = true;
boolean filtered = false;
for (Integer key : keys) {
log.info("Put [node=" + ignite.name() + ", key=" + key + ", part=" + aff.partition(key) + ", filtered=" + filtered + ']');
T2<Object, Object> t = updates.get(key);
Integer val = filtered ? (key % 2 == 0 ? key + 1 : key) : key * 2;
if (t == null) {
updates.put(key, new T2<>((Object) val, null));
if (!filtered)
expEvts.add(new T3<>((Object) key, (Object) val, null));
} else {
updates.put(key, new T2<>((Object) val, (Object) key));
if (!filtered)
expEvts.add(new T3<>((Object) key, (Object) val, (Object) key));
}
cache.put(key, val);
if (first) {
spi.skipMsg = true;
first = false;
}
filtered = !filtered;
}
stopGrid(i);
boolean check = GridTestUtils.waitForCondition(new PAX() {
@Override
public boolean applyx() throws IgniteCheckedException {
return expEvts.size() == lsnr.keys.size();
}
}, 5000L);
if (!check) {
Set<Integer> keys0 = new HashSet<>(keys);
keys0.removeAll(lsnr.keys);
log.info("Missed events for keys: " + keys0);
fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + keys0.size() + ']');
}
checkEvents(expEvts, lsnr, false);
}
cur.close();
}
Aggregations