use of org.apache.geode.cache.client.ClientRegionFactory in project geode by apache.
the class PostProcessorDUnitTest method testRegisterInterestPostProcess.
@Test
public void testRegisterInterestPostProcess() {
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterUpdate(EntryEvent event) {
assertEquals("super-user/AuthRegion/key1/value2", event.getSerializedNewValue().getDeserializedValue());
}
});
Region region = factory.create(REGION_NAME);
region.put("key1", "value1");
region.registerInterest("key1");
});
client2.invoke(() -> {
ClientCache cache = createClientCache("dataUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key1", "value2");
});
}
use of org.apache.geode.cache.client.ClientRegionFactory in project geode by apache.
the class PDXPostProcessorDUnitTest method testRegisterInterest.
@Test
public void testRegisterInterest() {
IgnoredException.addIgnoredException("NoAvailableServersException");
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterUpdate(EntryEvent event) {
Object key = event.getKey();
Object value = ((EntryEventImpl) event).getDeserializedValue();
if (key.equals("key1")) {
assertTrue(value instanceof SimpleClass);
} else if (key.equals("key2")) {
assertTrue(Arrays.equals(BYTES, (byte[]) value));
}
}
});
Region region = factory.create(REGION_NAME);
region.put("key1", "value1");
region.registerInterest("key1");
region.registerInterest("key2");
});
client2.invoke(() -> {
ClientCache cache = createClientCache("dataUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// put in a value that's a domain object
region.put("key1", new SimpleClass(1, (byte) 1));
region.put("key2", BYTES);
});
// wait for events to fire
Awaitility.await().atMost(1, TimeUnit.SECONDS);
PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
assertEquals(pp.getCount(), 2);
}
use of org.apache.geode.cache.client.ClientRegionFactory 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.ClientRegionFactory in project geode by apache.
the class RollingUpgrade2DUnitTest method createClientRegion.
// Assumes a client cache is passed
public static void createClientRegion(GemFireCache cache, String regionName, ClientRegionShortcut shortcut) throws Exception {
ClientRegionFactory rf = ((ClientCache) cache).createClientRegionFactory(shortcut);
rf.create(regionName);
}
use of org.apache.geode.cache.client.ClientRegionFactory 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;
}
});
}
Aggregations