Search in sources :

Example 31 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class NoShowValue1PostProcessorDUnitTest method testPostProcess.

@Test
public void testPostProcess() {
    List<String> keys = new ArrayList<>();
    keys.add("key1");
    keys.add("key2");
    client1.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // post process for get
        assertEquals("value3", region.get("key3"));
        assertNull(region.get("key1"));
        // post processs for getAll
        Map values = region.getAll(keys);
        assertEquals(2, values.size());
        assertEquals("value2", values.get("key2"));
        assertNull(values.get("key1"));
        // post process for query
        String query = "select * from /AuthRegion";
        SelectResults result = region.query(query);
        System.out.println("query result: " + result);
        assertEquals(5, result.size());
        assertTrue(result.contains("value0"));
        assertFalse(result.contains("value1"));
        assertTrue(result.contains("value2"));
        assertTrue(result.contains("value3"));
        assertTrue(result.contains("value4"));
        Pool pool = PoolManager.find(region);
        result = (SelectResults) pool.getQueryService().newQuery(query).execute();
        System.out.println("query result: " + result);
        assertTrue(result.contains("value0"));
        assertFalse(result.contains("value1"));
        assertTrue(result.contains("value2"));
        assertTrue(result.contains("value3"));
        assertTrue(result.contains("value4"));
    });
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Pool(org.apache.geode.cache.client.Pool) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) Map(java.util.Map) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 32 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class PDXPostProcessorDUnitTest method testQuery.

@Test
public void testQuery() {
    client2.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // put in a value that's a domain object
        region.put("key1", new SimpleClass(1, (byte) 1));
        region.put("key2", BYTES);
    });
    client1.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // post process for query
        String query = "select * from /AuthRegion";
        SelectResults result = region.query(query);
        Iterator itr = result.iterator();
        while (itr.hasNext()) {
            Object obj = itr.next();
            if (obj instanceof byte[]) {
                assertTrue(Arrays.equals(BYTES, (byte[]) obj));
            } else {
                assertTrue(obj instanceof SimpleClass);
            }
        }
    });
    // this makes sure PostProcessor is getting called
    PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
    assertEquals(pp.getCount(), 2);
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) SimpleClass(org.apache.geode.pdx.SimpleClass) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 33 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class PDXPostProcessorDUnitTest method testRegionGet.

@Test
public void testRegionGet() {
    client2.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // put in a value that's a domain object
        region.put("key1", new SimpleClass(1, (byte) 1));
        // put in a byte value
        region.put("key2", BYTES);
    });
    client1.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // post process for get the client domain object
        Object value = region.get("key1");
        assertTrue(value instanceof SimpleClass);
        // post process for get the raw byte value
        value = region.get("key2");
        assertTrue(Arrays.equals(BYTES, (byte[]) value));
    });
    // this makes sure PostProcessor is getting called
    PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
    assertEquals(pp.getCount(), 2);
}
Also used : Region(org.apache.geode.cache.Region) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) SimpleClass(org.apache.geode.pdx.SimpleClass) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 34 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class PostProcessorDUnitTest method testPostProcessRegionGet.

@Test
public void testPostProcessRegionGet() {
    List<String> keys = new ArrayList<>();
    keys.add("key1");
    keys.add("key2");
    client1.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // post process for get
        Object value = region.get("key3");
        assertEquals("super-user/AuthRegion/key3/value3", value);
        // post processs for getAll
        Map values = region.getAll(keys);
        assertEquals(2, values.size());
        assertEquals("super-user/AuthRegion/key1/value1", values.get("key1"));
        assertEquals("super-user/AuthRegion/key2/value2", values.get("key2"));
    });
}
Also used : ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) Map(java.util.Map) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 35 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class PostProcessorDUnitTest method testPostProcessQuery.

@Test
public void testPostProcessQuery() {
    client1.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // post process for query
        String query = "select * from /AuthRegion";
        SelectResults result = region.query(query);
        assertEquals(5, result.size());
        assertTrue(result.contains("super-user/null/null/value0"));
        assertTrue(result.contains("super-user/null/null/value1"));
        assertTrue(result.contains("super-user/null/null/value2"));
        assertTrue(result.contains("super-user/null/null/value3"));
        assertTrue(result.contains("super-user/null/null/value4"));
        Pool pool = PoolManager.find(region);
        result = (SelectResults) pool.getQueryService().newQuery(query).execute();
        assertTrue(result.contains("super-user/null/null/value0"));
        assertTrue(result.contains("super-user/null/null/value1"));
        assertTrue(result.contains("super-user/null/null/value2"));
        assertTrue(result.contains("super-user/null/null/value3"));
        assertTrue(result.contains("super-user/null/null/value4"));
    });
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Region(org.apache.geode.cache.Region) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Pool(org.apache.geode.cache.client.Pool) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

ClientCache (org.apache.geode.cache.client.ClientCache)115 Test (org.junit.Test)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)67 Region (org.apache.geode.cache.Region)65 VM (org.apache.geode.test.dunit.VM)43 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)42 Host (org.apache.geode.test.dunit.Host)40 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)31 QueryService (org.apache.geode.cache.query.QueryService)27 SelectResults (org.apache.geode.cache.query.SelectResults)26 SecurityTestUtil.createClientCache (org.apache.geode.security.SecurityTestUtil.createClientCache)25 SecurityTestUtil.createProxyRegion (org.apache.geode.security.SecurityTestUtil.createProxyRegion)23 CacheServer (org.apache.geode.cache.server.CacheServer)22 Cache (org.apache.geode.cache.Cache)20 CacheException (org.apache.geode.cache.CacheException)15 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)13 IOException (java.io.IOException)12 Properties (java.util.Properties)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)12