Search in sources :

Example 26 with ClientCacheFactory

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

the class ClientHealthStatsDUnitTest method createClientCache.

/**
   * Invoked in client1VM and client2VM
   */
private void createClientCache(final String hostName, final Integer port, final int clientNum, final boolean subscriptionEnabled) {
    Properties props = new Properties();
    props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    ClientCacheFactory cacheFactory = new ClientCacheFactory(props);
    if (subscriptionEnabled) {
        cacheFactory.setPoolSubscriptionEnabled(true);
        cacheFactory.setPoolSubscriptionAckInterval(50);
        cacheFactory.setPoolSubscriptionRedundancy(0);
    }
    cacheFactory.set(DURABLE_CLIENT_ID, "DurableClientId_" + clientNum);
    cacheFactory.set(DURABLE_CLIENT_TIMEOUT, "" + 30000);
    cacheFactory.addPoolServer(hostName, port);
    clientCache = cacheFactory.create();
    ClientRegionFactory<String, String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
    regionFactory.setConcurrencyChecksEnabled(false);
    regionFactory.addCacheListener(new CacheListenerAdapter<String, String>() {

        @Override
        public void afterCreate(final EntryEvent<String, String> event) {
            if ("last_key".equals(event.getKey())) {
                lastKeyReceived = true;
            }
        }
    });
    Region<String, String> region = regionFactory.create(REGION_NAME);
    if (subscriptionEnabled) {
        region.registerInterest("ALL_KEYS", true);
        clientCache.readyForEvents();
    }
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 27 with ClientCacheFactory

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

the class Bug49856JUnitTest method testNoGFThreadsRunningPostCacheClose.

@Test
public void testNoGFThreadsRunningPostCacheClose() throws Exception {
    ClientCacheFactory ccf = new ClientCacheFactory();
    GemFireCacheImpl cache = (GemFireCacheImpl) ccf.create();
    SystemFailure.getFailure();
    Thread.sleep(5000);
    // Assert the threads have been started.
    checkThreads(true);
    cache.close();
    Thread.sleep(5000);
    // Assert the threads have been terminated.
    checkThreads(false);
}
Also used : GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 28 with ClientCacheFactory

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

the class Bug47667DUnitTest method testbug47667.

@Test
public void testbug47667() {
    Host host = Host.getHost(0);
    VM locator = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    final String locatorHost = NetworkUtils.getServerHostName(host);
    locator.invoke("Start Locator", () -> startLocator(locatorHost, locatorPort, ""));
    String locString = getLocatorString(host, locatorPort);
    server1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "R1" }, locString, new String[] { "R1" }));
    server2.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "R2" }, locString, new String[] { "R2" }));
    client.invoke("create region and insert data in transaction", () -> {
        ClientCacheFactory ccf = new ClientCacheFactory();
        ccf.addPoolLocator(locatorHost, locatorPort);
        ClientCache cache = ccf.create();
        PoolManager.createFactory().addLocator(locatorHost, locatorPort).setServerGroup("R1").create("R1");
        PoolManager.createFactory().addLocator(locatorHost, locatorPort).setServerGroup("R2").create("R2");
        Region region1 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).setPoolName("R1").create("R1");
        Region region2 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).setPoolName("R2").create("R2");
        CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
        transactionManager.begin();
        region1.put(1, "value1");
        transactionManager.commit();
        transactionManager.begin();
        region2.put(2, "value2");
        transactionManager.commit();
        return null;
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 29 with ClientCacheFactory

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

the class Bug48571DUnitTest method createClientCache.

public static void createClientCache(Host host, Integer port) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    props.setProperty(DURABLE_CLIENT_ID, "durable-48571");
    props.setProperty(DURABLE_CLIENT_TIMEOUT, "300000");
    props.setProperty(LOG_FILE, "client_" + OSProcess.getId() + ".log");
    props.setProperty(LOG_LEVEL, "info");
    props.setProperty(STATISTIC_ARCHIVE_FILE, "client_" + OSProcess.getId() + ".gfs");
    props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    ClientCacheFactory ccf = new ClientCacheFactory(props);
    ccf.setPoolSubscriptionEnabled(true);
    ccf.setPoolSubscriptionAckInterval(50);
    ccf.setPoolSubscriptionRedundancy(0);
    ccf.addPoolServer(host.getHostName(), port);
    DistributedSystem ds = new Bug48571DUnitTest().getSystem(props);
    ds.disconnect();
    cache = (GemFireCacheImpl) ccf.create();
    ClientRegionFactory<String, String> crf = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
    crf.setConcurrencyChecksEnabled(false);
    crf.addCacheListener(new CacheListenerAdapter<String, String>() {

        public void afterInvalidate(EntryEvent<String, String> event) {
            cache.getLoggerI18n().fine("Invalidate Event: " + event.getKey() + ", " + event.getNewValue());
            numOfInvalidates++;
        }

        public void afterCreate(EntryEvent<String, String> event) {
            if (((String) event.getKey()).equals("last_key")) {
                lastKeyReceived = true;
            }
            cache.getLoggerI18n().fine("Create Event: " + event.getKey() + ", " + event.getNewValue());
            numOfCreates++;
        }

        public void afterUpdate(EntryEvent<String, String> event) {
            cache.getLoggerI18n().fine("Update Event: " + event.getKey() + ", " + event.getNewValue());
            numOfUpdates++;
        }
    });
    Region<String, String> r = crf.create(region);
    r.registerInterest("ALL_KEYS", true);
    cache.readyForEvents();
}
Also used : Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 30 with ClientCacheFactory

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

the class Bug48879DUnitTest method createClientCache.

@SuppressWarnings("deprecation")
public static void createClientCache(Host host, Integer[] ports, Boolean doRI) throws Exception {
    Properties props = new Properties();
    props.setProperty(STATISTIC_ARCHIVE_FILE, "client_" + OSProcess.getId() + ".gfs");
    props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    DistributedSystem ds = new Bug48879DUnitTest().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);
    Region<String, String> region = crf.create(REGION_NAME);
    if (doRI) {
        region.registerInterest("ALL_KEYS");
    }
}
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)

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