Search in sources :

Example 31 with CacheServerImpl

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

the class RegisterInterestBeforeRegionCreationDUnitTest method createServer.

public static Integer createServer(Boolean createRegion) throws Exception {
    new RegisterInterestBeforeRegionCreationDUnitTest().createCache(new Properties());
    boolean isCreateRegion = createRegion.booleanValue();
    if (isCreateRegion) {
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.DISTRIBUTED_ACK);
        factory.setMirrorType(MirrorType.KEYS_VALUES);
        RegionAttributes attrs = factory.createRegionAttributes();
        cache.createVMRegion(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 32 with CacheServerImpl

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

the class RedundancyLevelTestBase method startServer.

public static void startServer() {
    try {
        Cache c = CacheFactory.getAnyInstance();
        CacheServerImpl bs = (CacheServerImpl) c.getCacheServers().iterator().next();
        assertNotNull(bs);
        bs.start();
    } catch (Exception ex) {
        Assert.fail("while startServer()", ex);
    }
}
Also used : CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Cache(org.apache.geode.cache.Cache)

Example 33 with CacheServerImpl

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

the class RedundancyLevelTestBase method verifyNoCCP.

public static void verifyNoCCP() {
    assertEquals("More than one BridgeServer", 1, cache.getCacheServers().size());
    CacheServerImpl bs = (CacheServerImpl) cache.getCacheServers().iterator().next();
    assertNotNull(bs);
    assertNotNull(bs.getAcceptor());
    assertNotNull(bs.getAcceptor().getCacheClientNotifier());
    // no client is connected to this server
    assertTrue(0 == bs.getAcceptor().getCacheClientNotifier().getClientProxies().size());
}
Also used : CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 34 with CacheServerImpl

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

the class RedundancyLevelTestBase method verifyDispatcherIsAlive.

public static void verifyDispatcherIsAlive() {
    try {
        WaitCriterion wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                return cache.getCacheServers().size() == 1;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 3 * 60 * 1000, 1000, true);
        CacheServerImpl bs = (CacheServerImpl) cache.getCacheServers().iterator().next();
        assertNotNull(bs);
        assertNotNull(bs.getAcceptor());
        assertNotNull(bs.getAcceptor().getCacheClientNotifier());
        final CacheClientNotifier ccn = bs.getAcceptor().getCacheClientNotifier();
        wc = new WaitCriterion() {

            String excuse;

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

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
        Iterator iter_prox = ccn.getClientProxies().iterator();
        if (iter_prox.hasNext()) {
            final CacheClientProxy proxy = (CacheClientProxy) iter_prox.next();
            wc = new WaitCriterion() {

                String excuse;

                public boolean done() {
                    if (proxy._messageDispatcher == null) {
                        return false;
                    }
                    return proxy._messageDispatcher.isAlive();
                }

                public String description() {
                    return excuse;
                }
            };
            Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
        // assertTrue("Dispatcher on primary should be alive", proxy._messageDispatcher.isAlive());
        }
    } catch (Exception ex) {
        Assert.fail("while setting verifyDispatcherIsAlive  ", ex);
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Iterator(java.util.Iterator) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 35 with CacheServerImpl

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

the class CacheCreationJUnitTest method cacheServerCreationIsSkippedWhenAServerExistsForAGivenPort.

@Test
public void cacheServerCreationIsSkippedWhenAServerExistsForAGivenPort() {
    CacheCreation cacheCreation = new CacheCreation();
    CacheServerCreation br1 = new CacheServerCreation(cacheCreation, false);
    br1.setPort(40406);
    cacheCreation.getCacheServers().add(br1);
    CacheServerImpl mockServer = mock(CacheServerImpl.class);
    when(this.cache.addCacheServer()).thenReturn(mockServer);
    when(mockServer.getPort()).thenReturn(40406);
    List<CacheServer> cacheServers = new ArrayList<>();
    cacheServers.add(mockServer);
    when(this.cache.getCacheServers()).thenReturn(cacheServers);
    Integer configuredServerPort = null;
    String configuredServerBindAddress = null;
    Boolean disableDefaultCacheServer = false;
    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