use of org.apache.geode.cache.Cache in project geode by apache.
the class SizingFlagDUnitTest method getEvictions.
private long getEvictions(VM vm0) {
return (Long) vm0.invoke(new SerializableCallable() {
public Object call() {
Cache cache = getCache();
LocalRegion region = (LocalRegion) cache.getRegion("region");
return getEvictions(region);
}
});
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class SingleHopStatsDUnitTest method closeCacheAndDisconnect.
private void closeCacheAndDisconnect() {
try {
Cache cache = CacheFactory.getAnyInstance();
if (cache != null && !cache.isClosed()) {
cache.close();
cache.getDistributedSystem().disconnect();
}
} catch (CacheClosedException e) {
}
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class SizingFlagDUnitTest method prHostsBucketForKey.
private boolean prHostsBucketForKey(VM vm, final Object key) {
Boolean result = (Boolean) vm.invoke(new SerializableCallable("prHostsBucketForKey") {
public Object call() {
Cache cache = getCache();
DistributedMember myId = cache.getDistributedSystem().getDistributedMember();
Region region = cache.getRegion("region");
DistributedMember hostMember = PartitionRegionHelper.getPrimaryMemberForKey(region, key);
if (hostMember == null) {
throw new IllegalStateException("bucket for key " + key + " is not hosted!");
}
boolean res = Boolean.valueOf(myId.equals(hostMember));
// cache.getLogger().info("DEBUG prHostsBucketForKey=" + res);
return res;
}
});
return result.booleanValue();
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class SizingFlagDUnitTest method getObjectSizerInvocations.
private int getObjectSizerInvocations(VM vm0) {
return (Integer) vm0.invoke(new SerializableCallable() {
public Object call() {
Cache cache = getCache();
LocalRegion region = (LocalRegion) cache.getRegion("region");
return getObjectSizerInvocations(region);
}
});
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testStreamingClientServerFunction.
@Test
public void testStreamingClientServerFunction() {
Host host = Host.getHost(0);
VM server0 = host.getVM(0);
VM server1 = host.getVM(1);
VM server2 = host.getVM(2);
VM client = host.getVM(3);
VM locator = Host.getLocator();
final String regionName = getName();
initVM(server0, "mg,g0", regionName, true);
initVM(server1, "g1", regionName, true);
initVM(server2, "g0,g1", regionName, true);
final int locatorPort = getLocatorPort(locator);
final String hostName = host.getHostName();
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
try {
Cache c = CacheFactory.getAnyInstance();
c.close();
} catch (CacheClosedException cce) {
}
disconnectFromDS();
LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolLocator(hostName, locatorPort);
ccf.setPoolServerGroup("mg");
ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
ClientCache c = ccf.create();
c.getLogger().info("SWAP:invoking function from client on g0");
Execution e = InternalFunctionService.onServers(c, "g0");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(10, sum);
return null;
}
});
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
c.getLogger().fine("SWAP:invoking function from client on mg");
Execution e = InternalFunctionService.onServers(c, "mg");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(5, sum);
return null;
}
});
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
c.getLogger().fine("SWAP:invoking function from client on g0 g1");
Execution e = InternalFunctionService.onServers(c, "g0", "g1");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(15, sum);
return null;
}
});
}
Aggregations