Search in sources :

Example 51 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory 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)

Example 52 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory 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 53 with ClientCacheFactory

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

the class Bug47388DUnitTest method createClientCache.

@SuppressWarnings("deprecation")
public static void createClientCache(Host host, Integer[] ports, Boolean doRI) throws Exception {
    Properties props = new Properties();
    props.setProperty(DURABLE_CLIENT_ID, "my-durable-client-" + ports.length);
    props.setProperty(DURABLE_CLIENT_TIMEOUT, "300000");
    DistributedSystem ds = new Bug47388DUnitTest().getSystem(props);
    ds.disconnect();
    ClientCacheFactory ccf = new ClientCacheFactory(props);
    ccf.setPoolSubscriptionEnabled(doRI);
    ccf.setPoolSubscriptionAckInterval(50);
    ccf.setPoolSubscriptionRedundancy(1);
    for (int port : ports) {
        ccf.addPoolServer(host.getHostName(), port);
    }
    cache = (GemFireCacheImpl) ccf.create();
    ClientRegionFactory<String, String> crf = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
    if (doRI) {
        crf.addCacheListener(new CacheListenerAdapter<String, String>() {

            @Override
            public void afterDestroy(EntryEvent<String, String> event) {
                if (event.getKey().equalsIgnoreCase("LAST_KEY")) {
                    lastKeyDestroyed = true;
                }
            }
        });
    }
    Region<String, String> region = crf.create(REGION_NAME);
    if (doRI) {
        region.registerInterest("ALL_KEYS", true);
        cache.readyForEvents();
    }
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 54 with ClientCacheFactory

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

the class ClientServerMiscDUnitTest method clientIsPreventedFromConnectingToLocatorAsServer.

@Test(expected = GemFireConfigException.class)
public void clientIsPreventedFromConnectingToLocatorAsServer() throws Exception {
    IgnoredException.addIgnoredException("Improperly configured client detected");
    ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
    clientCacheFactory.addPoolServer("localhost", DistributedTestUtils.getDUnitLocatorPort());
    clientCacheFactory.setPoolSubscriptionEnabled(true);
    getClientCache(clientCacheFactory);
}
Also used : ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 55 with ClientCacheFactory

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

the class JUnit4CacheTestCase method createCache.

private final void createCache(final boolean client, final CacheFactory factory) {
    synchronized (JUnit4CacheTestCase.class) {
        try {
            System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
            InternalCache newCache;
            if (client) {
                System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "locators", "");
                System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
                newCache = (InternalCache) new ClientCacheFactory(getSystem().getProperties()).create();
            } else {
                if (factory == null) {
                    newCache = (InternalCache) CacheFactory.create(getSystem());
                } else {
                    Properties props = getSystem().getProperties();
                    for (Map.Entry entry : props.entrySet()) {
                        factory.set((String) entry.getKey(), (String) entry.getValue());
                    }
                    newCache = (InternalCache) factory.create();
                }
            }
            cache = newCache;
        } catch (CacheExistsException e) {
            // TODO: remove error handling
            Assert.fail("the cache already exists", e);
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            Assert.fail("Checked exception while initializing cache??", ex);
        } finally {
            System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
            System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "locators");
            System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT);
        }
    }
}
Also used : CacheExistsException(org.apache.geode.cache.CacheExistsException) InternalCache(org.apache.geode.internal.cache.InternalCache) Properties(java.util.Properties) Map(java.util.Map) RegionExistsException(org.apache.geode.cache.RegionExistsException) TimeoutException(org.apache.geode.cache.TimeoutException) CacheExistsException(org.apache.geode.cache.CacheExistsException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Aggregations

ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)87 ClientCache (org.apache.geode.cache.client.ClientCache)65 Test (org.junit.Test)45 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)44 VM (org.apache.geode.test.dunit.VM)42 Host (org.apache.geode.test.dunit.Host)40 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)40 Region (org.apache.geode.cache.Region)37 Properties (java.util.Properties)23 QueryService (org.apache.geode.cache.query.QueryService)22 SelectResults (org.apache.geode.cache.query.SelectResults)22 CacheServer (org.apache.geode.cache.server.CacheServer)22 Cache (org.apache.geode.cache.Cache)19 CacheException (org.apache.geode.cache.CacheException)14 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)13 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)13 IOException (java.io.IOException)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)12 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)11 PdxInstance (org.apache.geode.pdx.PdxInstance)10