Search in sources :

Example 46 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class PRClientServerRegionFunctionExecutionFailoverDUnitTest method testOnRegionFailoverNonHASingleHop.

/*
   * Ensure that the while executing the function if the servers are down then the execution
   * shouldn't failover to other available server
   */
@Test
public void testOnRegionFailoverNonHASingleHop() throws InterruptedException {
    // See #47489
    // before enabling
    // it
    ArrayList commonAttributes = createCommonServerAttributes("TestPartitionedRegion", null, 0, 13, null);
    createClientServerScenarioSingleHop(commonAttributes, 20, 20, 20);
    server1.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createReplicatedRegion());
    server2.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createReplicatedRegion());
    server3.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createReplicatedRegion());
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.createProxyRegion(NetworkUtils.getServerHostName(server1.getHost())));
    // Make sure the buckets are created.
    client.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            region = (LocalRegion) cache.getRegion(PRClientServerTestBase.PartitionedRegionName);
            for (int i = 0; i < 13; i++) {
                region.put(i, i);
            }
        }
    });
    // Make sure the client metadata is up to date.
    client.invoke(() -> PRClientServerRegionFunctionExecutionFailoverDUnitTest.fetchMetaData());
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_NONHA_REGION);
    registerFunctionAtServer(function);
    final Function function2 = new TestFunction(true, TestFunction.TEST_FUNCTION_NONHA_NOP);
    registerFunctionAtServer(function);
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.regionSingleKeyExecutionNonHA(Boolean.FALSE, function, Boolean.FALSE));
    // This validation doesn't work because the client may
    // still be asynchronously recording the departure of the
    // failed server
    // System.err.println("Trying the second function");
    // //Make sure the client can now execute a function
    // //on the server
    // client.invoke(new SerializableRunnable() {
    // @Override
    // public void run() {
    // ResultCollector rs = FunctionService.onRegion(region).execute(function2);
    // rs.getResult();
    // }
    // });
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.verifyMetaData(new Integer(1), new Integer(0)));
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) ArrayList(java.util.ArrayList) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 47 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method testserverMultiKeyExecutionNoResult_byName.

/*
   * Execution of the function on server with set multiple keys as the routing object and using the
   * name of the function
   */
@Test
public void testserverMultiKeyExecutionNoResult_byName() {
    createScenario();
    Function function = new TestFunction(false, TEST_FUNCTION7);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    client.invoke(() -> PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest.serverMultiKeyExecutionNoResult(isByName));
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 48 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method testServerCacheClosedFailoverWithTwoServerAliveHA.

/*
   * Ensure that the while executing the function if the servers is down then the execution is
   * failover to other available server
   */
@Test
public void testServerCacheClosedFailoverWithTwoServerAliveHA() throws InterruptedException {
    IgnoredException.addIgnoredException("FunctionInvocationTargetException");
    IgnoredException.addIgnoredException("Connection reset");
    IgnoredException.addIgnoredException("SocketTimeoutException");
    IgnoredException.addIgnoredException("ServerConnectivityException");
    IgnoredException.addIgnoredException("Socket Closed");
    ArrayList commonAttributes = createCommonServerAttributes("TestPartitionedRegion", null, 1, 13, null);
    createClientServerScenarion(commonAttributes, 20, 20, 20);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_HA);
    registerFunctionAtServer(function);
    server2.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.stopServerHA());
    server3.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.stopServerHA());
    client.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.putOperation());
    int AsyncInvocationArrSize = 1;
    AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
    async[0] = client.invokeAsync(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.executeFunctionHA());
    server2.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.startServerHA());
    server3.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.startServerHA());
    server1.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.closeCacheHA());
    client.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.verifyDeadAndLiveServers(new Integer(1), new Integer(2)));
    ThreadUtils.join(async[0], 5 * 60 * 1000);
    if (async[0].getException() != null) {
        Assert.fail("UnExpected Exception Occurred : ", async[0].getException());
    }
    List l = (List) async[0].getReturnValue();
    assertEquals(2, l.size());
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 49 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method testserverMultiKeyExecutionOnASingleBucket_byName.

/*
   * Ensure that the execution is limited to a single bucket put another way, that the routing logic
   * works correctly such that there is not extra execution
   */
@Test
public void testserverMultiKeyExecutionOnASingleBucket_byName() {
    createScenario();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    client.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.serverMultiKeyExecutionOnASingleBucket(isByName));
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 50 with TestFunction

use of org.apache.geode.internal.cache.functions.TestFunction in project geode by apache.

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method testServerSingleKeyExecution_byInstance.

/*
   * Execution of the function on server with single key as the routing object and using the
   * instance of the function
   */
@Test
public void testServerSingleKeyExecution_byInstance() {
    createScenario();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(false);
    client.invoke(() -> PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest.serverSingleKeyExecution(isByName));
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

TestFunction (org.apache.geode.internal.cache.functions.TestFunction)214 Function (org.apache.geode.cache.execute.Function)198 Test (org.junit.Test)151 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)150 HashSet (java.util.HashSet)112 Execution (org.apache.geode.cache.execute.Execution)106 ResultCollector (org.apache.geode.cache.execute.ResultCollector)104 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)104 ArrayList (java.util.ArrayList)96 FunctionException (org.apache.geode.cache.execute.FunctionException)89 List (java.util.List)81 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)79 IgnoredException (org.apache.geode.test.dunit.IgnoredException)72 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)72 Iterator (java.util.Iterator)67 Region (org.apache.geode.cache.Region)65 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)57 AttributesFactory (org.apache.geode.cache.AttributesFactory)55 VM (org.apache.geode.test.dunit.VM)55 Host (org.apache.geode.test.dunit.Host)54