Search in sources :

Example 1 with SimpleClass

use of org.apache.geode.pdx.SimpleClass in project geode by apache.

the class PDXGfshPostProcessorOnRemoteServerTest method testGfshCommand.

@Test
public void testGfshCommand() throws Exception {
    Properties locatorProps = new Properties();
    locatorProps.setProperty(TestSecurityManager.SECURITY_JSON, "org/apache/geode/management/internal/security/clientServer.json");
    locatorProps.setProperty(SECURITY_MANAGER, TestSecurityManager.class.getName());
    locatorProps.setProperty(SECURITY_POST_PROCESSOR, PDXPostProcessor.class.getName());
    MemberVM<Locator> locatorVM = lsRule.startLocatorVM(0, locatorProps);
    Properties serverProps = new Properties();
    serverProps.setProperty(TestSecurityManager.SECURITY_JSON, "org/apache/geode/management/internal/security/clientServer.json");
    serverProps.setProperty("security-username", "super-user");
    serverProps.setProperty("security-password", "1234567");
    MemberVM<Server> serverVM = lsRule.startServerVM(1, serverProps, locatorVM.getPort());
    serverVM.invoke(() -> {
        Cache cache = LocatorServerStartupRule.serverStarter.getCache();
        Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME);
        for (int i = 0; i < 5; i++) {
            SimpleClass obj = new SimpleClass(i, (byte) i);
            region.put("key" + i, obj);
        }
    });
    // wait until the region bean is visible
    locatorVM.invoke(() -> {
        Awaitility.await().pollInterval(500, TimeUnit.MICROSECONDS).atMost(5, TimeUnit.SECONDS).until(() -> {
            Cache cache = CacheFactory.getAnyInstance();
            Object bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean("/" + REGION_NAME);
            return bean != null;
        });
    });
    gfsh.connectAndVerify(locatorVM.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger, CliStrings.CONNECT__USERNAME, "dataUser", CliStrings.CONNECT__PASSWORD, "1234567");
    // get command
    CommandResult result = gfsh.executeAndVerifyCommand("get --key=key1 --region=AuthRegion");
    assertTrue(result.getContent().toString().contains(SimpleClass.class.getName()));
    gfsh.executeAndVerifyCommand("query --query=\"select * from /AuthRegion\"");
    serverVM.invoke(() -> {
        PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
        // verify that the post processor is called 6 times. (5 for the query, 1 for the get)
        assertEquals(pp.getCount(), 6);
    });
}
Also used : Server(org.apache.geode.test.dunit.rules.Server) Properties(java.util.Properties) SimpleClass(org.apache.geode.pdx.SimpleClass) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Locator(org.apache.geode.test.dunit.rules.Locator) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with SimpleClass

use of org.apache.geode.pdx.SimpleClass 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 3 with SimpleClass

use of org.apache.geode.pdx.SimpleClass 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 4 with SimpleClass

use of org.apache.geode.pdx.SimpleClass 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 5 with SimpleClass

use of org.apache.geode.pdx.SimpleClass in project geode by apache.

the class WANTestBase method validateRegionSize_PDX.

public static void validateRegionSize_PDX(String regionName, final int regionSize) {
    final Region r = cache.getRegion(Region.SEPARATOR + regionName);
    assertNotNull(r);
    Awaitility.await().atMost(200, TimeUnit.SECONDS).until(() -> assertEquals("Expected region entries: " + regionSize + " but actual entries: " + r.keySet().size() + " present region keyset " + r.keySet(), true, (regionSize <= r.keySet().size())));
    for (int i = 0; i < regionSize; i++) {
        LogWriterUtils.getLogWriter().info("For Key : Key_" + i + " : Values : " + r.get("Key_" + i));
        assertEquals(new SimpleClass(i, (byte) i), r.get("Key_" + i));
    }
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) SimpleClass(org.apache.geode.pdx.SimpleClass)

Aggregations

Region (org.apache.geode.cache.Region)8 SimpleClass (org.apache.geode.pdx.SimpleClass)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)6 Test (org.junit.Test)6 ClientCache (org.apache.geode.cache.client.ClientCache)5 SecurityTestUtil.createClientCache (org.apache.geode.security.SecurityTestUtil.createClientCache)5 SecurityTestUtil.createProxyRegion (org.apache.geode.security.SecurityTestUtil.createProxyRegion)5 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)2 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 Cache (org.apache.geode.cache.Cache)1 EntryEvent (org.apache.geode.cache.EntryEvent)1 ClientRegionFactory (org.apache.geode.cache.client.ClientRegionFactory)1 Pool (org.apache.geode.cache.client.Pool)1 CqAttributes (org.apache.geode.cache.query.CqAttributes)1 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)1