Search in sources :

Example 26 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class FunctionServiceStatsDUnitTest method testClientServerPartitonedRegionFunctionExecutionStats.

/**
   * 1-client 3-Servers Function : TEST_FUNCTION2 Function : TEST_FUNCTION3 Execution of the
   * function on serverRegion with set multiple keys as the routing object and using the name of the
   * function
   * 
   * On server side, function execution calls should be equal to the no of function executions
   * completed.
   */
@Test
public void testClientServerPartitonedRegionFunctionExecutionStats() {
    createScenario();
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION2);
    registerFunctionAtServer(function);
    function = new TestFunction(true, TestFunction.TEST_FUNCTION3);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    client.invoke(initializeStats);
    server1.invoke(initializeStats);
    server2.invoke(initializeStats);
    server3.invoke(initializeStats);
    SerializableCallable PopulateRegionAndExecuteFunctions = new SerializableCallable("PopulateRegionAndExecuteFunctions") {

        public Object call() throws Exception {
            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_FUNCTION2);
            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);
                }
                ResultCollector rc = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
                int resultSize = ((List) rc.getResult()).size();
                resultReceived_Aggregate += resultSize;
                resultReceived_TESTFUNCTION2 += resultSize;
                noOfExecutionCalls_Aggregate++;
                noOfExecutionCalls_TESTFUNCTION2++;
                noOfExecutionsCompleted_Aggregate++;
                noOfExecutionsCompleted_TESTFUNCTION2++;
                rc = dataSet.withFilter(testKeysSet).setArguments(testKeysSet).execute(function.getId());
                resultSize = ((List) rc.getResult()).size();
                resultReceived_Aggregate += resultSize;
                resultReceived_TESTFUNCTION2 += resultSize;
                noOfExecutionCalls_Aggregate++;
                noOfExecutionCalls_TESTFUNCTION2++;
                noOfExecutionsCompleted_Aggregate++;
                noOfExecutionsCompleted_TESTFUNCTION2++;
                function = new TestFunction(true, TestFunction.TEST_FUNCTION3);
                FunctionService.registerFunction(function);
                rc = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
                resultSize = ((List) rc.getResult()).size();
                resultReceived_Aggregate += resultSize;
                resultReceived_TESTFUNCTION3 += resultSize;
                noOfExecutionCalls_Aggregate++;
                noOfExecutionCalls_TESTFUNCTION3++;
                noOfExecutionsCompleted_Aggregate++;
                noOfExecutionsCompleted_TESTFUNCTION3++;
            } catch (Exception e) {
                LogWriterUtils.getLogWriter().info("Exception : " + e.getMessage());
                e.printStackTrace();
                fail("Test failed after the put operation");
            }
            return Boolean.TRUE;
        }
    };
    client.invoke(PopulateRegionAndExecuteFunctions);
    SerializableCallable checkStatsOnClient = new SerializableCallable("checkStatsOnClient") {

        public Object call() throws Exception {
            // checks for the aggregate stats
            InternalDistributedSystem iDS = (InternalDistributedSystem) cache.getDistributedSystem();
            FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
            waitNoFunctionsRunning(functionServiceStats);
            assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
            assertTrue(functionServiceStats.getResultsReceived() >= resultReceived_Aggregate);
            LogWriterUtils.getLogWriter().info("Calling FunctionStats for  TEST_FUNCTION2 :");
            FunctionStats functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION2, iDS);
            LogWriterUtils.getLogWriter().info("Called FunctionStats for  TEST_FUNCTION2 :");
            assertEquals(noOfExecutionCalls_TESTFUNCTION2, functionStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_TESTFUNCTION2, functionStats.getFunctionExecutionsCompleted());
            assertTrue(functionStats.getResultsReceived() >= resultReceived_TESTFUNCTION2);
            functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION3, iDS);
            assertEquals(noOfExecutionCalls_TESTFUNCTION3, functionStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_TESTFUNCTION3, functionStats.getFunctionExecutionsCompleted());
            assertTrue(functionStats.getResultsReceived() >= resultReceived_TESTFUNCTION3);
            return Boolean.TRUE;
        }
    };
    client.invoke(checkStatsOnClient);
    SerializableCallable checkStatsOnServer = new SerializableCallable("checkStatsOnClient") {

        public Object call() throws Exception {
            // checks for the aggregate stats
            InternalDistributedSystem iDS = (InternalDistributedSystem) cache.getDistributedSystem();
            FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
            waitNoFunctionsRunning(functionServiceStats);
            // functions are executed 3 times
            noOfExecutionCalls_Aggregate += 3;
            assertTrue(functionServiceStats.getFunctionExecutionCalls() >= noOfExecutionCalls_Aggregate);
            noOfExecutionsCompleted_Aggregate += 3;
            assertTrue(functionServiceStats.getFunctionExecutionsCompleted() >= noOfExecutionsCompleted_Aggregate);
            FunctionStats functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION2, iDS);
            // TEST_FUNCTION2 is executed twice
            noOfExecutionCalls_TESTFUNCTION2 += 2;
            assertTrue(functionStats.getFunctionExecutionCalls() >= noOfExecutionCalls_TESTFUNCTION2);
            noOfExecutionsCompleted_TESTFUNCTION2 += 2;
            assertTrue(functionStats.getFunctionExecutionsCompleted() >= noOfExecutionsCompleted_TESTFUNCTION2);
            functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION3, iDS);
            // TEST_FUNCTION3 is executed once
            noOfExecutionCalls_TESTFUNCTION3 += 1;
            assertTrue(functionStats.getFunctionExecutionCalls() >= noOfExecutionCalls_TESTFUNCTION3);
            noOfExecutionsCompleted_TESTFUNCTION3 += 1;
            assertTrue(functionStats.getFunctionExecutionsCompleted() >= noOfExecutionsCompleted_TESTFUNCTION3);
            return Boolean.TRUE;
        }
    };
    server1.invoke(checkStatsOnServer);
    server2.invoke(checkStatsOnServer);
    server3.invoke(checkStatsOnServer);
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ArrayList(java.util.ArrayList) List(java.util.List) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 27 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class FunctionServiceStatsDUnitTest method testClientServerwithoutRegion.

/**
   * Execution of the function on server using the name of the function TEST_FUNCTION1
   * TEST_FUNCTION5 On client side, the no of result received should equal to the no of function
   * execution calls. On server side, function execution calls should be equal to the no of function
   * executions completed.
   */
@Test
public void testClientServerwithoutRegion() {
    createClientServerScenarionWithoutRegion();
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
    registerFunctionAtServer(function);
    function = new TestFunction(true, TestFunction.TEST_FUNCTION5);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    client.invoke(initializeStats);
    server1.invoke(initializeStats);
    server2.invoke(initializeStats);
    server3.invoke(initializeStats);
    SerializableCallable ExecuteFunction = new SerializableCallable("ExecuteFunction") {

        public Object call() throws Exception {
            DistributedSystem.setThreadsSocketPolicy(false);
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            FunctionService.registerFunction(function);
            Execution member = FunctionService.onServers(pool);
            try {
                ResultCollector rs = member.setArguments(Boolean.TRUE).execute(function.getId());
                int size = ((List) rs.getResult()).size();
                resultReceived_Aggregate += size;
                noOfExecutionCalls_Aggregate++;
                noOfExecutionsCompleted_Aggregate++;
                resultReceived_TESTFUNCTION1 += size;
                noOfExecutionCalls_TESTFUNCTION1++;
                noOfExecutionsCompleted_TESTFUNCTION1++;
            } catch (Exception ex) {
                ex.printStackTrace();
                LogWriterUtils.getLogWriter().info("Exception : ", ex);
                fail("Test failed after the execute operation nn TRUE");
            }
            function = new TestFunction(true, TestFunction.TEST_FUNCTION5);
            FunctionService.registerFunction(function);
            try {
                final HashSet testKeysSet = new HashSet();
                for (int i = 0; i < 20; i++) {
                    testKeysSet.add("execKey-" + i);
                }
                ResultCollector rs = member.setArguments("Success").execute(function.getId());
                int size = ((List) rs.getResult()).size();
                resultReceived_Aggregate += size;
                noOfExecutionCalls_Aggregate++;
                noOfExecutionsCompleted_Aggregate++;
                resultReceived_TESTFUNCTION5 += size;
                noOfExecutionCalls_TESTFUNCTION5++;
                noOfExecutionsCompleted_TESTFUNCTION5++;
            } catch (Exception ex) {
                ex.printStackTrace();
                LogWriterUtils.getLogWriter().info("Exception : ", ex);
                fail("Test failed after the execute operationssssss");
            }
            return Boolean.TRUE;
        }
    };
    client.invoke(ExecuteFunction);
    SerializableCallable checkStatsOnClient = new SerializableCallable("checkStatsOnClient") {

        public Object call() throws Exception {
            // checks for the aggregate stats
            InternalDistributedSystem iDS = (InternalDistributedSystem) cache.getDistributedSystem();
            FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
            waitNoFunctionsRunning(functionServiceStats);
            assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
            assertEquals(resultReceived_Aggregate, functionServiceStats.getResultsReceived());
            FunctionStats functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION1, iDS);
            assertEquals(noOfExecutionCalls_TESTFUNCTION1, functionStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_TESTFUNCTION1, functionStats.getFunctionExecutionsCompleted());
            assertEquals(resultReceived_TESTFUNCTION1, functionStats.getResultsReceived());
            functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION5, iDS);
            assertEquals(noOfExecutionCalls_TESTFUNCTION5, functionStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_TESTFUNCTION5, functionStats.getFunctionExecutionsCompleted());
            assertEquals(resultReceived_TESTFUNCTION5, functionStats.getResultsReceived());
            return Boolean.TRUE;
        }
    };
    client.invoke(checkStatsOnClient);
    SerializableCallable checkStatsOnServer = new SerializableCallable("checkStatsOnClient") {

        public Object call() throws Exception {
            // checks for the aggregate stats
            InternalDistributedSystem iDS = (InternalDistributedSystem) cache.getDistributedSystem();
            FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
            waitNoFunctionsRunning(functionServiceStats);
            // functions are executed 2 times
            noOfExecutionCalls_Aggregate += 2;
            assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
            noOfExecutionsCompleted_Aggregate += 2;
            // before giving up
            for (int i = 0; i < 10; i++) {
                try {
                    assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
                } catch (RuntimeException r) {
                    if (i == 9) {
                        throw r;
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ie) {
                        Thread.currentThread().interrupt();
                        throw r;
                    }
                }
            }
            FunctionStats functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION1, iDS);
            // TEST_FUNCTION1 is executed once
            noOfExecutionCalls_TESTFUNCTION1 += 1;
            assertEquals(noOfExecutionCalls_TESTFUNCTION1, functionStats.getFunctionExecutionCalls());
            noOfExecutionsCompleted_TESTFUNCTION1 += 1;
            assertEquals(noOfExecutionsCompleted_TESTFUNCTION1, functionStats.getFunctionExecutionsCompleted());
            functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION5, iDS);
            // TEST_FUNCTION5 is executed once
            noOfExecutionCalls_TESTFUNCTION5 += 1;
            assertEquals(noOfExecutionCalls_TESTFUNCTION5, functionStats.getFunctionExecutionCalls());
            noOfExecutionsCompleted_TESTFUNCTION5 += 1;
            assertEquals(noOfExecutionsCompleted_TESTFUNCTION5, functionStats.getFunctionExecutionsCompleted());
            return Boolean.TRUE;
        }
    };
    server1.invoke(checkStatsOnServer);
    server2.invoke(checkStatsOnServer);
    server3.invoke(checkStatsOnServer);
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ArrayList(java.util.ArrayList) List(java.util.List) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 28 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class FunctionServiceStatsDUnitTest method testClientServerDistributedRegionFunctionExecutionStats.

/**
   * 1-client 3-Servers server1 : Replicate server2 : Replicate server3 : Replicate client : Empty
   * Function : TEST_FUNCTION2 Execution of the function on serverRegion with set multiple keys as
   * the routing object and using the name of the function
   * 
   * On server side, function execution calls should be equal to the no of function executions
   * completed.
   */
@Test
public void testClientServerDistributedRegionFunctionExecutionStats() {
    final String regionName = "FunctionServiceStatsDUnitTest";
    SerializableCallable createCahenServer = new SerializableCallable("createCahenServer") {

        public Object call() throws Exception {
            try {
                Properties props = new Properties();
                DistributedSystem ds = getSystem(props);
                assertNotNull(ds);
                ds.disconnect();
                ds = getSystem(props);
                cache = CacheFactory.create(ds);
                LogWriterUtils.getLogWriter().info("Created Cache on Server");
                assertNotNull(cache);
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setDataPolicy(DataPolicy.REPLICATE);
                assertNotNull(cache);
                Region region = cache.createRegion(regionName, factory.create());
                LogWriterUtils.getLogWriter().info("Region Created :" + region);
                assertNotNull(region);
                for (int i = 1; i <= 200; i++) {
                    region.put("execKey-" + i, new Integer(i));
                }
                CacheServer server = cache.addCacheServer();
                assertNotNull(server);
                int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
                server.setPort(port);
                try {
                    server.start();
                } catch (IOException e) {
                    Assert.fail("Failed to start the Server", e);
                }
                assertTrue(server.isRunning());
                return new Integer(server.getPort());
            } catch (Exception e) {
                Assert.fail("FunctionServiceStatsDUnitTest#createCache() Failed while creating the cache", e);
                throw e;
            }
        }
    };
    final Integer port1 = (Integer) server1.invoke(createCahenServer);
    final Integer port2 = (Integer) server2.invoke(createCahenServer);
    final Integer port3 = (Integer) server3.invoke(createCahenServer);
    SerializableCallable createCaheInClient = new SerializableCallable("createCaheInClient") {

        public Object call() throws Exception {
            try {
                Properties props = new Properties();
                props.put(MCAST_PORT, "0");
                props.put(LOCATORS, "");
                DistributedSystem ds = getSystem(props);
                assertNotNull(ds);
                ds.disconnect();
                ds = getSystem(props);
                cache = CacheFactory.create(ds);
                LogWriterUtils.getLogWriter().info("Created Cache on Client");
                assertNotNull(cache);
                CacheServerTestUtil.disableShufflingOfEndpoints();
                Pool p;
                try {
                    p = PoolManager.createFactory().addServer("localhost", port1.intValue()).addServer("localhost", port2.intValue()).addServer("localhost", port3.intValue()).setPingInterval(250).setSubscriptionEnabled(false).setSubscriptionRedundancy(-1).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(6).setMaxConnections(10).setRetryAttempts(3).create("FunctionServiceStatsDUnitTest_pool");
                } finally {
                    CacheServerTestUtil.enableShufflingOfEndpoints();
                }
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.LOCAL);
                factory.setDataPolicy(DataPolicy.EMPTY);
                factory.setPoolName(p.getName());
                assertNotNull(cache);
                Region region = cache.createRegion(regionName, factory.create());
                LogWriterUtils.getLogWriter().info("Client Region Created :" + region);
                assertNotNull(region);
                for (int i = 1; i <= 200; i++) {
                    region.put("execKey-" + i, new Integer(i));
                }
                return Boolean.TRUE;
            } catch (Exception e) {
                Assert.fail("FunctionServiceStatsDUnitTest#createCache() Failed while creating the cache", e);
                throw e;
            }
        }
    };
    client.invoke(createCaheInClient);
    client.invoke(initializeStats);
    server1.invoke(initializeStats);
    server2.invoke(initializeStats);
    server3.invoke(initializeStats);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION2);
    registerFunctionAtServer(function);
    function = new TestFunction(true, TestFunction.TEST_FUNCTION3);
    registerFunctionAtServer(function);
    SerializableCallable ExecuteFunctions = new SerializableCallable("PopulateRegionAndExecuteFunctions") {

        public Object call() throws Exception {
            Function function2 = new TestFunction(true, TestFunction.TEST_FUNCTION2);
            FunctionService.registerFunction(function2);
            Function function3 = new TestFunction(true, TestFunction.TEST_FUNCTION3);
            FunctionService.registerFunction(function3);
            Region region = cache.getRegion(regionName);
            Set filter = new HashSet();
            for (int i = 100; i < 120; i++) {
                filter.add("execKey-" + i);
            }
            try {
                noOfExecutionCalls_Aggregate++;
                noOfExecutionCalls_TESTFUNCTION2++;
                List list = (List) FunctionService.onRegion(region).withFilter(filter).execute(function2).getResult();
                noOfExecutionsCompleted_Aggregate++;
                noOfExecutionsCompleted_TESTFUNCTION2++;
                int size = list.size();
                resultReceived_Aggregate += size;
                resultReceived_TESTFUNCTION2 += size;
                noOfExecutionCalls_Aggregate++;
                noOfExecutionCalls_TESTFUNCTION2++;
                list = (List) FunctionService.onRegion(region).withFilter(filter).execute(function2).getResult();
                noOfExecutionsCompleted_Aggregate++;
                noOfExecutionsCompleted_TESTFUNCTION2++;
                size = list.size();
                resultReceived_Aggregate += size;
                resultReceived_TESTFUNCTION2 += size;
                return Boolean.TRUE;
            } catch (FunctionException e) {
                e.printStackTrace();
                Assert.fail("test failed due to", e);
                throw e;
            } catch (Exception e) {
                e.printStackTrace();
                Assert.fail("test failed due to", e);
                throw e;
            }
        }
    };
    client.invoke(ExecuteFunctions);
    SerializableCallable checkStatsOnClient = new SerializableCallable("checkStatsOnClient") {

        public Object call() throws Exception {
            // checks for the aggregate stats
            InternalDistributedSystem iDS = (InternalDistributedSystem) cache.getDistributedSystem();
            FunctionServiceStats functionServiceStats = iDS.getFunctionServiceStats();
            waitNoFunctionsRunning(functionServiceStats);
            assertEquals(noOfExecutionCalls_Aggregate, functionServiceStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_Aggregate, functionServiceStats.getFunctionExecutionsCompleted());
            assertEquals(resultReceived_Aggregate, functionServiceStats.getResultsReceived());
            FunctionStats functionStats = FunctionStats.getFunctionStats(TestFunction.TEST_FUNCTION2, iDS);
            assertEquals(noOfExecutionCalls_TESTFUNCTION2, functionStats.getFunctionExecutionCalls());
            assertEquals(noOfExecutionsCompleted_TESTFUNCTION2, functionStats.getFunctionExecutionsCompleted());
            assertEquals(resultReceived_TESTFUNCTION2, functionStats.getResultsReceived());
            return Boolean.TRUE;
        }
    };
    client.invoke(checkStatsOnClient);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) AttributesFactory(org.apache.geode.cache.AttributesFactory) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CacheServer(org.apache.geode.cache.server.CacheServer) Pool(org.apache.geode.cache.client.Pool) ArrayList(java.util.ArrayList) List(java.util.List) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) HashSet(java.util.HashSet) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 29 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class FetchEntriesMessageJUnitTest method testProcessChunk.

@Test
public void testProcessChunk() throws Exception {
    cache = Fakes.cache();
    PartitionedRegion pr = mock(PartitionedRegion.class);
    InternalDistributedSystem system = cache.getInternalDistributedSystem();
    FetchEntriesResponse response = new FetchEntriesResponse(system, pr, null, 0);
    HeapDataOutputStream chunkStream = createDummyChunk();
    FetchEntriesReplyMessage reply = new FetchEntriesReplyMessage(null, 0, 0, chunkStream, 0, 0, 0, false, false);
    reply.chunk = chunkStream.toByteArray();
    response.processChunk(reply);
    assertNull(response.returnRVV);
    assertEquals(2, response.returnValue.size());
    assertTrue(response.returnValue.get("keyWithOutVersionTag").equals("valueWithOutVersionTag"));
    assertTrue(response.returnValue.get("keyWithVersionTag").equals("valueWithVersionTag"));
    assertNull(response.returnVersions.get("keyWithOutVersionTag"));
    assertNotNull(response.returnVersions.get("keyWithVersionTag"));
}
Also used : FetchEntriesResponse(org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) FetchEntriesReplyMessage(org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesReplyMessage) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 30 with InternalDistributedSystem

use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.

the class AsyncEventListenerDUnitTest method testCreateAsyncEventQueueWithNullListener.

/**
   * Test to verify that AsyncEventQueue can not be created when null listener is passed.
   */
@Test
public void testCreateAsyncEventQueueWithNullListener() {
    AsyncEventQueueTestBase test = new AsyncEventQueueTestBase();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    InternalDistributedSystem ds = test.getSystem(props);
    cache = CacheFactory.create(ds);
    AsyncEventQueueFactory asyncQueueFactory = cache.createAsyncEventQueueFactory();
    try {
        asyncQueueFactory.create("testId", null);
        fail("AsyncQueueFactory should not allow to create AsyncEventQueue with null listener");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueueTestBase(org.apache.geode.internal.cache.wan.AsyncEventQueueTestBase) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)209 Properties (java.util.Properties)70 Test (org.junit.Test)60 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)58 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)41 IOException (java.io.IOException)35 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)32 DM (org.apache.geode.distributed.internal.DM)30 File (java.io.File)22 HashSet (java.util.HashSet)21 Set (java.util.Set)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)19 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)19 Region (org.apache.geode.cache.Region)17 ArrayList (java.util.ArrayList)16 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)14 VM (org.apache.geode.test.dunit.VM)14 Cache (org.apache.geode.cache.Cache)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13