Search in sources :

Example 1 with CqListenerImpl

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);
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) SimpleClass(org.apache.geode.pdx.SimpleClass) CqListenerImpl(org.apache.geode.cache.query.internal.cq.CqListenerImpl) CqEvent(org.apache.geode.cache.query.CqEvent) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) Region(org.apache.geode.cache.Region) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqResults(org.apache.geode.cache.query.CqResults) Pool(org.apache.geode.cache.client.Pool) CqQuery(org.apache.geode.cache.query.CqQuery) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with CqListenerImpl

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");
    });
}
Also used : CqListenerImpl(org.apache.geode.cache.query.internal.cq.CqListenerImpl) CqEvent(org.apache.geode.cache.query.CqEvent) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) Region(org.apache.geode.cache.Region) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqResults(org.apache.geode.cache.query.CqResults) Pool(org.apache.geode.cache.client.Pool) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) CqQuery(org.apache.geode.cache.query.CqQuery) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Region (org.apache.geode.cache.Region)2 ClientCache (org.apache.geode.cache.client.ClientCache)2 Pool (org.apache.geode.cache.client.Pool)2 CqAttributes (org.apache.geode.cache.query.CqAttributes)2 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)2 CqEvent (org.apache.geode.cache.query.CqEvent)2 CqQuery (org.apache.geode.cache.query.CqQuery)2 CqResults (org.apache.geode.cache.query.CqResults)2 QueryService (org.apache.geode.cache.query.QueryService)2 CqListenerImpl (org.apache.geode.cache.query.internal.cq.CqListenerImpl)2 SecurityTestUtil.createClientCache (org.apache.geode.security.SecurityTestUtil.createClientCache)2 SecurityTestUtil.createProxyRegion (org.apache.geode.security.SecurityTestUtil.createProxyRegion)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)2 Test (org.junit.Test)2 SimpleClass (org.apache.geode.pdx.SimpleClass)1