@Before public void setup() { serverVM = VM.getVM(0); clientVM = VM.getVM(1); final int locatorPort = DistributedTestUtils.getDUnitLocatorPort(); // create a server cache and a client cache serverVM.invoke(() -> { String locatorSpec = "localhost[" + locatorPort + "]"; CacheFactory config = new CacheFactory(); config.set( ConfigurationProperties.LOCATORS, locatorSpec); config.set( ConfigurationProperties.NAME, "server1"); Cache serverCache = config.create(); cache = serverCache; CacheServer cacheServer = serverCache.addCacheServer(); cacheServer.start(); }); clientVM.invoke(() -> { ClientCacheFactory config = new ClientCacheFactory(); config.addPoolLocator("localhost", locatorPort); config.setPoolSubscriptionEnabled(true); cache = config.create(); }); }
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); }
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()) .setPoolSubscriptionTimeoutMultiplier(poolAttr.getSubscriptionTimeoutMultiplier()) .setPoolSubscriptionAckInterval(poolAttr.getSubscriptionAckInterval()) .setPoolServerGroup(poolAttr.getServerGroup()) .setPoolMultiuserAuthentication(poolAttr.getMultiuserAuthentication()); for (InetSocketAddress locator : poolAttr.getLocators()) { ccf.addPoolLocator(locator.getHostName(), locator.getPort()); ccf.addPoolServer(server.getHostName(), server.getPort());
public void createClientCache() { clientCache = (InternalClientCache) new ClientCacheFactory(config).create(); }
@Deprecated public static ClientCache createClientCache(String username, String password, int serverPort, Properties extraProperties) { Properties props = new Properties(); props.setProperty(UserPasswordAuthInit.USER_NAME, username); props.setProperty(UserPasswordAuthInit.PASSWORD, password); props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName()); props.setProperty(LOCATORS, ""); props.setProperty(MCAST_PORT, "0"); props.putAll(extraProperties); if (Version.CURRENT.ordinal() >= 75) { props.setProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.security.query.data.*"); } ClientCache cache = new ClientCacheFactory(props).setPoolSubscriptionEnabled(true) .addPoolServer("localhost", serverPort).create(); return cache; }
.when(clientCacheFactorySpy).setPdxDiskStore(anyString()); .when(clientCacheFactorySpy).setPdxIgnoreUnreadFields(anyBoolean()); .when(clientCacheFactorySpy).setPdxPersistent(anyBoolean()); .when(clientCacheFactorySpy).setPdxReadSerialized(anyBoolean()); .when(clientCacheFactorySpy).setPdxSerializer(any(PdxSerializer.class)); mockPoolFactory.addLocator(invocation.getArgument(0), invocation.getArgument(1)); return clientCacheFactorySpy; }).when(clientCacheFactorySpy).addPoolLocator(anyString(), anyInt()); }).when(clientCacheFactorySpy).addPoolServer(anyString(), anyInt()); }).when(clientCacheFactorySpy).setPoolFreeConnectionTimeout(anyInt()); }).when(clientCacheFactorySpy).setPoolIdleTimeout(anyLong()); }).when(clientCacheFactorySpy).setPoolLoadConditioningInterval(anyInt()); }).when(clientCacheFactorySpy).setPoolMaxConnections(anyInt()); }).when(clientCacheFactorySpy).setPoolMinConnections(anyInt()); }).when(clientCacheFactorySpy).setPoolMultiuserAuthentication(anyBoolean()); }).when(clientCacheFactorySpy).setPoolPingInterval(anyLong());
@Override public void init(final DataGenerator dataGenerator) throws Exception { this.dataGenerator = dataGenerator; logger.info("Initializing Geode Region"); EnvParser envParser = this.envParser; if(this.propertyFactory.getProperty(NdBenchConstants.DISCOVERY_ENV).asString("").get().equals(NdBenchConstants.DISCOVERY_ENV_CF)) { Properties props = new Properties(); props.setProperty(USER_NAME, envParser.getUsername()); props.setProperty(PASSWORD, envParser.getPasssword()); props.setProperty("security-client-auth-init", "com.netflix.ndbench.geode.plugin.ClientAuthInitialize.create"); ClientCacheFactory ccf = new ClientCacheFactory(props); List<URI> locatorList = envParser.getLocators(); for (URI locator : locatorList) { ccf.addPoolLocator(locator.getHost(), locator.getPort()); } clientCache = ccf.create(); }else{ clientCache = new ClientCacheFactory() .addPoolLocator(Inet4Address.getLoopbackAddress().getHostAddress(),55221) .create(); } sampleRegion = clientCache.<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION); }
ClientCacheFactory ccf = new ClientCacheFactory(); ccf.setPdxReadSerialized(true); if (serverPort != 0) { ccf.addPoolServer(serverHost, serverPort); } else { InetSocketAddress locatorAddress = getLocatorAddress(locatorStr); ccf.addPoolLocator(locatorAddress.getHostName(), locatorAddress.getPort()); cache = ccf.create();
@Override protected void createOrRetrieveCache() { if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Creating cache"); } // Get the existing cache if any try { this.cache = ClientCacheFactory.getAnyInstance(); } catch (CacheClosedException e) { } // If no cache exists, create one String message = null; if (this.cache == null || this.cache.isClosed()) { // enable pool subscription so that default cache can be used by hibernate module this.cache = new ClientCacheFactory(createDistributedSystemProperties()).create(); message = "Created "; } else { message = "Retrieved "; } getLogger().info(message + this.cache); }
public void createClientCache(final ClientCacheFactory ClientCacheFactory) { clientCache = (InternalClientCache) ClientCacheFactory.create(); }
@Override public void run2() throws CacheException { getSystem(properties); final ClientCacheFactory ccf = new ClientCacheFactory(properties); for (int i = 0; i < servers.length; i++) { ccf.addPoolServer(NetworkUtils.getServerHostName(servers[i].getHost()), ports[i]); } ccf.setPoolSubscriptionEnabled(true); ccf.setPoolSubscriptionRedundancy(redundancyLevel); ClientCache cache = (ClientCache) getClientCache(ccf); } });
@Test(expected = GemFireConfigException.class) public void clientIsPreventedFromConnectingToLocatorAsServer() { IgnoredException.addIgnoredException("Improperly configured client detected"); ClientCacheFactory clientCacheFactory = new ClientCacheFactory(); clientCacheFactory.addPoolServer("localhost", DistributedTestUtils.getDUnitLocatorPort()); clientCacheFactory.setPoolSubscriptionEnabled(true); getClientCache(clientCacheFactory); Region region = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY) .create(REGION_NAME1); region.registerInterest(k1); }
/** * Constructs a new instance of {@link ClientCacheFactory} initialized with the given Pivotal GemFire/Apache Geode * {@link Properties} used to construct, configure and initialize an instance of a {@link ClientCache}. * * @param gemfireProperties {@link Properties} used by the {@link ClientCacheFactory} * to configure the {@link ClientCache}. * @return a new instance of {@link ClientCacheFactory} initialized with * the given Pivotal GemFire/Apache Geode {@link Properties}. * @see org.apache.geode.cache.client.ClientCacheFactory * @see java.util.Properties */ @Override protected Object createFactory(Properties gemfireProperties) { return new ClientCacheFactory(gemfireProperties); }
public ClientCacheRule withLocatorConnection(int... serverPorts) { withCacheSetup(cf -> { for (int serverPort : serverPorts) { cf.addPoolLocator("localhost", serverPort); } }); return this; }
public ClientCacheRule withPoolSubscription(boolean enabled) { withCacheSetup(cf -> cf.setPoolSubscriptionEnabled(enabled)); return this; }
public ClientCacheRule withServerConnection(int... serverPorts) { withCacheSetup(cf -> { for (int serverPort : serverPorts) { cf.addPoolServer("localhost", serverPort); } }); return this; }
public void createClientCache(final Properties config) { clientCache = (InternalClientCache) new ClientCacheFactory(config).create(); }
@Override public void init(final DataGenerator dataGenerator) throws Exception { this.dataGenerator = dataGenerator; logger.info("Initializing Geode Region"); EnvParser envParser = this.envParser; if(this.propertyFactory.getProperty(NdBenchConstants.DISCOVERY_ENV).asString("").get().equals(NdBenchConstants.DISCOVERY_ENV_CF)) { Properties props = new Properties(); props.setProperty(USER_NAME, envParser.getUsername()); props.setProperty(PASSWORD, envParser.getPasssword()); props.setProperty("security-client-auth-init", "com.netflix.ndbench.geode.plugin.ClientAuthInitialize.create"); ClientCacheFactory ccf = new ClientCacheFactory(props); List<URI> locatorList = envParser.getLocators(); for (URI locator : locatorList) { ccf.addPoolLocator(locator.getHost(), locator.getPort()); } clientCache = ccf.create(); }else{ clientCache = new ClientCacheFactory() .addPoolLocator(Inet4Address.getLoopbackAddress().getHostAddress(),55221) .create(); } sampleRegion = clientCache.<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION); }
@Override protected void createOrRetrieveCache() { if (getLogger().isDebugEnabled()) { getLogger().debug(this + ": Creating cache"); } // Get the existing cache if any try { this.cache = ClientCacheFactory.getAnyInstance(); } catch (CacheClosedException e) { } // If no cache exists, create one String message = null; if (this.cache == null || this.cache.isClosed()) { // enable pool subscription so that default cache can be used by hibernate module this.cache = new ClientCacheFactory(createDistributedSystemProperties()).create(); message = "Created "; } else { message = "Retrieved "; } getLogger().info(message + this.cache); }
private void createClientCache(Properties props, ClientCacheFactory ccf) throws Exception { DistributedSystem ds = getSystem(props); assertNotNull(ds); ds.disconnect(); ClientCache cc = ccf.create(); setSystem(props, cc.getDistributedSystem()); cache = (Cache) cc; assertNotNull(cache); expected = IgnoredException .addIgnoredException("java.net.ConnectionException||java.net.SocketException"); }