use of org.apache.ignite.spi.systemview.view.ScanQueryView in project ignite by apache.
the class SystemViewSelfTest method testScanQuery.
/**
*/
@Test
public void testScanQuery() throws Exception {
try (IgniteEx g0 = startGrid(0);
IgniteEx g1 = startGrid(1);
IgniteEx client1 = startClientGrid("client-1");
IgniteEx client2 = startClientGrid("client-2")) {
IgniteCache<Integer, Integer> cache1 = client1.createCache(new CacheConfiguration<Integer, Integer>("cache1").setGroupName("group1"));
IgniteCache<Integer, Integer> cache2 = client2.createCache("cache2");
for (int i = 0; i < 100; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
SystemView<ScanQueryView> qrySysView0 = g0.context().systemView().view(SCAN_QRY_SYS_VIEW);
SystemView<ScanQueryView> qrySysView1 = g1.context().systemView().view(SCAN_QRY_SYS_VIEW);
assertNotNull(qrySysView0);
assertNotNull(qrySysView1);
assertEquals(0, qrySysView0.size());
assertEquals(0, qrySysView1.size());
QueryCursor<Integer> qryRes1 = cache1.query(new ScanQuery<Integer, Integer>().setFilter(new TestPredicate()).setPageSize(10), new TestTransformer());
QueryCursor<?> qryRes2 = cache2.withKeepBinary().query(new ScanQuery<>().setPageSize(20));
assertTrue(qryRes1.iterator().hasNext());
assertTrue(qryRes2.iterator().hasNext());
checkScanQueryView(client1, client2, qrySysView0);
checkScanQueryView(client1, client2, qrySysView1);
qryRes1.close();
qryRes2.close();
boolean res = waitForCondition(() -> qrySysView0.size() + qrySysView1.size() == 0, 5_000);
assertTrue(res);
}
}
use of org.apache.ignite.spi.systemview.view.ScanQueryView in project ignite by apache.
the class SystemViewSelfTest method testLocalScanQuery.
/**
*/
@Test
public void testLocalScanQuery() throws Exception {
try (IgniteEx g0 = startGrid(0)) {
IgniteCache<Integer, Integer> cache1 = g0.createCache(new CacheConfiguration<Integer, Integer>("cache1").setGroupName("group1"));
int part = g0.affinity("cache1").primaryPartitions(g0.localNode())[0];
List<Integer> partKeys = partitionKeys(cache1, part, 11, 0);
for (Integer key : partKeys) cache1.put(key, key);
SystemView<ScanQueryView> qrySysView0 = g0.context().systemView().view(SCAN_QRY_SYS_VIEW);
assertNotNull(qrySysView0);
assertEquals(0, qrySysView0.size());
QueryCursor<Integer> qryRes1 = cache1.query(new ScanQuery<Integer, Integer>().setFilter(new TestPredicate()).setLocal(true).setPartition(part).setPageSize(10), new TestTransformer());
assertTrue(qryRes1.iterator().hasNext());
boolean res = waitForCondition(() -> qrySysView0.size() > 0, 5_000);
assertTrue(res);
ScanQueryView view = qrySysView0.iterator().next();
assertEquals(g0.localNode().id(), view.originNodeId());
assertEquals(0, view.queryId());
assertEquals("cache1", view.cacheName());
assertEquals(cacheId("cache1"), view.cacheId());
assertEquals(cacheGroupId("cache1", "group1"), view.cacheGroupId());
assertEquals("group1", view.cacheGroupName());
assertTrue(view.startTime() <= System.currentTimeMillis());
assertTrue(view.duration() >= 0);
assertFalse(view.canceled());
assertEquals(TEST_PREDICATE, view.filter());
assertTrue(view.local());
assertEquals(part, view.partition());
assertEquals(toStringSafe(g0.context().discovery().topologyVersionEx()), view.topology());
assertEquals(TEST_TRANSFORMER, view.transformer());
assertFalse(view.keepBinary());
assertNull(view.subjectId());
assertNull(view.taskName());
qryRes1.close();
res = waitForCondition(() -> qrySysView0.size() == 0, 5_000);
assertTrue(res);
}
}
use of org.apache.ignite.spi.systemview.view.ScanQueryView in project ignite by apache.
the class SystemViewSelfTest method checkScanQueryView.
/**
*/
private void checkScanQueryView(IgniteEx client1, IgniteEx client2, SystemView<ScanQueryView> qrySysView) throws Exception {
boolean res = waitForCondition(() -> qrySysView.size() > 1, 5_000);
assertTrue(res);
Consumer<ScanQueryView> cache1checker = view -> {
assertEquals(client1.localNode().id(), view.originNodeId());
assertTrue(view.queryId() != 0);
assertEquals("cache1", view.cacheName());
assertEquals(cacheId("cache1"), view.cacheId());
assertEquals(cacheGroupId("cache1", "group1"), view.cacheGroupId());
assertEquals("group1", view.cacheGroupName());
assertTrue(view.startTime() <= System.currentTimeMillis());
assertTrue(view.duration() >= 0);
assertFalse(view.canceled());
assertEquals(TEST_PREDICATE, view.filter());
assertFalse(view.local());
assertEquals(-1, view.partition());
assertEquals(toStringSafe(client1.context().discovery().topologyVersionEx()), view.topology());
assertEquals(TEST_TRANSFORMER, view.transformer());
assertFalse(view.keepBinary());
assertNull(view.subjectId());
assertNull(view.taskName());
assertEquals(10, view.pageSize());
};
Consumer<ScanQueryView> cache2checker = view -> {
assertEquals(client2.localNode().id(), view.originNodeId());
assertTrue(view.queryId() != 0);
assertEquals("cache2", view.cacheName());
assertEquals(cacheId("cache2"), view.cacheId());
assertEquals(cacheGroupId("cache2", null), view.cacheGroupId());
assertEquals("cache2", view.cacheGroupName());
assertTrue(view.startTime() <= System.currentTimeMillis());
assertTrue(view.duration() >= 0);
assertFalse(view.canceled());
assertNull(view.filter());
assertFalse(view.local());
assertEquals(-1, view.partition());
assertEquals(toStringSafe(client2.context().discovery().topologyVersionEx()), view.topology());
assertNull(view.transformer());
assertTrue(view.keepBinary());
assertNull(view.subjectId());
assertNull(view.taskName());
assertEquals(20, view.pageSize());
};
boolean found1 = false;
boolean found2 = false;
for (ScanQueryView view : qrySysView) {
if ("cache2".equals(view.cacheName())) {
cache2checker.accept(view);
found1 = true;
} else {
cache1checker.accept(view);
found2 = true;
}
}
assertTrue(found1 && found2);
}
Aggregations