Search in sources :

Example 6 with ClientRegionFactory

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

the class PostProcessorDUnitTest method testRegisterInterestPostProcess.

@Test
public void testRegisterInterestPostProcess() {
    client1.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
        factory.addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterUpdate(EntryEvent event) {
                assertEquals("super-user/AuthRegion/key1/value2", event.getSerializedNewValue().getDeserializedValue());
            }
        });
        Region region = factory.create(REGION_NAME);
        region.put("key1", "value1");
        region.registerInterest("key1");
    });
    client2.invoke(() -> {
        ClientCache cache = createClientCache("dataUser", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        region.put("key1", "value2");
    });
}
Also used : CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) 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) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with ClientRegionFactory

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

the class PDXPostProcessorDUnitTest method testRegisterInterest.

@Test
public void testRegisterInterest() {
    IgnoredException.addIgnoredException("NoAvailableServersException");
    client1.invoke(() -> {
        ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
        ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
        factory.addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterUpdate(EntryEvent event) {
                Object key = event.getKey();
                Object value = ((EntryEventImpl) event).getDeserializedValue();
                if (key.equals("key1")) {
                    assertTrue(value instanceof SimpleClass);
                } else if (key.equals("key2")) {
                    assertTrue(Arrays.equals(BYTES, (byte[]) value));
                }
            }
        });
        Region region = factory.create(REGION_NAME);
        region.put("key1", "value1");
        region.registerInterest("key1");
        region.registerInterest("key2");
    });
    client2.invoke(() -> {
        ClientCache cache = createClientCache("dataUser", "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);
    });
    // wait for events to fire
    Awaitility.await().atMost(1, TimeUnit.SECONDS);
    PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
    assertEquals(pp.getCount(), 2);
}
Also used : CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) 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) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) 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 8 with ClientRegionFactory

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

the class Bug43684DUnitTest method createClientCache.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void createClientCache(Host host, Integer port) {
    disconnectFromDS();
    Properties props = new Properties();
    props.setProperty(STATISTIC_ARCHIVE_FILE, "client_" + OSProcess.getId() + ".gfs");
    props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    ClientCacheFactory ccf = new ClientCacheFactory(props);
    ccf.addPoolServer(host.getHostName(), port).setPoolSubscriptionEnabled(true);
    cache = (GemFireCacheImpl) ccf.create();
    ClientRegionFactory crf = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
    crf.create(REGION_NAME);
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 9 with ClientRegionFactory

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

the class RollingUpgrade2DUnitTest method createClientRegion.

// Assumes a client cache is passed
public static void createClientRegion(GemFireCache cache, String regionName, ClientRegionShortcut shortcut) throws Exception {
    ClientRegionFactory rf = ((ClientCache) cache).createClientRegionFactory(shortcut);
    rf.create(regionName);
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory)

Example 10 with ClientRegionFactory

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

the class RemoteTransactionDUnitTest method testBug43176.

@Test
public void testBug43176() {
    Host host = Host.getHost(0);
    VM datastore = host.getVM(0);
    VM client = host.getVM(1);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            AttributesFactory<Integer, String> af = new AttributesFactory<Integer, String>();
            af.setScope(Scope.DISTRIBUTED_ACK);
            af.setDataPolicy(DataPolicy.EMPTY);
            af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            getCache().createRegionFactory(af.create()).create(EMPTY_REGION);
            af.setDataPolicy(DataPolicy.REPLICATE);
            getCache().createRegionFactory(af.create()).create(D_REFERENCE);
            return null;
        }
    });
    final int port = startServer(datastore);
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolServer("localhost", /* getServerHostName(Host.getHost(0)) */
            port);
            ccf.setPoolSubscriptionEnabled(true);
            ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache cCache = getClientCache(ccf);
            ClientRegionFactory<Integer, String> crf = cCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
            crf.addCacheListener(new ClientListener());
            crf.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
            Region r = crf.create(D_REFERENCE);
            Region empty = crf.create(EMPTY_REGION);
            r.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES);
            empty.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES);
            return null;
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region ref = getCache().getRegion(D_REFERENCE);
            Region empty = getCache().getRegion(EMPTY_REGION);
            getGemfireCache().getCacheTransactionManager().begin();
            ref.put("one", "value1");
            empty.put("eone", "valueOne");
            getCache().getLogger().info("SWAP:callingCommit");
            getGemfireCache().getCacheTransactionManager().commit();
            assertTrue(ref.containsKey("one"));
            assertEquals("value1", ref.get("one"));
            assertFalse(empty.containsKey("eone"));
            assertNull(empty.get("eone"));
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region empty = getCache().getRegion(EMPTY_REGION);
            final ClientListener l = (ClientListener) empty.getAttributes().getCacheListeners()[0];
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return l.invoked;
                }

                public String description() {
                    return "listener invoked:" + l.invoked;
                }
            };
            Wait.waitForCriterion(wc, 10 * 1000, 200, true);
            return null;
        }
    });
}
Also used : Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Aggregations

ClientRegionFactory (org.apache.geode.cache.client.ClientRegionFactory)10 ClientCache (org.apache.geode.cache.client.ClientCache)7 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)6 Region (org.apache.geode.cache.Region)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 Test (org.junit.Test)3 Properties (java.util.Properties)2 EntryEvent (org.apache.geode.cache.EntryEvent)2 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 SecurityTestUtil.createClientCache (org.apache.geode.security.SecurityTestUtil.createClientCache)2 SecurityTestUtil.createProxyRegion (org.apache.geode.security.SecurityTestUtil.createProxyRegion)2 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)2 NamingException (javax.naming.NamingException)1 RollbackException (javax.transaction.RollbackException)1 TXExpiryJUnitTest (org.apache.geode.TXExpiryJUnitTest)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1