use of org.apache.geode.cache.execute.Execution in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverMultiKeyExecutionSocketTimeOut.
public static void serverMultiKeyExecutionSocketTimeOut(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
region.put(i.next(), val);
}
List l = null;
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
l = ((List) rc1.getResult());
LogWriterUtils.getLogWriter().info("Result size : " + l.size());
assertEquals(3, l.size());
for (Iterator i = l.iterator(); i.hasNext(); ) {
assertEquals(Boolean.TRUE, i.next());
}
} catch (Exception e) {
Assert.fail("Test failed after the function execution", e);
}
}
use of org.apache.geode.cache.execute.Execution in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverSingleKeyExecutionSocketTimeOut.
public static void serverSingleKeyExecutionSocketTimeOut(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final String testKey = "execKey";
final Set testKeysSet = new HashSet();
testKeysSet.add(testKey);
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
region.put(testKey, new Integer(1));
try {
ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0));
ResultCollector rs2 = execute(dataSet, testKeysSet, testKey, function, isByName);
assertEquals(testKey, ((List) rs2.getResult()).get(0));
} catch (Exception ex) {
ex.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : ", ex);
Assert.fail("Test failed after the put operation", ex);
}
}
use of org.apache.geode.cache.execute.Execution in project geode by apache.
the class PRFunctionExecutionDUnitTest method testRemoteMultiKeyExecutionNoResult_byName.
/**
* Test multi-key remote execution by a pure accessor which doesn't have the function factory
* present. ResultCollector = DefaultResultCollector haveResults = false;
*/
@Test
public void testRemoteMultiKeyExecutionNoResult_byName() 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);
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(false, TEST_FUNCTION7);
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() {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
final HashSet testKeysSet = new HashSet();
for (int i = (pr.getTotalNumberOfBuckets() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(false, TEST_FUNCTION7);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(pr);
int j = 0;
HashSet origVals = new HashSet();
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
origVals.add(val);
pr.put(i.next(), val);
}
ResultCollector rs;
try {
rs = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
rs.getResult();
} catch (Exception expected) {
expected.printStackTrace();
assertTrue(expected.getMessage().startsWith(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("return any")));
return Boolean.TRUE;
}
return Boolean.FALSE;
}
});
assertEquals(Boolean.TRUE, o);
}
use of org.apache.geode.cache.execute.Execution in project geode by apache.
the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method serverMultiKeyExecutionOnASingleBucket.
public static void serverMultiKeyExecutionOnASingleBucket(Boolean isByName) {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 2); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
int j = 0;
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
region.put(i.next(), val);
}
DistributedSystem.setThreadsSocketPolicy(false);
for (Iterator kiter = testKeysSet.iterator(); kiter.hasNext(); ) {
try {
Set singleKeySet = Collections.singleton(kiter.next());
Function function = new TestFunction(true, TEST_FUNCTION2);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
ResultCollector rc1 = execute(dataSet, singleKeySet, Boolean.TRUE, function, isByName);
List l = null;
l = ((List) rc1.getResult());
assertEquals(1, l.size());
ResultCollector rc2 = execute(dataSet, singleKeySet, new HashSet(singleKeySet), function, isByName);
List l2 = null;
l2 = ((List) rc2.getResult());
assertEquals(1, l2.size());
List subList = (List) l2.iterator().next();
assertEquals(1, subList.size());
assertEquals(region.get(singleKeySet.iterator().next()), subList.iterator().next());
} catch (Exception expected) {
LogWriterUtils.getLogWriter().info("Exception : " + expected.getMessage());
expected.printStackTrace();
fail("Test failed after the put operation");
}
}
}
use of org.apache.geode.cache.execute.Execution in project geode by apache.
the class ExecuteFunction70 method executeFunctionOnGroups.
@Override
protected void executeFunctionOnGroups(Object function, Object args, String[] groups, boolean allMembers, Function functionObject, ServerToClientFunctionResultSender resultSender, boolean ignoreFailedMembers) {
DistributedSystem ds = InternalDistributedSystem.getConnectedInstance();
if (ds == null) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_DS_NOT_CREATED_OR_NOT_READY.toLocalizedString());
}
Set<DistributedMember> members = new HashSet<DistributedMember>();
for (String group : groups) {
if (allMembers) {
members.addAll(ds.getGroupMembers(group));
} else {
ArrayList<DistributedMember> memberList = new ArrayList<DistributedMember>(ds.getGroupMembers(group));
if (!memberList.isEmpty()) {
if (!FunctionServiceManager.RANDOM_onMember && memberList.contains(ds.getDistributedMember())) {
members.add(ds.getDistributedMember());
} else {
Collections.shuffle(memberList);
members.add(memberList.get(0));
}
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Executing Function on Groups: {} all members: {} members are: {}", Arrays.toString(groups), allMembers, members);
}
Execution execution = new MemberFunctionExecutor(ds, members, resultSender);
if (args != null) {
execution = execution.setArguments(args);
}
if (ignoreFailedMembers) {
if (logger.isDebugEnabled()) {
logger.debug("Function will ignore failed members");
}
((AbstractExecution) execution).setIgnoreDepartedMembers(true);
}
if (!functionObject.isHA()) {
((AbstractExecution) execution).setWaitOnExceptionFlag(true);
}
if (function instanceof String) {
execution.execute(functionObject.getId()).getResult();
} else {
execution.execute(functionObject).getResult();
}
}
Aggregations