use of org.apache.geode.cache.query.internal.cq.CqListenerImpl in project geode by apache.
the class CQPDXPostProcessorDUnitTest method testCQ.
@Test
public void testCQ() {
String query = "select * from /" + REGION_NAME;
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Pool pool = PoolManager.find(region);
QueryService qs = pool.getQueryService();
CqAttributesFactory factory = new CqAttributesFactory();
factory.addCqListener(new CqListenerImpl() {
@Override
public void onEvent(final CqEvent aCqEvent) {
Object key = aCqEvent.getKey();
Object value = aCqEvent.getNewValue();
if (key.equals("key1")) {
assertTrue(value instanceof SimpleClass);
} else if (key.equals("key2")) {
assertTrue(Arrays.equals(BYTES, (byte[]) value));
}
}
});
CqAttributes cqa = factory.create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa);
CqResults results = cq.executeWithInitialResults();
});
client2.invoke(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key1", new SimpleClass(1, (byte) 1));
region.put("key2", BYTES);
});
// wait for events to fire
Awaitility.await().atMost(1, TimeUnit.SECONDS);
PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
assertEquals(pp.getCount(), 2);
}
use of org.apache.geode.cache.query.internal.cq.CqListenerImpl in project geode by apache.
the class CQPostProcessorDunitTest method testPostProcess.
@Test
public void testPostProcess() {
String query = "select * from /AuthRegion";
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Pool pool = PoolManager.find(region);
QueryService qs = pool.getQueryService();
CqAttributesFactory factory = new CqAttributesFactory();
factory.addCqListener(new CqListenerImpl() {
@Override
public void onEvent(final CqEvent aCqEvent) {
assertEquals("key6", aCqEvent.getKey());
assertEquals("super-user/AuthRegion/key6/value6", aCqEvent.getNewValue());
}
});
CqAttributes cqa = factory.create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa);
CqResults results = cq.executeWithInitialResults();
assertEquals(5, results.size());
String resultString = results.toString();
assertTrue(resultString, resultString.contains("key:key0,value:super-user/null/key0/value0"));
assertTrue(resultString.contains("key:key1,value:super-user/null/key1/value1"));
assertTrue(resultString.contains("key:key2,value:super-user/null/key2/value2"));
assertTrue(resultString.contains("key:key3,value:super-user/null/key3/value3"));
assertTrue(resultString.contains("key:key4,value:super-user/null/key4/value4"));
});
client2.invoke(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key6", "value6");
});
}
Aggregations