use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class FunctionExecution_ExceptionDUnitTest method testRemoteMultiKeyExecution_SendException.
@Test
public void testRemoteMultiKeyExecution_SendException() throws Exception {
final String rName = getUniqueName();
Host host = Host.getHost(0);
final VM accessor = host.getVM(3);
final VM datastore0 = host.getVM(0);
final VM datastore1 = host.getVM(1);
final VM datastore2 = host.getVM(2);
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;
}
});
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);
Object o = accessor.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 < 3; i++) {
Integer val = new Integer(i);
origVals.add(val);
pr.put(val, "MyValue_" + i);
}
ResultCollector rs1 = dataSet.withFilter(origVals).setArguments((Serializable) origVals).execute(function);
List results = (ArrayList) rs1.getResult();
assertEquals(((origVals.size() * 3) + 3), results.size());
Iterator resultIterator = results.iterator();
int exceptionCount = 0;
while (resultIterator.hasNext()) {
Object o = resultIterator.next();
if (o instanceof MyFunctionExecutionException) {
exceptionCount++;
}
}
assertEquals(3, exceptionCount);
return Boolean.TRUE;
}
});
assertEquals(Boolean.TRUE, o);
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class FunctionExecution_ExceptionDUnitTest method testSingleKeyExecution_SendException_Datastore.
@Test
public void testSingleKeyExecution_SendException_Datastore() throws Exception {
final String rName = getUniqueName();
Host host = Host.getHost(0);
final VM datastore = host.getVM(3);
getCache();
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_SEND_EXCEPTION);
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
});
Object o = datastore.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_SEND_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);
ArrayList results = (ArrayList) rs1.getResult();
assertTrue(results.get(0) instanceof Exception);
rs1 = dataSet.withFilter(testKeysSet).setArguments((Serializable) testKeysSet).execute(function);
results = (ArrayList) rs1.getResult();
assertEquals((testKeysSet.size() + 1), results.size());
Iterator resultIterator = results.iterator();
int exceptionCount = 0;
while (resultIterator.hasNext()) {
Object o = resultIterator.next();
if (o instanceof MyFunctionExecutionException) {
exceptionCount++;
}
}
assertEquals(1, exceptionCount);
return Boolean.TRUE;
}
});
assertEquals(Boolean.TRUE, o);
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method checkBucketsOnServer.
public static void checkBucketsOnServer() {
PartitionedRegion region = (PartitionedRegion) cache.getRegion(PartitionedRegionName);
HashMap localBucket2RegionMap = (HashMap) region.getDataStore().getSizeLocally();
LogWriterUtils.getLogWriter().info("Size of the " + PartitionedRegionName + " in this VM :- " + localBucket2RegionMap.size());
Set entrySet = localBucket2RegionMap.entrySet();
assertNotNull(entrySet);
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class PRClientServerRegionFunctionExecutionDUnitTest method checkBucketsOnServer.
public static void checkBucketsOnServer() {
PartitionedRegion region = (PartitionedRegion) cache.getRegion(PartitionedRegionName);
HashMap localBucket2RegionMap = (HashMap) region.getDataStore().getSizeLocally();
LogWriterUtils.getLogWriter().info("Size of the " + PartitionedRegionName + " in this VM :- " + localBucket2RegionMap.size());
Set entrySet = localBucket2RegionMap.entrySet();
assertNotNull(entrySet);
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class FetchEntryMessageTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
FetchEntryMessage mockFetchEntryMessage = mock(FetchEntryMessage.class);
DistributionManager mockDistributionManager = mock(DistributionManager.class);
PartitionedRegion mockPartitionedRegion = mock(PartitionedRegion.class);
long startTime = System.currentTimeMillis();
Object key = new Object();
when(mockFetchEntryMessage.operateOnPartitionedRegion(eq(mockDistributionManager), eq(mockPartitionedRegion), eq(startTime))).thenReturn(true);
mockFetchEntryMessage.setKey(key);
verify(mockFetchEntryMessage, times(1)).setKey(key);
assertThat(mockFetchEntryMessage.operateOnPartitionedRegion(mockDistributionManager, mockPartitionedRegion, startTime)).isTrue();
}
Aggregations