use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class CacheContinuousQueryFilterDeploymentFailedTest method testContinuousQueryFilterDeploymentFailed.
/**
* Tests continuous query behavior in case of filter deployment obtaining failure.
*
* @throws Exception If failed.
*/
@Test
@SuppressWarnings({ "ThrowableNotThrown" })
public void testContinuousQueryFilterDeploymentFailed() throws Exception {
startGrids(NODES_CNT - 1);
IgniteEx cli = startClientGrid(NODES_CNT - 1);
IgniteCache<Integer, Integer> cache = cli.createCache(DEFAULT_CACHE_NAME);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
Class<Factory<CacheEntryEventFilter<Integer, Integer>>> rmtFilterFactoryCls = (Class<Factory<CacheEntryEventFilter<Integer, Integer>>>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");
qry.setRemoteFilterFactory(rmtFilterFactoryCls.newInstance());
spi(grid(1)).blockMessages((node, msg) -> msg instanceof GridDeploymentRequest);
assertThrowsWithCause(() -> cache.query(qry), CacheException.class);
assertTrue(stopRoutineLatch.await(getTestTimeout(), MILLISECONDS));
assertTrue(allGrids().stream().allMatch(g -> ((IgniteEx) g).context().systemView().view(CQ_SYS_VIEW).size() == 0));
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class CacheContinuousQueryDeploymentToClientTest method testDeploymentToNewClient.
/**
* Test starts 1 server node and 1 client node. The client node deploys
* CQ for the cache {@link #CACHE_NAME}. After that another client node is started.
* Expected that CQ won't be deployed to the new client, since the client doesn't
* store any data.
*
* @throws Exception If failed.
*/
@Test
public void testDeploymentToNewClient() throws Exception {
startGrid(0);
IgniteEx client1 = startClientGrid(1);
IgniteCache<Integer, String> cache = client1.cache(CACHE_NAME);
AbstractContinuousQuery<Integer, String> qry = new ContinuousQuery<Integer, String>().setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory((Factory<CacheEntryEventFilter<Integer, String>>) () -> evt -> true);
cache.query(qry);
IgniteEx client2 = startClientGrid(2);
GridContinuousProcessor proc = client2.context().continuous();
assertEquals(0, ((Map<?, ?>) U.field(proc, "locInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "rmtInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "startFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "stopFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "bufCheckThreads")).size());
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class CacheContinuousQueryDeploymentToClientTest method testDeploymentToExistingClient.
/**
* Test starts 1 server node and 2 client nodes. The first client node deploys
* CQ for the cache {@link #CACHE_NAME}.
* Expected that CQ won't be deployed to the second client, since the client doesn't
* store any data.
*
* @throws Exception If failed.
*/
@Test
public void testDeploymentToExistingClient() throws Exception {
startGrid(0);
IgniteEx client1 = startClientGrid(1);
IgniteCache<Integer, String> cache = client1.cache(CACHE_NAME);
IgniteEx client2 = startClientGrid(2);
AbstractContinuousQuery<Integer, String> qry = new ContinuousQuery<Integer, String>().setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory((Factory<CacheEntryEventFilter<Integer, String>>) () -> evt -> true);
cache.query(qry);
GridContinuousProcessor proc = client2.context().continuous();
assertEquals(0, ((Map<?, ?>) U.field(proc, "locInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "rmtInfos")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "startFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "stopFuts")).size());
assertEquals(0, ((Map<?, ?>) U.field(proc, "bufCheckThreads")).size());
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class CacheContinuousQueryOperationFromCallbackTest method doTest.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
@SuppressWarnings({ "TypeMayBeWeakened", "unchecked", "TooBroadScope" })
protected void doTest(final CacheConfiguration ccfg, boolean fromLsnr) throws Exception {
ignite(0).createCache(ccfg);
List<QueryCursor<?>> qries = new ArrayList<>();
assertEquals(0, filterCbCntr.get());
try {
List<Set<T2<QueryTestKey, QueryTestValue>>> rcvdEvts = new ArrayList<>(NODES);
List<Set<T2<QueryTestKey, QueryTestValue>>> evtsFromCallbacks = new ArrayList<>(NODES);
final AtomicInteger qryCntr = new AtomicInteger(0);
final AtomicInteger cbCntr = new AtomicInteger(0);
final int threadCnt = SYSTEM_POOL_SIZE * 2;
for (int idx = 0; idx < NODES; idx++) {
Set<T2<QueryTestKey, QueryTestValue>> evts = Collections.newSetFromMap(new ConcurrentHashMap<T2<QueryTestKey, QueryTestValue>, Boolean>());
Set<T2<QueryTestKey, QueryTestValue>> evtsFromCb = Collections.newSetFromMap(new ConcurrentHashMap<T2<QueryTestKey, QueryTestValue>, Boolean>());
IgniteCache<Object, Object> cache = grid(idx).getOrCreateCache(ccfg.getName());
ContinuousQuery qry = new ContinuousQuery();
qry.setLocalListener(new TestCacheAsyncEventListener(evts, evtsFromCb, fromLsnr ? cache : null, qryCntr, cbCntr));
if (!fromLsnr)
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheTestRemoteFilterAsync(ccfg.getName())));
rcvdEvts.add(evts);
evtsFromCallbacks.add(evtsFromCb);
QueryCursor qryCursor = cache.query(qry);
qries.add(qryCursor);
}
IgniteInternalFuture<Long> f = GridTestUtils.runMultiThreadedAsync(new Runnable() {
@Override
public void run() {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < ITERATION_CNT; i++) {
IgniteCache<QueryTestKey, QueryTestValue> cache = grid(rnd.nextInt(NODES)).cache(ccfg.getName());
QueryTestKey key = new QueryTestKey(rnd.nextInt(KEYS) - KEYS);
boolean startTx = cache.getConfiguration(CacheConfiguration.class).getAtomicityMode() != ATOMIC && rnd.nextBoolean();
Transaction tx = null;
boolean committed = false;
while (!committed && !Thread.currentThread().isInterrupted()) {
try {
if (startTx)
tx = cache.unwrap(Ignite.class).transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
if ((cache.get(key) == null) || rnd.nextBoolean())
cache.invoke(key, new IncrementTestEntryProcessor());
else {
QueryTestValue val;
QueryTestValue newVal;
do {
val = cache.get(key);
newVal = val == null ? new QueryTestValue(0) : new QueryTestValue(val.val1 + 1);
} while (!cache.replace(key, val, newVal));
}
if (tx != null)
tx.commit();
committed = true;
} catch (Exception e) {
assertTrue(e.getCause() instanceof TransactionSerializationException);
assertEquals(ccfg.getAtomicityMode(), TRANSACTIONAL_SNAPSHOT);
} finally {
if (tx != null)
tx.close();
}
}
}
}
}, threadCnt, "put-thread");
f.get(30, TimeUnit.SECONDS);
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return qryCntr.get() >= ITERATION_CNT * threadCnt * NODES;
}
}, getTestTimeout());
for (Set<T2<QueryTestKey, QueryTestValue>> set : rcvdEvts) checkEvents(set, ITERATION_CNT * threadCnt, grid(0).cache(ccfg.getName()), false);
if (fromLsnr) {
final int expCnt = qryCntr.get() * NODES * KEYS_FROM_CALLBACK;
boolean res = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cbCntr.get() >= expCnt;
}
}, getTestTimeout());
assertTrue("Failed to wait events [exp=" + expCnt + ", act=" + cbCntr.get() + "]", res);
assertEquals(expCnt, cbCntr.get());
for (Set<T2<QueryTestKey, QueryTestValue>> set : evtsFromCallbacks) checkEvents(set, qryCntr.get() * KEYS_FROM_CALLBACK, grid(0).cache(ccfg.getName()), true);
} else {
final int expInvkCnt = ITERATION_CNT * threadCnt * (ccfg.getCacheMode() != REPLICATED ? (ccfg.getBackups() + 1) : NODES - 1) * NODES;
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return filterCbCntr.get() >= expInvkCnt;
}
}, getTestTimeout());
assertEquals(expInvkCnt, filterCbCntr.get());
for (Set<T2<QueryTestKey, QueryTestValue>> set : evtsFromCallbacks) checkEvents(set, expInvkCnt * KEYS_FROM_CALLBACK, grid(0).cache(ccfg.getName()), true);
}
} finally {
for (QueryCursor<?> qry : qries) qry.close();
ignite(0).destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class CacheEntryEventProbe method start.
/**
* {@inheritDoc}
*/
@Override
public void start(BenchmarkDriver drv, BenchmarkConfiguration cfg) throws Exception {
this.cfg = cfg;
if (drv instanceof IgniteCacheAbstractBenchmark) {
IgniteCacheAbstractBenchmark drv0 = (IgniteCacheAbstractBenchmark) drv;
if (drv0.cache() != null) {
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
final AtomicLong cnt = new AtomicLong();
qry.setLocalListener(localListener(cnt));
qryCur = drv0.cache().query(qry);
buildingService = Executors.newSingleThreadExecutor();
buildingService.execute(new Runnable() {
@Override
public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
Thread.sleep(1000);
long evts = cnt.getAndSet(0);
BenchmarkProbePoint pnt = new BenchmarkProbePoint(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()), new double[] { evts });
collectPoint(pnt);
}
} catch (InterruptedException e) {
// No-op.
}
}
});
println(cfg, getClass().getSimpleName() + " probe is started.");
}
}
if (qryCur == null)
errorHelp(cfg, "Can not start " + getClass().getSimpleName() + " probe. Probably, the driver doesn't provide \"cache()\" method.");
}
Aggregations