use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class RemoteTransactionDUnitTest method testBug43176.
@Test
public void testBug43176() {
Host host = Host.getHost(0);
VM datastore = host.getVM(0);
VM client = host.getVM(1);
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
AttributesFactory<Integer, String> af = new AttributesFactory<Integer, String>();
af.setScope(Scope.DISTRIBUTED_ACK);
af.setDataPolicy(DataPolicy.EMPTY);
af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
getCache().createRegionFactory(af.create()).create(EMPTY_REGION);
af.setDataPolicy(DataPolicy.REPLICATE);
getCache().createRegionFactory(af.create()).create(D_REFERENCE);
return null;
}
});
final int port = startServer(datastore);
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolServer("localhost", /* getServerHostName(Host.getHost(0)) */
port);
ccf.setPoolSubscriptionEnabled(true);
ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
ClientCache cCache = getClientCache(ccf);
ClientRegionFactory<Integer, String> crf = cCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
crf.addCacheListener(new ClientListener());
crf.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled());
Region r = crf.create(D_REFERENCE);
Region empty = crf.create(EMPTY_REGION);
r.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES);
empty.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS_VALUES);
return null;
}
});
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region ref = getCache().getRegion(D_REFERENCE);
Region empty = getCache().getRegion(EMPTY_REGION);
getGemfireCache().getCacheTransactionManager().begin();
ref.put("one", "value1");
empty.put("eone", "valueOne");
getCache().getLogger().info("SWAP:callingCommit");
getGemfireCache().getCacheTransactionManager().commit();
assertTrue(ref.containsKey("one"));
assertEquals("value1", ref.get("one"));
assertFalse(empty.containsKey("eone"));
assertNull(empty.get("eone"));
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region empty = getCache().getRegion(EMPTY_REGION);
final ClientListener l = (ClientListener) empty.getAttributes().getCacheListeners()[0];
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return l.invoked;
}
public String description() {
return "listener invoked:" + l.invoked;
}
};
Wait.waitForCriterion(wc, 10 * 1000, 200, true);
return null;
}
});
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class Bug43684DUnitTest method createClientCache.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void createClientCache(Host host, Integer port) {
disconnectFromDS();
Properties props = new Properties();
props.setProperty(STATISTIC_ARCHIVE_FILE, "client_" + OSProcess.getId() + ".gfs");
props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
ClientCacheFactory ccf = new ClientCacheFactory(props);
ccf.addPoolServer(host.getHostName(), port).setPoolSubscriptionEnabled(true);
cache = (GemFireCacheImpl) ccf.create();
ClientRegionFactory crf = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
crf.create(REGION_NAME);
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class Bug47388DUnitTest method createClientCache.
@SuppressWarnings("deprecation")
public static void createClientCache(Host host, Integer[] ports, Boolean doRI) throws Exception {
Properties props = new Properties();
props.setProperty(DURABLE_CLIENT_ID, "my-durable-client-" + ports.length);
props.setProperty(DURABLE_CLIENT_TIMEOUT, "300000");
DistributedSystem ds = new Bug47388DUnitTest().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);
if (doRI) {
crf.addCacheListener(new CacheListenerAdapter<String, String>() {
@Override
public void afterDestroy(EntryEvent<String, String> event) {
if (event.getKey().equalsIgnoreCase("LAST_KEY")) {
lastKeyDestroyed = true;
}
}
});
}
Region<String, String> region = crf.create(REGION_NAME);
if (doRI) {
region.registerInterest("ALL_KEYS", true);
cache.readyForEvents();
}
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class ClientServerMiscDUnitTest method clientIsPreventedFromConnectingToLocatorAsServer.
@Test(expected = GemFireConfigException.class)
public void clientIsPreventedFromConnectingToLocatorAsServer() throws Exception {
IgnoredException.addIgnoredException("Improperly configured client detected");
ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
clientCacheFactory.addPoolServer("localhost", DistributedTestUtils.getDUnitLocatorPort());
clientCacheFactory.setPoolSubscriptionEnabled(true);
getClientCache(clientCacheFactory);
}
use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.
the class JUnit4CacheTestCase method createCache.
private final void createCache(final boolean client, final CacheFactory factory) {
synchronized (JUnit4CacheTestCase.class) {
try {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
InternalCache newCache;
if (client) {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "locators", "");
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
newCache = (InternalCache) new ClientCacheFactory(getSystem().getProperties()).create();
} else {
if (factory == null) {
newCache = (InternalCache) CacheFactory.create(getSystem());
} else {
Properties props = getSystem().getProperties();
for (Map.Entry entry : props.entrySet()) {
factory.set((String) entry.getKey(), (String) entry.getValue());
}
newCache = (InternalCache) factory.create();
}
}
cache = newCache;
} catch (CacheExistsException e) {
// TODO: remove error handling
Assert.fail("the cache already exists", e);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
Assert.fail("Checked exception while initializing cache??", ex);
} finally {
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "locators");
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT);
}
}
}
Aggregations