Search in sources :

Example 36 with CacheServerImpl

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

the class CacheCreationJUnitTest method defaultCacheServerIsNotCreatedWhenDisableDefaultCacheServerIsTrue.

@Test
public void defaultCacheServerIsNotCreatedWhenDisableDefaultCacheServerIsTrue() {
    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 = true;
    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)

Example 37 with CacheServerImpl

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

the class HARQueueNewImplDUnitTest method verifyRegionSize.

public static void verifyRegionSize(final Integer regionSize, final Integer msgsRegionsize) {
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        @Override
        public boolean done() {
            try {
                // Get the clientMessagesRegion and check the size.
                Region region = cache.getRegion("/" + regionName);
                int sz = region.size();
                if (regionSize.intValue() != sz) {
                    excuse = "Expected regionSize = " + regionSize.intValue() + ", actual = " + sz;
                    return false;
                }
                Iterator iter = cache.getCacheServers().iterator();
                if (!iter.hasNext()) {
                    return true;
                }
                CacheServerImpl server = (CacheServerImpl) iter.next();
                sz = server.getAcceptor().getCacheClientNotifier().getHaContainer().size();
                if (sz != msgsRegionsize.intValue()) {
                    excuse = "Expected msgsRegionsize = " + msgsRegionsize.intValue() + ", actual = " + sz;
                    return false;
                }
                return true;
            } catch (Exception e) {
                excuse = "failed due to " + e;
                return false;
            }
        }

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

Example 38 with CacheServerImpl

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

the class HAInterestTestCase method verifyInterestRegistration.

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

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

        @Override
        public String description() {
            return "waiting for cache.getCacheServers().size() == 1";
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, 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() {

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

        @Override
        public String description() {
            return "waiting for ccn.getClientProxies().size() > 0";
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
    Iterator iter_prox = ccn.getClientProxies().iterator();
    if (iter_prox.hasNext()) {
        final CacheClientProxy ccp = (CacheClientProxy) iter_prox.next();
        wc = new WaitCriterion() {

            @Override
            public boolean done() {
                Set keysMap = (Set) ccp.cils[RegisterInterestTracker.interestListIndex].getProfile(Region.SEPARATOR + REGION_NAME).getKeysOfInterestFor(ccp.getProxyID());
                return keysMap != null && keysMap.size() == 2;
            }

            @Override
            public String description() {
                return "waiting for keys of interest to include 2 keys";
            }
        };
        Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
        Set keysMap = (Set) ccp.cils[RegisterInterestTracker.interestListIndex].getProfile(Region.SEPARATOR + REGION_NAME).getKeysOfInterestFor(ccp.getProxyID());
        assertNotNull(keysMap);
        assertEquals(2, keysMap.size());
        assertTrue(keysMap.contains(k1));
        assertTrue(keysMap.contains(k2));
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Set(java.util.Set) Iterator(java.util.Iterator) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 39 with CacheServerImpl

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

the class HAStartupAndFailoverDUnitTest method startServer.

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

Example 40 with CacheServerImpl

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

the class HAStartupAndFailoverDUnitTest method stopServer.

public static void stopServer() {
    try {
        assertEquals("Expected exactly one BridgeServer", 1, cache.getCacheServers().size());
        CacheServerImpl bs = (CacheServerImpl) cache.getCacheServers().iterator().next();
        assertNotNull(bs);
        bs.stop();
    } catch (Exception ex) {
        Assert.fail("while setting stopServer", ex);
    }
}
Also used : CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

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