Search in sources :

Example 11 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl 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 12 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl 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 13 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class Bug43684DUnitTest method createServerCache.

@SuppressWarnings("rawtypes")
public static Integer createServerCache(Boolean isReplicated, Boolean isPrimaryEmpty) throws Exception {
    disconnectFromDS();
    Properties props = new Properties();
    props.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
    props.setProperty(STATISTIC_ARCHIVE_FILE, "server_" + OSProcess.getId() + ".gfs");
    props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    CacheFactory cf = new CacheFactory(props);
    cache = (GemFireCacheImpl) cf.create();
    RegionFactory rf;
    if (isReplicated) {
        RegionShortcut rs = isPrimaryEmpty ? RegionShortcut.REPLICATE_PROXY : RegionShortcut.REPLICATE;
        rf = cache.createRegionFactory(rs);
    } else {
        RegionShortcut rs = isPrimaryEmpty ? RegionShortcut.PARTITION_PROXY : RegionShortcut.PARTITION;
        rf = cache.createRegionFactory(rs);
        rf.setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numBuckets).create());
    }
    rf.create(REGION_NAME);
    CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
    server.setPort(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
    server.start();
    return server.getPort();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) RegionShortcut(org.apache.geode.cache.RegionShortcut) ClientRegionShortcut(org.apache.geode.cache.client.ClientRegionShortcut) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 14 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class OperationsPropagationDUnitTest method createServerCache.

/**
   * Create the server
   */
public static Integer createServerCache() throws Exception {
    new OperationsPropagationDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attrs = factory.create();
    region = cache.createRegion(REGION_NAME, attrs);
    CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
    assertNotNull(server);
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    server.setNotifyBySubscription(true);
    server.start();
    return new Integer(server.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 15 with CacheServerImpl

use of org.apache.geode.internal.cache.CacheServerImpl in project geode by apache.

the class ClientServerMiscDUnitTest method verifyNoCacheClientProxyOnServer.

public static void verifyNoCacheClientProxyOnServer() {
    try {
        Cache cache = new ClientServerMiscDUnitTest().getCache();
        assertEquals("More than one BridgeServer", 1, cache.getCacheServers().size());
        CacheServerImpl bs = (CacheServerImpl) cache.getCacheServers().iterator().next();
        assertNotNull(bs);
        assertNotNull(bs.getAcceptor());
        final CacheClientNotifier ccn = bs.getAcceptor().getCacheClientNotifier();
        assertNotNull(ccn);
        WaitCriterion wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                return ccn.getClientProxies().size() == 0;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 40 * 1000, 1000, true);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("while setting verifyNoCacheClientProxyOnServer  " + ex);
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) GemFireIOException(org.apache.geode.GemFireIOException) GemFireConfigException(org.apache.geode.GemFireConfigException) CacheException(org.apache.geode.cache.CacheException) Cache(org.apache.geode.cache.Cache)

Aggregations

CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)76 Iterator (java.util.Iterator)23 Cache (org.apache.geode.cache.Cache)19 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)19 CacheServer (org.apache.geode.cache.server.CacheServer)14 IOException (java.io.IOException)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13 CacheException (org.apache.geode.cache.CacheException)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)8 Set (java.util.Set)7 InternalCache (org.apache.geode.internal.cache.InternalCache)7 Map (java.util.Map)6 Properties (java.util.Properties)6 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 HashMap (java.util.HashMap)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 RegionAttributes (org.apache.geode.cache.RegionAttributes)5 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)5