Search in sources :

Example 46 with CacheServerImpl

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

the class ConnectionPoolDUnitTest method test022ClientRegisterUnregisterRequests.

@Test
public void test022ClientRegisterUnregisterRequests() throws CacheException {
    final String regionName1 = this.getName() + "-1";
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM client = host.getVM(2);
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setDataPolicy(DataPolicy.REPLICATE);
            factory.setConcurrencyChecksEnabled(false);
            createRegion(regionName1, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    };
    // Create server1.
    server1.invoke(createServer);
    final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    SerializableRunnable createPool = new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            getLonerSystem();
            getCache();
            Region region1 = null;
            AttributesFactory regionFactory = new AttributesFactory();
            regionFactory.setScope(Scope.LOCAL);
            regionFactory.setConcurrencyChecksEnabled(false);
            ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, true, -1, -1, null);
            region1 = createRegion(regionName1, regionFactory.create());
            region1.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
        }
    };
    // Create client.
    client.invoke(createPool);
    // Init values at server.
    server1.invoke(new CacheSerializableRunnable("Create values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            for (int i = 0; i < 20; i++) {
                region1.put("key-string-" + i, "value-" + i);
            }
        }
    });
    // Put some values on the client.
    client.invoke(new CacheSerializableRunnable("Put values client") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            for (int i = 0; i < 10; i++) {
                region1.put("key-string-" + i, "client-value-" + i);
            }
        }
    });
    SerializableRunnable closePool = new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            String pName = region1.getAttributes().getPoolName();
            region1.localDestroyRegion();
            PoolImpl p = (PoolImpl) PoolManager.find(pName);
            p.destroy();
        }
    };
    client.invoke(closePool);
    SerializableRunnable validateClientRegisterUnRegister = new CacheSerializableRunnable("validate Client Register UnRegister") {

        public void run2() throws CacheException {
            for (Iterator bi = getCache().getCacheServers().iterator(); bi.hasNext(); ) {
                CacheServerImpl bsi = (CacheServerImpl) bi.next();
                final CacheClientNotifierStats ccnStats = bsi.getAcceptor().getCacheClientNotifier().getStats();
                WaitCriterion ev = new WaitCriterion() {

                    public boolean done() {
                        return ccnStats.getClientRegisterRequests() == ccnStats.getClientUnRegisterRequests();
                    }

                    public String description() {
                        return null;
                    }
                };
                Wait.waitForCriterion(ev, 62 * 1000, 200, true);
                assertEquals("HealthMonitor Client Register/UnRegister mismatch.", ccnStats.getClientRegisterRequests(), ccnStats.getClientUnRegisterRequests());
            }
        }
    };
    server1.invoke(validateClientRegisterUnRegister);
    server1.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) Endpoint(org.apache.geode.cache.client.internal.Endpoint) CacheClientNotifierStats(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifierStats) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 47 with CacheServerImpl

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

the class HABugInPutDUnitTest method createServerCache.

public static Integer createServerCache() throws Exception {
    new HABugInPutDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
    assertNotNull(server);
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    server.setNotifyBySubscription(false);
    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 48 with CacheServerImpl

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

the class CacheClientNotifierDUnitTest method createCacheServerWithCSC.

private int createCacheServerWithCSC(VM vm, final boolean withCSC, final int capacity, final String policy, final String diskStoreName) {
    final int serverPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    SerializableRunnable createCacheServer = new SerializableRunnable() {

        @Override
        public void run() throws Exception {
            CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
            server.setPort(serverPort);
            if (withCSC) {
                if (diskStoreName != null) {
                    DiskStore ds = cache.findDiskStore(diskStoreName);
                    if (ds == null) {
                        ds = cache.createDiskStoreFactory().create(diskStoreName);
                    }
                }
                ClientSubscriptionConfig csc = server.getClientSubscriptionConfig();
                csc.setCapacity(capacity);
                csc.setEvictionPolicy(policy);
                csc.setDiskStoreName(diskStoreName);
                server.setHostnameForClients("localhost");
            // server.setGroups(new String[]{"serv"});
            }
            try {
                server.start();
            } catch (IOException e) {
                org.apache.geode.test.dunit.Assert.fail("Failed to start server ", e);
            }
        }
    };
    vm.invoke(createCacheServer);
    return serverPort;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) IOException(java.io.IOException)

Example 49 with CacheServerImpl

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

the class ClientInterestNotifyDUnitTest method waitForQueuesToDrain.

public static void waitForQueuesToDrain() {
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            // assume a single cache server as configured in this test
            CacheServerImpl bridgeServer = (CacheServerImpl) cacheServer.getCacheServers().iterator().next();
            if (bridgeServer == null) {
                excuse = "No Cache Server";
                return false;
            }
            Iterator proxies = bridgeServer.getAcceptor().getCacheClientNotifier().getClientProxies().iterator();
            if (!proxies.hasNext()) {
                excuse = "No CacheClientProxy";
                return false;
            }
            while (proxies.hasNext()) {
                CacheClientProxy proxy = (CacheClientProxy) proxies.next();
                if (proxy == null) {
                    excuse = "No CacheClientProxy";
                    return false;
                }
                // Verify the queue size
                int sz = proxy.getQueueSize();
                if (0 != sz) {
                    excuse = "Queue did not drain. Expected size = 0, actual = " + sz + "for " + proxy;
                    return false;
                }
            }
            return true;
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Iterator(java.util.Iterator) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 50 with CacheServerImpl

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

the class CacheCreationJUnitTest method defaultCacheServerIsNotCreatedWithDefaultPortWhenNoDeclarativeServerIsConfigured.

@Test
public void defaultCacheServerIsNotCreatedWithDefaultPortWhenNoDeclarativeServerIsConfigured() {
    CacheCreation cacheCreation = new CacheCreation();
    CacheServerImpl mockServer = mock(CacheServerImpl.class);
    when(this.cache.addCacheServer()).thenReturn(mockServer);
    List<CacheServer> cacheServers = new ArrayList<>();
    when(this.cache.getCacheServers()).thenReturn(cacheServers);
    Boolean disableDefaultCacheServer = false;
    Integer configuredServerPort = null;
    String configuredServerBindAddress = null;
    cacheCreation.startCacheServers(cacheCreation.getCacheServers(), this.cache, configuredServerPort, configuredServerBindAddress, disableDefaultCacheServer);
    verify(this.cache, never()).addCacheServer();
}
Also used : ArrayList(java.util.ArrayList) CacheServer(org.apache.geode.cache.server.CacheServer) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

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