Search in sources :

Example 26 with ClientCache

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

the class ClientsWithVersioningRetryDUnitTest method createClientRegion.

private void createClientRegion(final VM vm, final int port1, final int port2, final boolean threadLocalConnections) {
    SerializableCallable createRegion = new SerializableCallable("create client region in " + vm) {

        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port1);
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port2);
            cf.setPoolPRSingleHopEnabled(false);
            cf.setPoolThreadLocalConnections(threadLocalConnections);
            cf.setPoolReadTimeout(10 * 60 * 1000);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("region");
            return null;
        }
    };
    vm.invoke(createRegion);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 27 with ClientCache

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

the class PdxClientServerDUnitTest method createClientRegion.

private void createClientRegion(final VM vm, final int port, final boolean threadLocalConnections, final boolean setPdxTypeClearProp, final String... autoSerializerPatterns) {
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            if (setPdxTypeClearProp) {
                System.setProperty(PoolImpl.ON_DISCONNECT_CLEAR_PDXTYPEIDS, "true");
            }
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port);
            cf.setPoolThreadLocalConnections(threadLocalConnections);
            if (autoSerializerPatterns != null && autoSerializerPatterns.length != 0) {
                cf.setPdxSerializer(new ReflectionBasedAutoSerializer(autoSerializerPatterns));
            }
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("testSimplePdx");
            return null;
        }
    };
    vm.invoke(createRegion);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 28 with ClientCache

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

the class PdxTypeExportDUnitTest method loadCache.

@SuppressWarnings("serial")
public void loadCache() throws Exception {
    SerializableCallable peer = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
            Cache cache = getCache(cf);
            Region r = cache.createRegionFactory(RegionShortcut.REPLICATE).create("pdxtest");
            r.put(1, new MyObjectPdx(1, "test", MyEnumPdx.const1));
            return null;
        }
    };
    final Host host = Host.getHost(0);
    host.getVM(1).invoke(peer);
    SerializableCallable server = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
            CacheServer server = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailableTCPPort();
            server.setPort(port);
            server.start();
            Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create("pdxtest");
            return port;
        }
    };
    final int port = (Integer) host.getVM(2).invoke(server);
    SerializableCallable client = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory().setPdxSerializer(new MyPdxSerializer()).addPoolServer(NetworkUtils.getServerHostName(host), port);
            ClientCache cache = getClientCache(cf);
            Region r = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("pdxtest");
            return null;
        }
    };
    host.getVM(3).invoke(client);
    peer.call();
}
Also used : MyPdxSerializer(com.examples.snapshot.MyPdxSerializer) MyObjectPdx(com.examples.snapshot.MyObjectPdx) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 29 with ClientCache

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

the class PdxDeserializationDUnitTest method createClient.

private void createClient(final int port0) {
    ClientCacheFactory cf = new ClientCacheFactory();
    cf.addPoolServer("localhost", port0);
    cf.setPoolSubscriptionEnabled(true);
    ClientCache cache = getClientCache(cf);
    Region replicate = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("replicate");
    Region pr = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("pr");
    cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("overflow_replicate");
    cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create("overflow_pr");
    // Register interest in a key
    replicate.registerInterest("A", InterestResultPolicy.KEYS_VALUES);
    pr.registerInterest("A", InterestResultPolicy.KEYS_VALUES);
}
Also used : Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 30 with ClientCache

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

the class JSONPdxClientServerDUnitTest method createClientRegion.

private void createClientRegion(final VM vm, final int port, final boolean threadLocalConnections) {
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port);
            cf.setPoolThreadLocalConnections(threadLocalConnections);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("testSimplePdx");
            return null;
        }
    };
    vm.invoke(createRegion);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

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