Search in sources :

Example 86 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class TransactionsWithDeltaDUnitTest method createRegionOnServer.

private Integer createRegionOnServer(VM vm, final boolean startServer, final boolean accessor) {
    return (Integer) vm.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            createRegion(accessor, 0, null);
            if (startServer) {
                int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
                CacheServer s = getCache().addCacheServer();
                s.setPort(port);
                s.start();
                return port;
            }
            return 0;
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer)

Example 87 with CacheServer

use of org.apache.geode.cache.server.CacheServer 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 88 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class TestFunction method executeHAAndNonHAOnRegion.

public void executeHAAndNonHAOnRegion(FunctionContext context) {
    List<CacheServer> servers = CacheFactory.getAnyInstance().getCacheServers();
    ArrayList<String> args = (ArrayList<String>) context.getArguments();
    RegionFunctionContext rfContext = (RegionFunctionContext) context;
    rfContext.getDataSet().getCache().getLogger().info("Executing function :  executeHAAndNonHAOnRegion " + rfContext);
    Region r = CacheFactory.getAnyInstance().getRegion(args.get(0));
    String testName = args.get(1);
    Integer numTimesStopped = (Integer) r.get("stopped");
    Integer numTimesSentResult = (Integer) r.get("sentresult");
    if (context.isPossibleDuplicate()) {
        if (testName.equals("regionExecutionHATwoServerDown")) {
            if ((Integer) r.get("stopped") == 2) {
                if (numTimesSentResult == null) {
                    r.put("sentresult", 1);
                } else {
                    r.put("sentresult", ++numTimesSentResult);
                }
                context.getResultSender().lastResult(args.get(0));
            } else {
                r.put("stopped", ++numTimesStopped);
                for (CacheServer s : servers) {
                    if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
                        s.stop();
                        DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
                        ds.disconnect();
                    }
                }
            }
        } else if (testName.equals("regionExecutionHAOneServerDown")) {
            if (numTimesSentResult == null) {
                r.put("sentresult", 1);
            } else {
                r.put("sentresult", ++numTimesSentResult);
            }
            context.getResultSender().lastResult(args.get(0));
        } else {
            context.getResultSender().lastResult(args.get(0));
        }
    } else {
        if (numTimesStopped == null) {
            r.put("stopped", 1);
        } else {
            r.put("stopped", ++numTimesStopped);
        }
        for (CacheServer s : servers) {
            if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
                s.stop();
                DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
                ds.disconnect();
            }
        }
        context.getResultSender().lastResult(args.get(0));
    }
}
Also used : ArrayList(java.util.ArrayList) CacheServer(org.apache.geode.cache.server.CacheServer) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 89 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class TestFunction method executeHAAndNonHAOnServer.

public void executeHAAndNonHAOnServer(FunctionContext context) {
    List<CacheServer> servers = CacheFactory.getAnyInstance().getCacheServers();
    ArrayList<String> args = (ArrayList<String>) context.getArguments();
    Region r = CacheFactory.getAnyInstance().getRegion(args.get(0));
    String testName = args.get(1);
    Integer numTimesStopped = (Integer) r.get("stopped");
    Integer numTimesSentResult = (Integer) r.get("sentresult");
    if (context.isPossibleDuplicate()) {
        if (testName.equals("serverExecutionHATwoServerDown")) {
            if ((Integer) r.get("stopped") == 2) {
                if (numTimesSentResult == null) {
                    r.put("sentresult", 1);
                } else {
                    r.put("sentresult", ++numTimesSentResult);
                }
                context.getResultSender().lastResult(args.get(0));
            } else {
                r.put("stopped", ++numTimesStopped);
                for (CacheServer s : servers) {
                    if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
                        s.stop();
                        DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
                        ds.disconnect();
                    }
                }
            }
        } else if (testName.equals("serverExecutionHAOneServerDown")) {
            if (numTimesSentResult == null) {
                r.put("sentresult", 1);
            } else {
                r.put("sentresult", ++numTimesSentResult);
            }
            context.getResultSender().lastResult(args.get(0));
        } else {
            context.getResultSender().lastResult(args.get(0));
        }
    } else {
        if (numTimesStopped == null) {
            r.put("stopped", 1);
        } else {
            r.put("stopped", ++numTimesStopped);
        }
        for (CacheServer s : servers) {
            if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
                s.stop();
                DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
                ds.disconnect();
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CacheServer(org.apache.geode.cache.server.CacheServer) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 90 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class StatsBugDUnitTest method createServerCache.

/**
   * Creates and starts the cache-server
   * 
   * @return - the port on which cache-server is running
   * @throws Exception - thrown if any problem occurs in cache/server creation
   */
public static Integer createServerCache() throws Exception {
    StatsBugDUnitTest test = new StatsBugDUnitTest();
    Properties props = new Properties();
    cache = test.createCache(props);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    server.setNotifyBySubscription(false);
    server.setSocketBufferSize(32768);
    server.start();
    LogWriterUtils.getLogWriter().info("Server started at PORT = " + port);
    return new Integer(port);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Aggregations

CacheServer (org.apache.geode.cache.server.CacheServer)323 AttributesFactory (org.apache.geode.cache.AttributesFactory)99 Properties (java.util.Properties)97 Test (org.junit.Test)77 Cache (org.apache.geode.cache.Cache)76 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)76 RegionAttributes (org.apache.geode.cache.RegionAttributes)60 IOException (java.io.IOException)53 ClientCache (org.apache.geode.cache.client.ClientCache)53 Region (org.apache.geode.cache.Region)50 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)49 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)33 Iterator (java.util.Iterator)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)30 Host (org.apache.geode.test.dunit.Host)27 VM (org.apache.geode.test.dunit.VM)25 DistributedSystem (org.apache.geode.distributed.DistributedSystem)20 CacheException (org.apache.geode.cache.CacheException)17 CacheFactory (org.apache.geode.cache.CacheFactory)17