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;
}
});
}
use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.
the class PRFunctionExecutionDUnitTest method testRemoteMultiKeyExecution_BucketMoved.
@Test
public void testRemoteMultiKeyExecution_BucketMoved() 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 {
AttributesFactory factory = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setTotalNumBuckets(113);
paf.setLocalMaxMemory(0);
paf.setRedundantCopies(1);
paf.setStartupRecoveryDelay(0);
PartitionAttributes partitionAttributes = paf.create();
factory.setDataPolicy(DataPolicy.PARTITION);
factory.setPartitionAttributes(partitionAttributes);
RegionAttributes attrs = factory.create();
getCache().createRegion(rName, attrs);
return Boolean.TRUE;
}
});
SerializableCallable dataStoreCreate = new SerializableCallable("Create PR with Function Factory") {
public Object call() throws Exception {
AttributesFactory factory = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setTotalNumBuckets(113);
paf.setLocalMaxMemory(40);
paf.setRedundantCopies(1);
paf.setStartupRecoveryDelay(0);
PartitionAttributes partitionAttributes = paf.create();
factory.setDataPolicy(DataPolicy.PARTITION);
factory.setPartitionAttributes(partitionAttributes);
RegionAttributes attrs = factory.create();
getCache().createRegion(rName, attrs);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_LASTRESULT);
FunctionService.registerFunction(function);
return Boolean.TRUE;
}
};
datastore0.invoke(dataStoreCreate);
datastore1.invoke(dataStoreCreate);
SerializableCallable put = new SerializableCallable("put in PR") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
for (int i = 0; i < 113; i++) {
pr.put(i, "execKey-" + i);
}
return Boolean.TRUE;
}
};
accessor.invoke(put);
datastore2.invoke(dataStoreCreate);
Object result = accessor.invoke(new SerializableCallable("invoke exectuable") {
public Object call() throws Exception {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_LASTRESULT);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(pr);
ResultCollector rc2 = dataSet.setArguments(Boolean.TRUE).execute(function.getId());
List l = ((List) rc2.getResult());
return l;
}
});
List l = (List) result;
assertEquals(2, l.size());
}
Aggregations