Search in sources :

Example 21 with ClientCacheFactory

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

the class RegionCreateDestroyDUnitTest method testCreateInvalidRegion.

@Test
public void testCreateInvalidRegion() throws InterruptedException {
    Cache serverCache = getCache();
    try {
        serverCache.createRegionFactory(RegionShortcut.REPLICATE).create(BAD_REGION_NAME);
    } catch (IllegalArgumentException iae) {
        assertEquals("Region names may only be alphanumeric and may contain hyphens or underscores: Bad@Region", iae.getMessage());
    }
    try {
        startServer(serverCache);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    client1.invoke(() -> {
        ClientCache cache = new ClientCacheFactory(createClientProperties()).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
        try {
            cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(BAD_REGION_NAME);
            fail("Should have thrown an IllegalArgumentException");
        } catch (IllegalArgumentException iae) {
            assertEquals("Region names may only be alphanumeric and may contain hyphens or underscores: Bad@Region", iae.getMessage());
        }
    });
}
Also used : IOException(java.io.IOException) ClientCache(org.apache.geode.cache.client.ClientCache) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 22 with ClientCacheFactory

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

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

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

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

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