use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class CacheContinuousQueryRandomOperationsTest method batchOperation.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void batchOperation(CacheConfiguration ccfg) throws Exception {
IgniteCache<QueryTestKey, QueryTestValue> cache = grid(getClientIndex()).createCache(ccfg);
try {
ContinuousQuery<QueryTestKey, QueryTestValue> qry = new ContinuousQuery<>();
final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts = new CopyOnWriteArrayList<>();
if (noOpFilterFactory() != null)
qry.setRemoteFilterFactory(noOpFilterFactory());
qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> events) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events) evts.add(e);
}
});
Map<QueryTestKey, QueryTestValue> map = new TreeMap<>();
for (int i = 0; i < KEYS; i++) map.put(new QueryTestKey(i), new QueryTestValue(i));
try (QueryCursor qryCur = cache.query(qry)) {
for (int i = 0; i < ITERATION_CNT / 2; i++) {
log.info("Start iteration: " + i);
// Not events.
cache.removeAll(map.keySet());
cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
// Get events.
cache.putAll(map);
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return evts.size() == KEYS;
}
}, 5_000);
checkEvents(evts, CREATED);
evts.clear();
// Not events.
cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
U.sleep(100);
assertEquals(0, evts.size());
// Get events.
cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
// Not events.
cache.removeAll(map.keySet());
cache.removeAll(map.keySet());
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return evts.size() == KEYS;
}
}, 5_000);
checkEvents(evts, REMOVED);
evts.clear();
log.info("Finish iteration: " + i);
}
}
} finally {
grid(getClientIndex()).destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class CacheContinuousQueryRandomOperationsTest method singleOperation.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void singleOperation(CacheConfiguration ccfg) throws Exception {
IgniteCache<QueryTestKey, QueryTestValue> cache = grid(getClientIndex()).createCache(ccfg);
try {
ContinuousQuery<QueryTestKey, QueryTestValue> qry = new ContinuousQuery<>();
final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts = new CopyOnWriteArrayList<>();
if (noOpFilterFactory() != null)
qry.setRemoteFilterFactory(noOpFilterFactory());
qry.setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> events) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events) evts.add(e);
}
});
QueryTestKey key = new QueryTestKey(1);
try (QueryCursor qryCur = cache.query(qry)) {
for (int i = 0; i < ITERATION_CNT; i++) {
log.info("Start iteration: " + i);
// Not events.
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
// Get events.
cache.put(key, new QueryTestValue(1));
cache.remove(key);
// Not events.
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
cache.remove(key);
// Get events.
cache.put(key, new QueryTestValue(2));
// Not events.
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
// Get events.
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
// Not events.
cache.remove(key);
// Get events.
cache.put(key, new QueryTestValue(3));
cache.put(key, new QueryTestValue(4));
// Not events.
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
cache.putIfAbsent(key, new QueryTestValue(5));
cache.putIfAbsent(key, new QueryTestValue(5));
cache.putIfAbsent(key, new QueryTestValue(5));
cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
cache.remove(key, new QueryTestValue(5));
// Get events.
cache.remove(key, new QueryTestValue(4));
cache.putIfAbsent(key, new QueryTestValue(5));
// Not events.
cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
// Get events.
cache.replace(key, new QueryTestValue(5), new QueryTestValue(6));
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return evts.size() == 9;
}
}, 5_000);
checkSingleEvent(evts.get(0), CREATED, new QueryTestValue(1), null);
checkSingleEvent(evts.get(1), REMOVED, null, new QueryTestValue(1));
checkSingleEvent(evts.get(2), CREATED, new QueryTestValue(2), null);
checkSingleEvent(evts.get(3), REMOVED, null, new QueryTestValue(2));
checkSingleEvent(evts.get(4), CREATED, new QueryTestValue(3), null);
checkSingleEvent(evts.get(5), EventType.UPDATED, new QueryTestValue(4), new QueryTestValue(3));
checkSingleEvent(evts.get(6), REMOVED, null, new QueryTestValue(4));
checkSingleEvent(evts.get(7), CREATED, new QueryTestValue(5), null);
checkSingleEvent(evts.get(8), EventType.UPDATED, new QueryTestValue(6), new QueryTestValue(5));
evts.clear();
cache.remove(key);
cache.remove(key);
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return evts.size() == 1;
}
}, 5_000);
evts.clear();
log.info("Finish iteration: " + i);
}
}
} finally {
grid(getClientIndex()).destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridTcpCommunicationSpiMultithreadedSelfTest method afterTest.
/**
* @throws Exception If failed.
*/
@Override
protected void afterTest() throws Exception {
super.afterTest();
for (MessageListener lsnr : lsnrs.values()) {
lsnr.rcvdMsgs.clear();
lsnr.rmtMsgCnt.set(0);
}
for (CommunicationSpi spi : spis.values()) {
final ConcurrentMap<UUID, GridCommunicationClient[]> clients = U.field(spi, "clients");
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
for (GridCommunicationClient[] clients0 : clients.values()) {
for (GridCommunicationClient client : clients0) {
if (client != null)
return false;
}
}
return true;
}
}, getTestTimeout()) : "Clients: " + clients;
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridServiceProcessorProxySelfTest method testLocalProxyInvocation.
/**
* @throws Exception If failed.
*/
public void testLocalProxyInvocation() throws Exception {
final String name = "testLocalProxyInvocation";
final Ignite ignite = grid(0);
ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>());
for (int i = 0; i < nodeCount(); i++) {
final int idx = i;
final AtomicReference<MapService<Integer, String>> ref = new AtomicReference<>();
//wait because after deployNodeSingleton we don't have guarantees what service was deploy.
boolean wait = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
MapService<Integer, String> svc = grid(idx).services().serviceProxy(name, MapService.class, false);
ref.set(svc);
return svc instanceof Service;
}
}, 2000);
// Make sure service is a local instance.
assertTrue("Invalid service instance [srv=" + ref.get() + ", node=" + i + ']', wait);
ref.get().put(i, Integer.toString(i));
}
MapService<Integer, String> map = ignite.services().serviceProxy(name, MapService.class, false);
for (int i = 0; i < nodeCount(); i++) assertEquals(1, map.size());
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteServiceDynamicCachesSelfTest method testDeployCalledAfterCacheStart.
/**
* @throws Exception If failed.
*/
public void testDeployCalledAfterCacheStart() throws Exception {
String cacheName = "cache";
CacheConfiguration ccfg = new CacheConfiguration(cacheName);
ccfg.setBackups(1);
Ignite ig = ignite(0);
ig.createCache(ccfg);
try {
final IgniteServices svcs = ig.services();
final String svcName = "myService";
svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, primaryKey(ig.cache(cacheName)));
boolean res = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return svcs.service(svcName) != null;
}
}, 10 * 1000);
assertTrue("Service was not deployed", res);
ig.destroyCache(cacheName);
res = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return svcs.service(svcName) == null;
}
}, 10 * 1000);
assertTrue("Service was not undeployed", res);
} finally {
ig.services().cancelAll();
ig.destroyCache(cacheName);
}
}
Aggregations