Search in sources :

Example 66 with ClientCacheFactory

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

the class RestAPIsAndInterOpsDUnitTest method createClientCache.

private void createClientCache(final String host, final int port) throws Exception {
    // Connect using the GemFire locator and create a Caching_Proxy cache
    ClientCache c = new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(host, port).create();
    c.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 67 with ClientCacheFactory

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

the class ClientServerTimeSyncDUnitTest method testClientTimeAdvances.

@Ignore("Bug 52327")
@Test
public void testClientTimeAdvances() {
    Host host = Host.getHost(0);
    // Server
    VM vm0 = host.getVM(0);
    // Client
    VM vm1 = host.getVM(1);
    final String regionName = "testRegion";
    final long TEST_OFFSET = 10000;
    ClientCache cache = null;
    try {
        final int serverPort = (Integer) vm0.invoke(new SerializableCallable("Start server with a region") {

            @Override
            public Object call() {
                Cache cache = getCache();
                cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
                LogWriterUtils.getLogWriter().info("Done creating region, now creating CacheServer");
                CacheServer server = null;
                try {
                    server = cache.addCacheServer();
                    server.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
                    server.start();
                } catch (IOException e) {
                    Assert.fail("Starting cache server failed.", e);
                }
                // now set an artificial time offset for the test
                basicGetSystem().getClock().setCacheTimeOffset(null, TEST_OFFSET, true);
                LogWriterUtils.getLogWriter().info("Done creating and starting CacheServer on port " + server.getPort());
                return server.getPort();
            }
        });
        final String hostName = NetworkUtils.getServerHostName(vm0.getHost());
        // Start client with proxy region and register interest
        disconnectFromDS();
        Properties props = new Properties();
        props.setProperty(LOCATORS, "");
        props = getSystem(props).getProperties();
        cache = new ClientCacheFactory(props).setPoolSubscriptionEnabled(true).addPoolServer(hostName, serverPort).setPoolPingInterval(5000).create();
        Region proxyRegion = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regionName);
        proxyRegion.registerInterestRegex(".*");
        proxyRegion.put("testkey", "testValue1");
        final DSClock clock = ((GemFireCacheImpl) cache).getSystem().getClock();
        WaitCriterion wc = new WaitCriterion() {

            public boolean done() {
                long clientTimeOffset = clock.getCacheTimeOffset();
                LogWriterUtils.getLogWriter().info("Client node's new time offset is: " + clientTimeOffset);
                return clientTimeOffset >= TEST_OFFSET;
            }

            public String description() {
                return "Waiting for cacheTimeOffset to be non-zero.  PingOp should have set it to something";
            }
        };
        Wait.waitForCriterion(wc, 60000, 1000, true);
    } finally {
        cache.close();
        vm1.invoke(() -> CacheTestCase.disconnectFromDS());
    }
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) IOException(java.io.IOException) Properties(java.util.Properties) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) DSClock(org.apache.geode.distributed.internal.DSClock) CacheServer(org.apache.geode.cache.server.CacheServer) ClientCache(org.apache.geode.cache.client.ClientCache) Ignore(org.junit.Ignore) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 68 with ClientCacheFactory

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

the class ClientServerTimeSyncDUnitTest method testClientTimeSlowsDown.

@Ignore("not yet implemented")
@Test
public void testClientTimeSlowsDown() {
    Host host = Host.getHost(0);
    // Server
    VM vm0 = host.getVM(0);
    // Client
    VM vm1 = host.getVM(1);
    final String regionName = "testRegion";
    final long TEST_OFFSET = 10000;
    ClientCache cache = null;
    try {
        final int serverPort = (Integer) vm0.invoke(new SerializableCallable("Start server with a region") {

            @Override
            public Object call() {
                Cache cache = getCache();
                cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
                LogWriterUtils.getLogWriter().info("Done creating region, now creating CacheServer");
                CacheServer server = null;
                try {
                    server = cache.addCacheServer();
                    server.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
                    server.start();
                } catch (IOException e) {
                    Assert.fail("Starting cache server failed.", e);
                }
                // now set an artificial time offset for the test
                basicGetSystem().getClock().setCacheTimeOffset(null, -TEST_OFFSET, true);
                LogWriterUtils.getLogWriter().info("Done creating and starting CacheServer on port " + server.getPort());
                return server.getPort();
            }
        });
        // let cacheTimeMillis consume the time offset
        Wait.pause((int) TEST_OFFSET);
        final String hostName = NetworkUtils.getServerHostName(vm0.getHost());
        // Start client with proxy region and register interest
        disconnectFromDS();
        Properties props = new Properties();
        props.setProperty(LOCATORS, "");
        props = getSystem(props).getProperties();
        cache = new ClientCacheFactory(props).setPoolSubscriptionEnabled(true).addPoolServer(hostName, serverPort).setPoolPingInterval(5000).create();
        Region proxyRegion = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regionName);
        proxyRegion.registerInterestRegex(".*");
        proxyRegion.put("testkey", "testValue1");
        final DSClock clock = ((GemFireCacheImpl) cache).getSystem().getClock();
        WaitCriterion wc = new WaitCriterion() {

            public boolean done() {
                long clientTimeOffset = clock.getCacheTimeOffset();
                LogWriterUtils.getLogWriter().info("Client node's new time offset is: " + clientTimeOffset);
                if (clientTimeOffset >= 0) {
                    return false;
                }
                long cacheTime = clock.cacheTimeMillis();
                return Math.abs(System.currentTimeMillis() - (cacheTime - clientTimeOffset)) < 5;
            }

            public String description() {
                return "Waiting for cacheTimeOffset to be negative and cacheTimeMillis to stabilize";
            }
        };
        Wait.waitForCriterion(wc, 60000, 1000, true);
    } finally {
        cache.close();
        vm1.invoke(() -> CacheTestCase.disconnectFromDS());
    }
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) IOException(java.io.IOException) Properties(java.util.Properties) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) DSClock(org.apache.geode.distributed.internal.DSClock) CacheServer(org.apache.geode.cache.server.CacheServer) ClientCache(org.apache.geode.cache.client.ClientCache) Ignore(org.junit.Ignore) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 69 with ClientCacheFactory

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

the class RestAPIsWithSSLDUnitTest method startInfraWithSSL.

private String startInfraWithSSL(final Properties sslProperties, boolean clusterLevel) throws Exception {
    final Host host = Host.getHost(0);
    VM locator = host.getVM(0);
    VM manager = host.getVM(1);
    VM server = host.getVM(2);
    VM client = host.getVM(3);
    // start locator
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    final String locatorHostName = NetworkUtils.getServerHostName(locator.getHost());
    locator.invoke("Start Locator", () -> {
        startLocator(locatorHostName, locatorPort, "");
    });
    // find locators
    String locators = locatorHostName + "[" + locatorPort + "]";
    // start manager (peer cache)
    manager.invoke("StartManager", () -> startManager(locators, new String[] { REGION_NAME }, sslProperties));
    // start startBridgeServer With RestService enabled
    String restEndpoint = server.invoke("startBridgeServerWithRestServiceOnInVM", () -> {
        final String hostName = server.getHost().getHostName();
        final int restServicePort = AvailablePortHelper.getRandomAvailableTCPPort();
        startBridgeServer(hostName, restServicePort, locators, new String[] { REGION_NAME }, sslProperties, clusterLevel);
        return "https://" + hostName + ":" + restServicePort + urlContext + "/v1";
    });
    // create a client cache
    client.invoke("Create ClientCache", () -> {
        new ClientCacheFactory().setPdxReadSerialized(true).addPoolLocator(locatorHostName, locatorPort).create();
        return null;
    });
    // create region in Manager, peer cache and Client cache nodes
    manager.invoke("createRegionInManager", () -> createRegionInCache());
    server.invoke("createRegionInPeerServer", () -> createRegionInCache());
    client.invoke("createRegionInClientCache", () -> createRegionInClientCache());
    // do some person puts from clientcache
    client.invoke("doPutsInClientCache", () -> doPutsInClientCache());
    return restEndpoint;
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 70 with ClientCacheFactory

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

the class CacheServerSSLConnectionDUnitTest method setUpClientVM.

public void setUpClientVM(String host, int port, boolean cacheServerSslenabled, boolean cacheServerSslRequireAuth, String keyStore, String trustStore, boolean subscription) {
    Properties gemFireProps = new Properties();
    String cacheServerSslprotocols = "any";
    String cacheServerSslciphers = "any";
    String keyStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, keyStore);
    String trustStorePath = TestUtil.getResourcePath(CacheServerSSLConnectionDUnitTest.class, trustStore);
    // using new server-ssl-* properties
    gemFireProps.put(SERVER_SSL_ENABLED, String.valueOf(cacheServerSslenabled));
    gemFireProps.put(SERVER_SSL_PROTOCOLS, cacheServerSslprotocols);
    gemFireProps.put(SERVER_SSL_CIPHERS, cacheServerSslciphers);
    gemFireProps.put(SERVER_SSL_REQUIRE_AUTHENTICATION, String.valueOf(cacheServerSslRequireAuth));
    gemFireProps.put(SERVER_SSL_KEYSTORE_TYPE, "jks");
    gemFireProps.put(SERVER_SSL_KEYSTORE, keyStorePath);
    gemFireProps.put(SERVER_SSL_KEYSTORE_PASSWORD, "password");
    gemFireProps.put(SERVER_SSL_TRUSTSTORE, trustStorePath);
    gemFireProps.put(SERVER_SSL_TRUSTSTORE_PASSWORD, "password");
    StringWriter sw = new StringWriter();
    PrintWriter writer = new PrintWriter(sw);
    gemFireProps.list(writer);
    System.out.println("Starting client ds with following properties \n" + sw.getBuffer());
    ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemFireProps);
    clientCacheFactory.setPoolSubscriptionEnabled(subscription).addPoolServer(host, port);
    clientCache = clientCacheFactory.create();
    ClientRegionFactory<String, String> regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY);
    Region<String, String> region = regionFactory.create("serverRegion");
    assertNotNull(region);
}
Also used : StringWriter(java.io.StringWriter) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PrintWriter(java.io.PrintWriter) 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