Search in sources :

Example 81 with ClientCacheFactory

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

the class ClassNotFoundExceptionDUnitTest method createClientRegion.

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

        public Object call() throws Exception {
            disconnectFromDS();
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port);
            cf.setPoolSubscriptionEnabled(true);
            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 82 with ClientCacheFactory

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

the class UpdatePropagationDUnitTest method createClientCache.

private void createClientCache(String host, Integer port1, Integer port2) throws Exception {
    ClientCache cache;
    try {
        System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "PoolImpl.DISABLE_RANDOM", "true");
        int PORT1 = port1.intValue();
        int PORT2 = port2.intValue();
        Properties props = new Properties();
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(LOCATORS, "");
        ClientCacheFactory cf = new ClientCacheFactory();
        cf.addPoolServer(host, PORT1).addPoolServer(host, PORT2).setPoolSubscriptionEnabled(true).setPoolSubscriptionRedundancy(-1).setPoolMinConnections(4).setPoolSocketBufferSize(1000).setPoolReadTimeout(2000).setPoolPingInterval(300);
        cache = getClientCache(cf);
    } finally {
        System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "PoolImpl.DISABLE_RANDOM", "false");
        CacheServerTestUtil.enableShufflingOfEndpoints();
    }
    cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).addCacheListener(new EventTrackingCacheListener()).create(REGION_NAME);
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 83 with ClientCacheFactory

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

the class FunctionServiceClientBase method createServersAndClient.

public ClientCache createServersAndClient(int numberOfServers) {
    int[] ports = new int[numberOfServers];
    Host host = Host.getHost(0);
    for (int i = 0; i < numberOfServers; i++) {
        VM vm = host.getVM(i);
        ports[i] = createServer(vm);
    }
    ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
    Arrays.stream(ports).forEach(port -> {
        clientCacheFactory.addPoolServer("localhost", port);
    });
    configureClient(clientCacheFactory);
    return getClientCache(clientCacheFactory);
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 84 with ClientCacheFactory

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

the class CacheServerTestUtil method createCacheClientFromXml.

public static void createCacheClientFromXml(URL url, String poolName, String durableClientId, int timeout, Boolean addControlListener) {
    ClientCacheFactory ccf = new ClientCacheFactory();
    try {
        File cacheXmlFile = new File(url.toURI().getPath());
        ccf.set(CACHE_XML_FILE, cacheXmlFile.toURI().getPath());
    } catch (URISyntaxException e) {
        throw new ExceptionInInitializerError(e);
    }
    ccf.set(MCAST_PORT, "0");
    ccf.set(DURABLE_CLIENT_ID, durableClientId);
    ccf.set(DURABLE_CLIENT_TIMEOUT, String.valueOf(timeout));
    cache = (Cache) ccf.create();
    expected = IgnoredException.addIgnoredException("java.net.ConnectionException||java.net.SocketException");
    pool = (PoolImpl) PoolManager.find(poolName);
}
Also used : URISyntaxException(java.net.URISyntaxException) File(java.io.File) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 85 with ClientCacheFactory

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

the class CacheServerTestUtil method createClientCache.

public static void createClientCache(Pool poolAttr, String regionName, Properties dsProperties) throws Exception {
    ClientCacheFactory ccf = new ClientCacheFactory(dsProperties);
    if (poolAttr != null) {
        ccf.setPoolFreeConnectionTimeout(poolAttr.getFreeConnectionTimeout()).setPoolLoadConditioningInterval(poolAttr.getLoadConditioningInterval()).setPoolSocketBufferSize(poolAttr.getSocketBufferSize()).setPoolMinConnections(poolAttr.getMinConnections()).setPoolMaxConnections(poolAttr.getMaxConnections()).setPoolIdleTimeout(poolAttr.getIdleTimeout()).setPoolPingInterval(poolAttr.getPingInterval()).setPoolStatisticInterval(poolAttr.getStatisticInterval()).setPoolRetryAttempts(poolAttr.getRetryAttempts()).setPoolThreadLocalConnections(poolAttr.getThreadLocalConnections()).setPoolReadTimeout(poolAttr.getReadTimeout()).setPoolSubscriptionEnabled(poolAttr.getSubscriptionEnabled()).setPoolPRSingleHopEnabled(poolAttr.getPRSingleHopEnabled()).setPoolSubscriptionRedundancy(poolAttr.getSubscriptionRedundancy()).setPoolSubscriptionMessageTrackingTimeout(poolAttr.getSubscriptionMessageTrackingTimeout()).setPoolSubscriptionAckInterval(poolAttr.getSubscriptionAckInterval()).setPoolServerGroup(poolAttr.getServerGroup()).setPoolMultiuserAuthentication(poolAttr.getMultiuserAuthentication());
        for (InetSocketAddress locator : poolAttr.getLocators()) {
            ccf.addPoolLocator(locator.getHostName(), locator.getPort());
        }
        for (InetSocketAddress server : poolAttr.getServers()) {
            ccf.addPoolServer(server.getHostName(), server.getPort());
        }
    }
    new CacheServerTestUtil().createClientCache(dsProperties, ccf);
    ClientCache cc = (ClientCache) cache;
    cc.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regionName);
    pool = (PoolImpl) ((GemFireCacheImpl) cc).getDefaultPool();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) 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