use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientSnapshotDUnitTest method loadCache.
@SuppressWarnings("serial")
public void loadCache() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
Cache cache = getCache(cf);
CacheServer server = cache.addCacheServer();
final int port = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(port);
server.start();
region = cache.<Integer, MyObject>createRegionFactory(RegionShortcut.REPLICATE).create("clienttest");
final Host host = Host.getHost(0);
SerializableCallable client = new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCacheFactory cf = new ClientCacheFactory().set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()).setPdxSerializer(new MyPdxSerializer()).addPoolServer(NetworkUtils.getServerHostName(host), port).setPoolSubscriptionEnabled(true).setPoolPRSingleHopEnabled(false);
ClientCache cache = getClientCache(cf);
Region r = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU).setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(5)).create("clienttest");
return null;
}
};
SerializableCallable remote = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
Cache cache = getCache(cf);
cache.<Integer, MyObject>createRegionFactory(RegionShortcut.REPLICATE).create("clienttest");
return null;
}
};
host.getVM(3).invoke(client);
host.getVM(2).invoke(remote);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class CQClientAuthDUnitTest method testPostProcess.
@Test
public void testPostProcess() {
String query = "select * from /" + REGION_NAME;
client1.invoke(() -> {
Properties props = new Properties();
props.setProperty(LOCATORS, "");
props.setProperty(MCAST_PORT, "0");
props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create");
ClientCacheFactory factory = new ClientCacheFactory(props);
factory.addPoolServer("localhost", server.getPort());
factory.setPoolThreadLocalConnections(false);
factory.setPoolMinConnections(5);
factory.setPoolSubscriptionEnabled(true);
factory.setPoolMultiuserAuthentication(true);
ClientCache clientCache = factory.create();
Region region = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
Pool pool = PoolManager.find(region);
Properties userProps = new Properties();
userProps.setProperty("security-username", "super-user");
userProps.setProperty("security-password", "1234567");
ProxyCache cache = (ProxyCache) clientCache.createAuthenticatedView(userProps, pool.getName());
QueryService qs = cache.getQueryService();
CqAttributesFactory cqAttributesFactory = new CqAttributesFactory();
CqAttributes cqa = cqAttributesFactory.create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa, true);
cq.execute();
});
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class CQPDXPostProcessorDUnitTest method testCQ.
@Test
public void testCQ() {
String query = "select * from /" + REGION_NAME;
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Pool pool = PoolManager.find(region);
QueryService qs = pool.getQueryService();
CqAttributesFactory factory = new CqAttributesFactory();
factory.addCqListener(new CqListenerImpl() {
@Override
public void onEvent(final CqEvent aCqEvent) {
Object key = aCqEvent.getKey();
Object value = aCqEvent.getNewValue();
if (key.equals("key1")) {
assertTrue(value instanceof SimpleClass);
} else if (key.equals("key2")) {
assertTrue(Arrays.equals(BYTES, (byte[]) value));
}
}
});
CqAttributes cqa = factory.create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa);
CqResults results = cq.executeWithInitialResults();
});
client2.invoke(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
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.ClientCache in project geode by apache.
the class CQPostProcessorDunitTest method testPostProcess.
@Test
public void testPostProcess() {
String query = "select * from /AuthRegion";
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
Pool pool = PoolManager.find(region);
QueryService qs = pool.getQueryService();
CqAttributesFactory factory = new CqAttributesFactory();
factory.addCqListener(new CqListenerImpl() {
@Override
public void onEvent(final CqEvent aCqEvent) {
assertEquals("key6", aCqEvent.getKey());
assertEquals("super-user/AuthRegion/key6/value6", aCqEvent.getNewValue());
}
});
CqAttributes cqa = factory.create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa);
CqResults results = cq.executeWithInitialResults();
assertEquals(5, results.size());
String resultString = results.toString();
assertTrue(resultString, resultString.contains("key:key0,value:super-user/null/key0/value0"));
assertTrue(resultString.contains("key:key1,value:super-user/null/key1/value1"));
assertTrue(resultString.contains("key:key2,value:super-user/null/key2/value2"));
assertTrue(resultString.contains("key:key3,value:super-user/null/key3/value3"));
assertTrue(resultString.contains("key:key4,value:super-user/null/key4/value4"));
});
client2.invoke(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key6", "value6");
});
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientQueryAuthDUnitTest method testQuery.
@Test
public void testQuery() {
client1.invoke(() -> {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
final Region region = createProxyRegion(cache, REGION_NAME);
String query = "select * from /AuthRegion";
assertNotAuthorized(() -> region.query(query), "DATA:READ:AuthRegion");
Pool pool = PoolManager.find(region);
assertNotAuthorized(() -> pool.getQueryService().newQuery(query).execute(), "DATA:READ:AuthRegion");
});
}
Aggregations