Search in sources :

Example 71 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class AcceptorImplDUnitTest method testAcceptorImplCloseCleansUp.

@Test
public void testAcceptorImplCloseCleansUp() throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    try (InternalCache cache = (InternalCache) new CacheFactory(props).create()) {
        RegionFactory<Object, Object> regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
        final CacheServer server = cache.addCacheServer();
        final int port = AvailablePortHelper.getRandomAvailableTCPPort();
        server.setPort(port);
        server.start();
        regionFactory.create("region1");
        assertTrue(cache.isServer());
        assertFalse(cache.isClosed());
        Awaitility.await("Acceptor is up and running").atMost(10, SECONDS).until(() -> getAcceptorImplFromCache(cache) != null);
        AcceptorImpl acceptorImpl = getAcceptorImplFromCache(cache);
        cache.close();
        Awaitility.await("Acceptor shuts down properly").atMost(10, SECONDS).until(acceptorImpl::isShutdownProperly);
        assertTrue(cache.isClosed());
        assertFalse(acceptorImpl.isRunning());
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServer(org.apache.geode.cache.server.CacheServer) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 72 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class CacheServerTestUtil method stopCacheServers.

public static void stopCacheServers() {
    Iterator iter = getCache().getCacheServers().iterator();
    if (iter.hasNext()) {
        CacheServer server = (CacheServer) iter.next();
        server.stop();
        assertFalse(server.isRunning());
    }
}
Also used : Iterator(java.util.Iterator) CacheServer(org.apache.geode.cache.server.CacheServer)

Example 73 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class EventIDVerificationDUnitTest method createServerCache.

public static Integer createServerCache() throws Exception {
    new EventIDVerificationDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setCacheListener(new CacheListenerAdapter() {

        public void afterCreate(EntryEvent event) {
            synchronized (EventIDVerificationDUnitTest.class) {
                gotCallback = true;
                testEventIDResult = ((EntryEventImpl) event).getEventId().equals(eventId);
                EventIDVerificationDUnitTest.class.notify();
            }
        }

        public void afterUpdate(EntryEvent event) {
            synchronized (EventIDVerificationDUnitTest.class) {
                gotCallback = true;
                testEventIDResult = ((EntryEventImpl) event).getEventId().equals(eventId);
                EventIDVerificationDUnitTest.class.notify();
            }
        }

        public void afterDestroy(EntryEvent event) {
            synchronized (EventIDVerificationDUnitTest.class) {
                gotCallback = true;
                testEventIDResult = ((EntryEventImpl) event).getEventId().equals(eventId);
                EventIDVerificationDUnitTest.class.notify();
            }
        }

        public void afterRegionDestroy(RegionEvent event) {
            synchronized (EventIDVerificationDUnitTest.class) {
                gotCallback = true;
                testEventIDResult = ((RegionEventImpl) event).getEventId().equals(eventId);
                EventIDVerificationDUnitTest.class.notify();
            }
        }

        public void afterRegionClear(RegionEvent event) {
            synchronized (EventIDVerificationDUnitTest.class) {
                gotCallback = true;
                // verifyEventIDsDuringRegionDestroy(event);
                testEventIDResult = ((RegionEventImpl) event).getEventId().equals(eventId);
                EventIDVerificationDUnitTest.class.notify();
            }
        }
    });
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server1 = cache.addCacheServer();
    server1.setPort(port);
    server1.setNotifyBySubscription(true);
    server1.start();
    return new Integer(server1.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent)

Example 74 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class HAInterestTestCase method createServerCacheWithLocalRegion.

public static Integer createServerCacheWithLocalRegion() throws Exception {
    new HAInterestTestCase().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setConcurrencyChecksEnabled(true);
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    // ensures updates to be sent instead of invalidations
    server.setNotifyBySubscription(true);
    server.setMaximumTimeBetweenPings(180000);
    server.start();
    return new Integer(server.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 75 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class HAStartupAndFailoverDUnitTest method createServerCache.

public static Integer createServerCache() throws Exception {
    new HAStartupAndFailoverDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setEnableBridgeConflation(true);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    CacheServer server1 = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server1.setPort(port);
    // ensures updates to be sent instead of invalidations
    server1.setNotifyBySubscription(true);
    server1.setMaximumTimeBetweenPings(180000);
    server1.start();
    return new Integer(server1.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Aggregations

CacheServer (org.apache.geode.cache.server.CacheServer)323 AttributesFactory (org.apache.geode.cache.AttributesFactory)99 Properties (java.util.Properties)97 Test (org.junit.Test)77 Cache (org.apache.geode.cache.Cache)76 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)76 RegionAttributes (org.apache.geode.cache.RegionAttributes)60 IOException (java.io.IOException)53 ClientCache (org.apache.geode.cache.client.ClientCache)53 Region (org.apache.geode.cache.Region)50 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)49 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)33 Iterator (java.util.Iterator)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)30 Host (org.apache.geode.test.dunit.Host)27 VM (org.apache.geode.test.dunit.VM)25 DistributedSystem (org.apache.geode.distributed.DistributedSystem)20 CacheException (org.apache.geode.cache.CacheException)17 CacheFactory (org.apache.geode.cache.CacheFactory)17