use of org.apache.geode.cache.client.ClientCache 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.ClientCache in project geode by apache.
the class ClientExecuteRegionFunctionAuthDUnitTest method testExecuteRegionFunction.
@Test
public void testExecuteRegionFunction() {
FunctionService.registerFunction(function);
client1.invoke("logging in with dataReader", () -> {
ClientCache cache = createClientCache("dataReader", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
FunctionService.registerFunction(function);
assertNotAuthorized(() -> FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(function.getId()), "DATA:WRITE");
});
client2.invoke("logging in with super-user", () -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
FunctionService.registerFunction(function);
ResultCollector rc = FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(function.getId());
rc.getResult();
});
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientGetEntryAuthDUnitTest method testGetEntry.
@Test
public void testGetEntry() throws Exception {
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
transactionManager.begin();
try {
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.getEntry("key3"), "DATA:READ:AuthRegion:key3");
} finally {
transactionManager.commit();
}
});
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
transactionManager.begin();
try {
Region region = createProxyRegion(cache, REGION_NAME);
region.getEntry("key3");
} finally {
transactionManager.commit();
}
});
ai1.await();
ai2.await();
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientGetPutAuthDUnitTest method testGetPutAuthorization.
@Test
public void testGetPutAuthorization() throws InterruptedException {
Map<String, String> allValues = new HashMap<String, String>();
allValues.put("key1", "value1");
allValues.put("key2", "value2");
List<String> keys = new ArrayList<>();
keys.add("key1");
keys.add("key2");
// client1 connects to server as a user not authorized to do any operations
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.put("key3", "value3"), "DATA:WRITE:AuthRegion:key3");
assertNotAuthorized(() -> region.get("key3"), "DATA:READ:AuthRegion:key3");
// putall
assertNotAuthorized(() -> region.putAll(allValues), "DATA:WRITE:AuthRegion");
// not authorized for either keys, get no record back
Map keyValues = region.getAll(keys);
assertEquals(0, keyValues.size());
assertNotAuthorized(() -> region.keySetOnServer(), "DATA:READ:AuthRegion");
});
// client2 connects to user as a user authorized to use AuthRegion region
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key3", "value3");
assertEquals("value3", region.get("key3"));
// put all
region.putAll(allValues);
// get all
Map keyValues = region.getAll(keys);
assertEquals(2, keyValues.size());
// keyset
Set keySet = region.keySetOnServer();
assertEquals(5, keySet.size());
});
// client3 connects to user as a user authorized to use key1 in AuthRegion region
AsyncInvocation ai3 = client3.invokeAsync(() -> {
ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
assertNotAuthorized(() -> region.put("key2", "value1"), "DATA:WRITE:AuthRegion:key2");
assertNotAuthorized(() -> region.get("key2"), "DATA:READ:AuthRegion:key2");
assertNotAuthorized(() -> region.putAll(allValues), "DATA:WRITE:AuthRegion");
// only authorized for one recrod
Map keyValues = region.getAll(keys);
assertEquals(1, keyValues.size());
// keyset
assertNotAuthorized(() -> region.keySetOnServer(), "DATA:READ:AuthRegion");
});
ai1.join();
ai2.join();
ai3.join();
ai1.checkException();
ai2.checkException();
ai3.checkException();
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class ClientContainsKeyAuthDUnitTest method testContainsKey.
@Test
public void testContainsKey() throws Exception {
AsyncInvocation ai1 = client1.invokeAsync(() -> {
ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
final Region region = createProxyRegion(cache, REGION_NAME);
assertTrue(region.containsKeyOnServer("key1"));
SecurityTestUtil.assertNotAuthorized(() -> region.containsKeyOnServer("key3"), "DATA:READ:AuthRegion:key3");
});
AsyncInvocation ai2 = client2.invokeAsync(() -> {
ClientCache cache = createClientCache("authRegionReader", "1234567", server.getPort());
final Region region = createProxyRegion(cache, REGION_NAME);
region.containsKeyOnServer("key3");
assertTrue(region.containsKeyOnServer("key1"));
});
ai1.await();
ai2.await();
}
Aggregations