Search in sources :

Example 6 with CacheServerImpl

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

the class HADispatcherDUnitTest method createServerCache.

private Integer createServerCache(Boolean isListenerPresent) throws IOException {
    createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    if (isListenerPresent.booleanValue() == true) {
        CacheListener serverListener = new HAServerListener();
        factory.setCacheListener(serverListener);
    }
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
    assertNotNull(server);
    int port = getRandomAvailablePort(SOCKET);
    server.setPort(port);
    server.setNotifyBySubscription(true);
    server.start();
    return new Integer(server.getPort());
}
Also used : CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) Properties(java.util.Properties)

Example 7 with CacheServerImpl

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

the class CQListGIIDUnitTest method VerifyCUMCQList.

public static void VerifyCUMCQList(Integer numOfKeys, Integer numOfClients) {
    try {
        Iterator iter = cache.getCacheServers().iterator();
        if (iter.hasNext()) {
            CacheServerImpl server = (CacheServerImpl) iter.next();
            Map haContainer = server.getAcceptor().getCacheClientNotifier().getHaContainer();
            Object[] keys = haContainer.keySet().toArray();
            logger.fine("### numOfKeys :" + numOfKeys.intValue() + " keys.length : " + keys.length + " haContainer size : " + haContainer.size());
            assertEquals(numOfKeys.intValue(), keys.length);
            for (int i = 0; i < numOfKeys.intValue(); i++) {
                logger.fine("i=: " + i);
                ClientUpdateMessageImpl cum = (ClientUpdateMessageImpl) haContainer.get(keys[i]);
                assertNotNull(cum);
                assertNotNull(cum.getClientCqs());
                assertEquals("This test may fail if the image provider gets an ack from client before providing image", numOfClients.intValue(), cum.getClientCqs().size());
            }
        }
    } catch (Exception e) {
        Assert.fail("failed in VerifyCUMCQList()" + e, e);
    }
}
Also used : ClientUpdateMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl) Iterator(java.util.Iterator) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) Map(java.util.Map) HashMap(java.util.HashMap) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 8 with CacheServerImpl

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

the class DeltaToRegionRelationCQRegistrationDUnitTest method getBridgeServer.

/*
   * get cache server / bridge server attacted to cache
   */
private static CacheServerImpl getBridgeServer() {
    CacheServerImpl bridgeServer = (CacheServerImpl) cache.getCacheServers().iterator().next();
    assertNotNull(bridgeServer);
    return bridgeServer;
}
Also used : CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 9 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 10 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)

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