use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class FunctionServiceStatsDUnitTest method testFunctionExecutionExceptionStatsOnAllNodesPRegion.
/**
* Test the exception occurred while invoking the function execution on all members of DS
*
* Function throws the Exception, The check is added to for the no of function execution execption
* in datatostore1
*/
@Test
public void testFunctionExecutionExceptionStatsOnAllNodesPRegion() throws Exception {
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 dataStoreCreate = new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
AttributesFactory raf = new AttributesFactory(ra);
PartitionAttributesImpl pa = new PartitionAttributesImpl();
pa.setAll(ra.getPartitionAttributes());
pa.setTotalNumBuckets(17);
raf.setPartitionAttributes(pa);
getCache().createRegion(rName, raf.create());
Function function = new TestFunction(true, "TestFunctionException");
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
};
datastore0.invoke(dataStoreCreate);
datastore1.invoke(dataStoreCreate);
datastore2.invoke(dataStoreCreate);
datastore3.invoke(dataStoreCreate);
Object o = datastore3.invoke(new SerializableCallable("Create data, invoke exectuable") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
DistributedSystem.setThreadsSocketPolicy(false);
final HashSet testKeys = new HashSet();
for (int i = (pr.getTotalNumberOfBuckets() * 3); i > 0; i--) {
testKeys.add("execKey-" + i);
}
int j = 0;
for (Iterator i = testKeys.iterator(); i.hasNext(); ) {
Integer key = new Integer(j++);
pr.put(key, i.next());
}
try {
Function function = new TestFunction(true, "TestFunctionException");
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(pr);
ResultCollector rc = dataSet.setArguments(Boolean.TRUE).execute(function.getId());
// Wait Criterion is added to make sure that the function execution
// happens on all nodes and all nodes get the FunctionException so that the stats will get
// incremented,
WaitCriterion wc = new WaitCriterion() {
String excuse;
public boolean done() {
return false;
}
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 20000, 1000, false);
rc.getResult();
} catch (Exception expected) {
return Boolean.TRUE;
}
fail("No exception Occurred");
return Boolean.FALSE;
}
});
assertEquals(Boolean.TRUE, o);
SerializableCallable checkFunctionExecutionStatsForDataStore = new SerializableCallable("checkFunctionExecutionStatsForDataStore") {
public Object call() throws Exception {
FunctionStats functionStats = FunctionStats.getFunctionStats("TestFunctionException", getSystem());
noOfExecutionCalls_TestFunctionException++;
noOfExecutionExceptions_TestFunctionException++;
assertEquals(noOfExecutionCalls_TestFunctionException, functionStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_TestFunctionException, functionStats.getFunctionExecutionsCompleted());
assertEquals(noOfExecutionExceptions_TestFunctionException, functionStats.getFunctionExecutionExceptions());
noOfExecutionCalls_Aggregate++;
noOfExecutionExceptions_Aggregate++;
FunctionServiceStats functionServiceStats = ((InternalDistributedSystem) getCache().getDistributedSystem()).getFunctionServiceStats();
assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
assertEquals(noOfExecutionExceptions_Aggregate, functionServiceStats.getFunctionExecutionExceptions());
return Boolean.TRUE;
}
};
/*
* datastore0.invoke(checkFunctionExecutionStatsForDataStore);
* datastore1.invoke(checkFunctionExecutionStatsForDataStore);
* datastore2.invoke(checkFunctionExecutionStatsForDataStore);
* datastore3.invoke(checkFunctionExecutionStatsForDataStore);
*/
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);
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class FunctionServiceStatsDUnitTest method testP2PPartitionedRegionsFunctionExecutionStats.
/**
* Ensure that the execution is happening all the PR as a whole
*
* Function Execution will not take place on accessor, accessor will onlu receive the
* resultsReceived. On datastore, no of function execution calls should be equal to the no of
* function execution calls from the accessor.
*/
@Test
public void testP2PPartitionedRegionsFunctionExecutionStats() throws Exception {
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 accessor = host.getVM(3);
datastore0.invoke(initializeStats);
datastore1.invoke(initializeStats);
datastore2.invoke(initializeStats);
accessor.invoke(initializeStats);
accessor.invoke(new SerializableCallable("Create PR") {
public Object call() throws Exception {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 0);
AttributesFactory raf = new AttributesFactory(ra);
PartitionAttributesImpl pa = new PartitionAttributesImpl();
pa.setAll(ra.getPartitionAttributes());
pa.setTotalNumBuckets(17);
raf.setPartitionAttributes(pa);
PartitionedRegion pr = (PartitionedRegion) getCache().createRegion(rName, raf.create());
return Boolean.TRUE;
}
});
SerializableCallable dataStoreCreate = new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
AttributesFactory raf = new AttributesFactory(ra);
PartitionAttributesImpl pa = new PartitionAttributesImpl();
pa.setAll(ra.getPartitionAttributes());
pa.setTotalNumBuckets(17);
raf.setPartitionAttributes(pa);
PartitionedRegion pr = (PartitionedRegion) getCache().createRegion(rName, raf.create());
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION2);
FunctionService.registerFunction(function);
function = new TestFunction(true, TestFunction.TEST_FUNCTION3);
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
};
datastore0.invoke(dataStoreCreate);
datastore1.invoke(dataStoreCreate);
datastore2.invoke(dataStoreCreate);
accessor.invoke(new SerializableCallable("Create data, invoke exectuable") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
DistributedSystem.setThreadsSocketPolicy(false);
final HashSet testKeys = new HashSet();
for (int i = (pr.getTotalNumberOfBuckets() * 3); i > 0; i--) {
testKeys.add("execKey-" + i);
}
int j = 0;
for (Iterator i = testKeys.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
pr.put(i.next(), val);
}
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION2);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(pr);
ResultCollector rc1 = dataSet.setArguments(Boolean.TRUE).execute(function);
int size = ((List) rc1.getResult()).size();
resultReceived_Aggregate += size;
resultReceived_TESTFUNCTION2 += size;
rc1 = dataSet.setArguments(testKeys).execute(function);
size = ((List) rc1.getResult()).size();
resultReceived_Aggregate += size;
resultReceived_TESTFUNCTION2 += size;
function = new TestFunction(true, TestFunction.TEST_FUNCTION3);
FunctionService.registerFunction(function);
rc1 = dataSet.setArguments(Boolean.TRUE).execute(function);
size = ((List) rc1.getResult()).size();
resultReceived_Aggregate += size;
resultReceived_TESTFUNCTION3 += size;
return Boolean.TRUE;
}
});
accessor.invoke(new SerializableCallable("checkFunctionExecutionStatsForAccessor") {
public Object call() throws Exception {
InternalDistributedSystem iDS = ((InternalDistributedSystem) getCache().getDistributedSystem());
FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
waitNoFunctionsRunning(functionServiceStats);
assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
assertEquals(resultReceived_Aggregate, functionServiceStats.getResultsReceived());
FunctionStats functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION2, iDS);
assertEquals(noOfExecutionCalls_TESTFUNCTION2, functionStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_TESTFUNCTION2, functionStats.getFunctionExecutionsCompleted());
assertEquals(resultReceived_TESTFUNCTION2, functionStats.getResultsReceived());
functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION3, iDS);
assertEquals(noOfExecutionCalls_TESTFUNCTION3, functionStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_TESTFUNCTION3, functionStats.getFunctionExecutionsCompleted());
assertEquals(resultReceived_TESTFUNCTION3, functionStats.getResultsReceived());
return Boolean.TRUE;
}
});
SerializableCallable checkFunctionExecutionStatsForDataStore = new SerializableCallable("checkFunctionExecutionStatsForDataStore") {
public Object call() throws Exception {
InternalDistributedSystem iDS = ((InternalDistributedSystem) getCache().getDistributedSystem());
// 3 Function Executions took place
FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
waitNoFunctionsRunning(functionServiceStats);
noOfExecutionCalls_Aggregate += 3;
noOfExecutionsCompleted_Aggregate += 3;
assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
FunctionStats functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION2, iDS);
// TEST_FUNCTION2 is executed twice
noOfExecutionCalls_TESTFUNCTION2 += 2;
assertEquals(noOfExecutionCalls_TESTFUNCTION2, functionStats.getFunctionExecutionCalls());
noOfExecutionsCompleted_TESTFUNCTION2 += 2;
assertEquals(noOfExecutionsCompleted_TESTFUNCTION2, functionStats.getFunctionExecutionsCompleted());
functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION3, iDS);
// TEST_FUNCTION3 is executed once
noOfExecutionCalls_TESTFUNCTION3 += 1;
assertEquals(noOfExecutionCalls_TESTFUNCTION3, functionStats.getFunctionExecutionCalls());
noOfExecutionsCompleted_TESTFUNCTION3 += 1;
assertEquals(noOfExecutionsCompleted_TESTFUNCTION3, functionStats.getFunctionExecutionsCompleted());
return Boolean.TRUE;
}
};
datastore0.invoke(checkFunctionExecutionStatsForDataStore);
datastore1.invoke(checkFunctionExecutionStatsForDataStore);
datastore2.invoke(checkFunctionExecutionStatsForDataStore);
SerializableCallable closeDistributedSystem = new SerializableCallable("closeDistributedSystem") {
public Object call() throws Exception {
if (getCache() != null && !getCache().isClosed()) {
getCache().close();
getCache().getDistributedSystem().disconnect();
}
return Boolean.TRUE;
}
};
accessor.invoke(closeDistributedSystem);
datastore0.invoke(closeDistributedSystem);
datastore1.invoke(closeDistributedSystem);
datastore2.invoke(closeDistributedSystem);
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class FunctionExecution_ExceptionDUnitTest method testRemoteAllKeyExecution_SendException.
@Test
public void testRemoteAllKeyExecution_SendException() throws Exception {
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);
getCache();
SerializableCallable dataStoreCreate = new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
AttributesFactory raf = new AttributesFactory(ra);
PartitionAttributesImpl pa = new PartitionAttributesImpl();
pa.setAll(ra.getPartitionAttributes());
raf.setPartitionAttributes(pa);
getCache().createRegion(rName, raf.create());
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SEND_EXCEPTION);
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
};
datastore0.invoke(dataStoreCreate);
datastore1.invoke(dataStoreCreate);
datastore2.invoke(dataStoreCreate);
datastore3.invoke(dataStoreCreate);
Object o = datastore0.invoke(new SerializableCallable("Create data, invoke exectuable") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SEND_EXCEPTION);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(pr);
HashSet origVals = new HashSet();
for (int i = 0; i < 4; i++) {
Integer val = new Integer(i);
origVals.add(val);
pr.put(val, "MyValue_" + i);
}
ResultCollector rc2 = null;
ResultCollector rs1 = dataSet.withFilter(origVals).setArguments((Serializable) origVals).execute(function);
List results = (ArrayList) rs1.getResult();
assertEquals(((origVals.size() * 4) + 4), results.size());
Iterator resultIterator = results.iterator();
int exceptionCount = 0;
while (resultIterator.hasNext()) {
Object o = resultIterator.next();
if (o instanceof MyFunctionExecutionException) {
exceptionCount++;
}
}
assertEquals(4, exceptionCount);
return Boolean.TRUE;
}
});
assertEquals(Boolean.TRUE, o);
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class FunctionExecution_ExceptionDUnitTest method testRemoteSingleKeyExecution_ThrowException_Accessor.
@Test
public void testRemoteSingleKeyExecution_ThrowException_Accessor() throws Exception {
final String rName = getUniqueName();
Host host = Host.getHost(0);
final VM accessor = host.getVM(2);
final VM datastore = host.getVM(3);
getCache();
accessor.invoke(new SerializableCallable("Create PR") {
public Object call() throws Exception {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 0);
getCache().createRegion(rName, ra);
return Boolean.TRUE;
}
});
datastore.invoke(new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
AttributesFactory raf = new AttributesFactory(ra);
PartitionAttributesImpl pa = new PartitionAttributesImpl();
pa.setAll(ra.getPartitionAttributes());
raf.setPartitionAttributes(pa);
getCache().createRegion(rName, raf.create());
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_THROW_EXCEPTION);
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
});
Object o = accessor.invoke(new SerializableCallable("Create data, invoke exectuable") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
final String testKey = "execKey";
final Set testKeysSet = new HashSet();
testKeysSet.add(testKey);
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_THROW_EXCEPTION);
FunctionService.registerFunction(function);
// DefaultResultCollector rs = new DefaultResultCollector();
// .withCollector(rs);
Execution dataSet = FunctionService.onRegion(pr);
pr.put(testKey, new Integer(1));
ResultCollector rs1 = null;
rs1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function);
try {
ArrayList results = (ArrayList) rs1.getResult();
fail("Expecting Exception");
} catch (Exception e) {
e.printStackTrace();
return Boolean.TRUE;
}
return Boolean.FALSE;
}
});
assertEquals(Boolean.TRUE, o);
}
use of org.apache.geode.internal.cache.PartitionAttributesImpl in project geode by apache.
the class FunctionExecution_ExceptionDUnitTest method testRemoteAllKeyExecution_ThrowException.
@Test
public void testRemoteAllKeyExecution_ThrowException() throws Exception {
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);
getCache();
SerializableCallable dataStoreCreate = new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
RegionAttributes ra = PartitionedRegionTestHelper.createRegionAttrsForPR(0, 10);
AttributesFactory raf = new AttributesFactory(ra);
PartitionAttributesImpl pa = new PartitionAttributesImpl();
pa.setAll(ra.getPartitionAttributes());
raf.setPartitionAttributes(pa);
getCache().createRegion(rName, raf.create());
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_THROW_EXCEPTION);
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
};
datastore0.invoke(dataStoreCreate);
datastore1.invoke(dataStoreCreate);
datastore2.invoke(dataStoreCreate);
datastore3.invoke(dataStoreCreate);
Object o = datastore0.invoke(new SerializableCallable("Create data, invoke exectuable") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_THROW_EXCEPTION);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(pr);
HashSet origVals = new HashSet();
for (int i = 0; i < 4; i++) {
Integer val = new Integer(i);
origVals.add(val);
pr.put(val, "MyValue_" + i);
}
ResultCollector rc2 = null;
rc2 = dataSet.withFilter(origVals).setArguments(origVals).execute(function.getId());
try {
ArrayList results = (ArrayList) rc2.getResult();
fail("Expecting Exception");
} catch (Exception e) {
e.printStackTrace();
return Boolean.TRUE;
}
return Boolean.FALSE;
}
});
assertEquals(Boolean.TRUE, o);
}
Aggregations