use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method serverMultiKeyExecutionNoResult.
public static void serverMultiKeyExecutionNoResult(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(false, TEST_FUNCTION7);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
String msg = "<ExpectedException action=add>" + "FunctionException" + "</ExpectedException>";
cache.getLogger().info(msg);
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);
}
ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName);
rc1.getResult();
Thread.sleep(20000);
fail("Test failed after the put operation");
} catch (FunctionException expected) {
expected.printStackTrace();
LogWriterUtils.getLogWriter().info("Exception : " + expected.getMessage());
assertTrue(expected.getMessage().startsWith((LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("return any"))));
} catch (Exception notexpected) {
Assert.fail("Test failed during execute or sleeping", notexpected);
} finally {
cache.getLogger().info("<ExpectedException action=remove>" + "FunctionException" + "</ExpectedException>");
}
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class ClientServerFunctionExecutionDUnitTest method testServerExecution_byName_WithoutRegister.
@Test
public void testServerExecution_byName_WithoutRegister() {
createScenario();
// function = new TestFunction1();
function = new TestFunction(true, TEST_FUNCTION1);
registerFunctionAtServer(function);
isByName = new Boolean(true);
toRegister = new Boolean(false);
LogWriterUtils.getLogWriter().info("ClientServerFFunctionExecutionDUnitTest#testServerSingleKeyExecution_byName : Starting test");
client.invoke(() -> ClientServerFunctionExecutionDUnitTest.serverExecution(isByName, function, toRegister));
client.invoke(() -> ClientServerFunctionExecutionDUnitTest.allServerExecution(isByName, function, toRegister));
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class ClientServerFunctionExecutionDUnitTest method testServerExecution_byName.
/*
* Execution of the function on server using the name of the function
*/
@Test
public void testServerExecution_byName() {
createScenario();
// function = new TestFunction1();
function = new TestFunction(true, TEST_FUNCTION1);
registerFunctionAtServer(function);
isByName = new Boolean(true);
toRegister = new Boolean(true);
LogWriterUtils.getLogWriter().info("ClientServerFFunctionExecutionDUnitTest#testServerSingleKeyExecution_byName : Starting test");
client.invoke(() -> ClientServerFunctionExecutionDUnitTest.serverExecution(isByName, function, toRegister));
client.invoke(() -> ClientServerFunctionExecutionDUnitTest.allServerExecution(isByName, function, toRegister));
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class ClientServerFunctionExecutionDUnitTest method testOnServerFailoverWithTwoServerDownHA.
@SuppressWarnings("rawtypes")
@Test
public void testOnServerFailoverWithTwoServerDownHA() throws InterruptedException {
// The test code appears to trigger this because the first
// call to the function disconnects from the DS but does not call
// last result;
IgnoredException.addIgnoredException("Socket Closed");
IgnoredException.addIgnoredException("did not send last result");
createScenario();
server1.invoke(() -> ClientServerFunctionExecutionDUnitTest.createReplicatedRegion());
server2.invoke(() -> ClientServerFunctionExecutionDUnitTest.createReplicatedRegion());
server3.invoke(() -> ClientServerFunctionExecutionDUnitTest.createReplicatedRegion());
client.invoke(() -> ClientServerFunctionExecutionDUnitTest.createProxyRegion(NetworkUtils.getServerHostName(server1.getHost())));
function = new TestFunction(true, TestFunction.TEST_FUNCTION_HA_SERVER);
registerFunctionAtServer(function);
client.invoke(() -> ClientServerFunctionExecutionDUnitTest.serverExecutionHATwoServerDown(Boolean.FALSE, function, Boolean.FALSE));
client.invoke(() -> ClientServerFunctionExecutionDUnitTest.verifyMetaData(new Integer(2), new Integer(0)));
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class PRFunctionExecutionDUnitTest method testRemoteSingleKeyExecution_byName_FunctionInvocationTargetException.
/**
* Test remote execution by a pure accessor which doesn't have the function factory
* present.Function throws the FunctionInvocationTargetException. As this is the case of HA then
* system should retry the function execution. After 5th attempt function will send Boolean as
* last result.
*/
@Test
public void testRemoteSingleKeyExecution_byName_FunctionInvocationTargetException() 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_REEXECUTE_EXCEPTION);
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
});
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_REEXECUTE_EXCEPTION);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(pr);
pr.put(testKey, new Integer(1));
try {
ResultCollector rs1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
List list = (ArrayList) rs1.getResult();
assertEquals(list.get(0), 5);
} catch (Throwable e) {
e.printStackTrace();
Assert.fail("This is not expected Exception", e);
}
return Boolean.TRUE;
}
});
}
Aggregations