use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ShutdownAllDUnitTest method getBucketList.
protected Set<Integer> getBucketList(VM vm, final String regionName) {
SerializableCallable getBuckets = new SerializableCallable("get buckets") {
public Object call() throws Exception {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
if (region instanceof PartitionedRegion) {
PartitionedRegion pr = (PartitionedRegion) region;
return new TreeSet<Integer>(pr.getDataStore().getAllLocalBucketIds());
} else {
return null;
}
}
};
return (Set<Integer>) vm.invoke(getBuckets);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testNonPersistentProxy.
@Test
public void testNonPersistentProxy() {
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
VM vm3 = host.getVM(2);
final String regionName = getName();
SerializableCallable createAccessor = new SerializableCallable() {
@Override
public Object call() throws Exception {
getCache().createRegionFactory(RegionShortcut.PARTITION_PROXY).create(regionName);
return null;
}
};
vm1.invoke(createAccessor);
vm2.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
Region r = getCache().createRegionFactory(RegionShortcut.PARTITION_PERSISTENT).create(regionName);
assertTrue(r.getAttributes().getConcurrencyChecksEnabled());
return null;
}
});
vm3.invoke(createAccessor);
SerializableCallable verifyConcurrencyChecks = new SerializableCallable() {
@Override
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
assertTrue(r.getAttributes().getConcurrencyChecksEnabled());
return null;
}
};
vm1.invoke(verifyConcurrencyChecks);
vm3.invoke(verifyConcurrencyChecks);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testCloseDuringRegionOperation.
@Test
public void testCloseDuringRegionOperation() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
createPR(vm0, 1, -1, 1);
createPR(vm1, 1, -1, 1);
// Make sure we create a bucket
createData(vm1, 0, 1, "a");
// Try to make sure there are some operations in flight while closing the cache
SerializableCallable createData = new SerializableCallable() {
public Object call() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
int i = 0;
while (true) {
try {
region.put(0, i);
i++;
} catch (CacheClosedException e) {
break;
}
}
return i - 1;
}
};
AsyncInvocation asyncCreate = vm0.invokeAsync(createData);
SerializableCallable waitForIntValue = new SerializableCallable() {
public Object call() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
// The value is initialized as a String so wait
// for it to be changed to an Integer.
await().atMost(60, SECONDS).until(() -> {
return region.get(0) instanceof Integer;
});
return region.get(0);
}
};
vm0.invoke(waitForIntValue);
vm1.invoke(waitForIntValue);
AsyncInvocation close0 = closeCacheAsync(vm0);
AsyncInvocation close1 = closeCacheAsync(vm1);
// wait for the close to finish
close0.getResult();
close1.getResult();
Integer lastSuccessfulInt = (Integer) asyncCreate.getResult();
System.err.println("Cache was closed on integer " + lastSuccessfulInt);
AsyncInvocation create1 = createPRAsync(vm0, 1, -1, 1);
AsyncInvocation create2 = createPRAsync(vm1, 1, -1, 1);
create1.getResult(MAX_WAIT);
create2.getResult(MAX_WAIT);
SerializableCallable getValue = new SerializableCallable() {
public Object call() {
Cache cache = getCache();
Region region = cache.getRegion(PR_REGION_NAME);
int value = (Integer) region.get(0);
return value;
}
};
int vm1Value = (Integer) vm0.invoke(getValue);
int vm2Value = (Integer) vm1.invoke(getValue);
assertEquals(vm1Value, vm2Value);
assertTrue("value = " + vm1Value + ", lastSuccessfulInt=" + lastSuccessfulInt, vm1Value == lastSuccessfulInt || vm1Value == lastSuccessfulInt + 1);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class PersistentPartitionedRegionTestBase method moveBucket.
protected boolean moveBucket(final int bucketId, VM source, VM target) {
SerializableCallable getId = new SerializableCallable("Get Id") {
public Object call() throws Exception {
Cache cache = getCache();
return cache.getDistributedSystem().getDistributedMember();
}
};
final InternalDistributedMember sourceId = (InternalDistributedMember) source.invoke(getId);
SerializableCallable move = new SerializableCallable("move bucket") {
public Object call() {
Cache cache = getCache();
PartitionedRegion region = (PartitionedRegion) cache.getRegion(PR_REGION_NAME);
return region.getDataStore().moveBucket(bucketId, sourceId, false);
}
};
return (Boolean) target.invoke(move);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class PersistentPartitionedRegionTestBase method backup.
// used for above test
protected BackupStatus backup(VM vm) {
return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members") {
public Object call() {
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
adminDS.waitToBeConnected(MAX_WAIT);
return adminDS.backupAllMembers(getBackupDir());
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
}
Aggregations