use of org.apache.geode.test.dunit.SerializableCallable 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.test.dunit.SerializableCallable 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.test.dunit.SerializableCallable 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.test.dunit.SerializableCallable in project geode by apache.
the class FunctionServiceStatsDUnitTest method testP2PMembersFunctionExecutionStats.
/**
* Test the execution of function on all memebers haveResults = true
*
* member1 calls for the function executions sp the results received on memeber 1 should be equal
* to the no of function execution calls. Function Execution should happen on all other members
* too. so the no of function execution calls and no of function executions completed should be
* equal tio the no of functions from member 1
*/
@Test
public void testP2PMembersFunctionExecutionStats() throws Exception {
Host host = Host.getHost(0);
VM member1 = host.getVM(0);
VM member2 = host.getVM(1);
VM member3 = host.getVM(2);
VM member4 = host.getVM(3);
SerializableCallable connectToDistributedSystem = new SerializableCallable("connectToDistributedSystem") {
public Object call() throws Exception {
Properties props = new Properties();
try {
ds = getSystem(props);
assertNotNull(ds);
} catch (Exception e) {
Assert.fail("Failed while creating the Distribued System", e);
}
return Boolean.TRUE;
}
};
member1.invoke(connectToDistributedSystem);
member2.invoke(connectToDistributedSystem);
member3.invoke(connectToDistributedSystem);
member4.invoke(connectToDistributedSystem);
member1.invoke(initializeStats);
member2.invoke(initializeStats);
member3.invoke(initializeStats);
member4.invoke(initializeStats);
final int noOfMembers = 1;
final Function inlineFunction = new FunctionAdapter() {
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else {
context.getResultSender().lastResult("Failure");
}
}
public String getId() {
return getClass().getName();
}
public boolean hasResult() {
return true;
}
};
member1.invoke(new SerializableCallable("excuteOnMembers_InlineFunction") {
public Object call() throws Exception {
assertNotNull(ds);
Execution memberExecution = null;
DistributedMember localmember = ds.getDistributedMember();
memberExecution = FunctionService.onMember(localmember);
memberExecution.setArguments("Key");
try {
ResultCollector rc = memberExecution.execute(inlineFunction);
int size = ((List) rc.getResult()).size();
resultReceived_Aggregate += size;
noOfExecutionCalls_Aggregate++;
noOfExecutionsCompleted_Aggregate++;
resultReceived_Inline += size;
noOfExecutionCalls_Inline++;
noOfExecutionsCompleted_Inline++;
} catch (Exception e) {
LogWriterUtils.getLogWriter().info("Exception Occurred : " + e.getMessage());
e.printStackTrace();
Assert.fail("Test failed", e);
}
return Boolean.TRUE;
}
});
member1.invoke(new SerializableCallable("checkFunctionExecutionStatsForMember1") {
public Object call() throws Exception {
FunctionServiceStats functionServiceStats = ds.getFunctionServiceStats();
waitNoFunctionsRunning(functionServiceStats);
assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
assertEquals(resultReceived_Aggregate, functionServiceStats.getResultsReceived());
FunctionStats functionStats = FunctionStats.getFunctionStats(inlineFunction.getId(), ds);
assertEquals(noOfExecutionCalls_Inline, functionStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Inline, functionStats.getFunctionExecutionsCompleted());
assertEquals(resultReceived_Inline, functionStats.getResultsReceived());
return Boolean.TRUE;
}
});
SerializableCallable checkFunctionExecutionStatsForOtherMember = new SerializableCallable("checkFunctionExecutionStatsForOtherMember") {
public Object call() throws Exception {
FunctionServiceStats functionServiceStats = ds.getFunctionServiceStats();
waitNoFunctionsRunning(functionServiceStats);
// One function Execution took place on there members
// noOfExecutionCalls_Aggregate++;
// noOfExecutionsCompleted_Aggregate++;
assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
FunctionStats functionStats = FunctionStats.getFunctionStats(inlineFunction.getId(), ds);
// noOfExecutionCalls_Inline++;
// noOfExecutionsCompleted_Inline++;
assertEquals(noOfExecutionCalls_Inline, functionStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Inline, functionStats.getFunctionExecutionsCompleted());
return Boolean.TRUE;
}
};
member2.invoke(checkFunctionExecutionStatsForOtherMember);
member3.invoke(checkFunctionExecutionStatsForOtherMember);
member4.invoke(checkFunctionExecutionStatsForOtherMember);
SerializableCallable closeDistributedSystem = new SerializableCallable("closeDistributedSystem") {
public Object call() throws Exception {
if (getCache() != null && !getCache().isClosed()) {
getCache().close();
getCache().getDistributedSystem().disconnect();
}
return Boolean.TRUE;
}
};
member1.invoke(closeDistributedSystem);
member2.invoke(closeDistributedSystem);
member3.invoke(closeDistributedSystem);
member4.invoke(closeDistributedSystem);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class FunctionServiceStatsDUnitTest method testP2PDistributedRegionFunctionExecutionStats.
/**
* Test the function execution statistics in case of the distributed Region P2P DataStore0 is with
* Empty datapolicy
*/
@Test
public void testP2PDistributedRegionFunctionExecutionStats() {
final String rName = getUniqueName();
Host host = Host.getHost(0);
final VM datastore0 = host.getVM(0);
final VM datastore1 = host.getVM(1);
final VM datastore2 = host.getVM(2);
final VM datastore3 = host.getVM(3);
datastore0.invoke(initializeStats);
datastore1.invoke(initializeStats);
datastore2.invoke(initializeStats);
datastore3.invoke(initializeStats);
SerializableCallable createAndPopulateRegionWithEmpty = new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
Region region = getCache().createRegion(rName, factory.create());
LogWriterUtils.getLogWriter().info("Region Created :" + region);
assertNotNull(region);
FunctionService.registerFunction(new TestFunction(true, TestFunction.TEST_FUNCTION2));
for (int i = 1; i <= 200; i++) {
region.put("execKey-" + i, new Integer(i));
}
return Boolean.TRUE;
}
};
datastore0.invoke(createAndPopulateRegionWithEmpty);
SerializableCallable createAndPopulateRegionWithReplicate = new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
Region region = getCache().createRegion(rName, factory.create());
LogWriterUtils.getLogWriter().info("Region Created :" + region);
assertNotNull(region);
FunctionService.registerFunction(new TestFunction(true, TestFunction.TEST_FUNCTION2));
for (int i = 1; i <= 200; i++) {
region.put("execKey-" + i, new Integer(i));
}
return Boolean.TRUE;
}
};
datastore1.invoke(createAndPopulateRegionWithReplicate);
datastore2.invoke(createAndPopulateRegionWithReplicate);
datastore3.invoke(createAndPopulateRegionWithReplicate);
SerializableCallable executeFunction = new SerializableCallable("ExecuteFunction from Normal Region") {
public Object call() throws Exception {
Region region = getCache().getRegion(rName);
try {
List list = (List) FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(TestFunction.TEST_FUNCTION2).getResult();
// this is the Distributed Region with Empty Data policy.
// therefore no function execution takes place here. it only receives the results.
resultReceived_Aggregate += list.size();
assertEquals(resultReceived_Aggregate, ((InternalDistributedSystem) getCache().getDistributedSystem()).getFunctionServiceStats().getResultsReceived());
resultReceived_TESTFUNCTION2 += list.size();
assertEquals(resultReceived_TESTFUNCTION2, ((InternalDistributedSystem) getCache().getDistributedSystem()).getFunctionServiceStats().getResultsReceived());
return Boolean.TRUE;
} catch (FunctionException e) {
e.printStackTrace();
Assert.fail("test failed due to", e);
return Boolean.FALSE;
} catch (Exception e) {
e.printStackTrace();
Assert.fail("test failed due to", e);
return Boolean.FALSE;
}
}
};
datastore0.invoke(executeFunction);
// there is a replicated region on 3 nodes so we cannot predict on which
// node the function execution will take place
// so i have avoided that check.
SerializableCallable closeDistributedSystem = new SerializableCallable("closeDistributedSystem") {
public Object call() throws Exception {
if (getCache() != null && !getCache().isClosed()) {
getCache().close();
getCache().getDistributedSystem().disconnect();
}
return Boolean.TRUE;
}
};
datastore0.invoke(closeDistributedSystem);
datastore1.invoke(closeDistributedSystem);
datastore2.invoke(closeDistributedSystem);
datastore3.invoke(closeDistributedSystem);
}
Aggregations