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);
}
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());
}
}
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());
}
}
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;
}
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);
}
Aggregations