Search in sources :

Example 41 with CacheServer

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

the class CacheXml66DUnitTest method testDefaultCacheServerBindAddress.

@Test
public void testDefaultCacheServerBindAddress() throws Exception {
    CacheCreation cache = new CacheCreation();
    CacheServer bs = cache.addCacheServer();
    bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    CacheServer server = (CacheServer) cache.getCacheServers().iterator().next();
    assertNotNull(server);
    assertEquals(CacheServer.DEFAULT_BIND_ADDRESS, server.getBindAddress());
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 42 with CacheServer

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

the class CacheXml80DUnitTest method testCacheServerDisableTcpNoDelay.

@Test
public void testCacheServerDisableTcpNoDelay() throws Exception {
    CacheCreation cache = new CacheCreation();
    CacheServer cs = cache.addCacheServer();
    cs.setPort(0);
    cs.setTcpNoDelay(false);
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setDataPolicy(DataPolicy.NORMAL);
    cache.createVMRegion("rootNORMAL", attrs);
    testXml(cache);
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 43 with CacheServer

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

the class ClientServerCCEDUnitTest method createServerRegion.

private int createServerRegion(VM vm, final String regionName, final boolean replicatedRegion) {
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            // TombstoneService.VERBOSE = true;
            AttributesFactory af = new AttributesFactory();
            if (replicatedRegion) {
                af.setScope(Scope.DISTRIBUTED_ACK);
                af.setDataPolicy(DataPolicy.REPLICATE);
            } else {
                af.setDataPolicy(DataPolicy.PARTITION);
                af.setPartitionAttributes((new PartitionAttributesFactory()).setTotalNumBuckets(2).create());
            }
            TestRegion = (LocalRegion) createRootRegion(regionName, af.create());
            CacheServer server = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailableTCPPort();
            server.setPort(port);
            server.start();
            return port;
        }
    };
    return (Integer) vm.invoke(createRegion);
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer)

Example 44 with CacheServer

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

the class MultiVMRegionTestCase method versionTestGIISendsTombstones.

/*
   * This test creates a server cache in vm0 and a peer cache in vm1. It then tests to see if GII
   * transferred tombstones to vm1 like it's supposed to. A client cache is created in vm2 and the
   * same sort of check is performed for register-interest.
   */
public void versionTestGIISendsTombstones() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final int serverPort = AvailablePortHelper.getRandomAvailableTCPPort();
    // create replicated regions in VM 0 and 1, then perform concurrent ops
    // on the same key while creating the region in VM2. Afterward make
    // sure that all three regions are consistent
    final String name = this.getUniqueName() + "-CC";
    SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

        @Override
        public void run() {
            try {
                RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                CCRegion = (LocalRegion) f.create(name);
                if (VM.getCurrentVMNum() == 0) {
                    CacheServer bridge = CCRegion.getCache().addCacheServer();
                    bridge.setPort(serverPort);
                    try {
                        bridge.start();
                    } catch (IOException ex) {
                        fail("While creating bridge", ex);
                    }
                }
            } catch (CacheException ex) {
                fail("While creating region", ex);
            }
        }
    };
    SerializableRunnable asserter = new SerializableRunnable("ensure tombstone has been received") {

        @Override
        public void run() {
            RegionEntry entry = CCRegion.getRegionEntry("object2");
            assertTrue(entry != null);
            assertTrue(entry.isTombstone());
        }
    };
    vm0.invoke(createRegion);
    vm0.invoke(new SerializableRunnable("create some tombstones") {

        @Override
        public void run() {
            CCRegion.put("object1", "value1");
            CCRegion.put("object2", "value2");
            CCRegion.put("object3", "value3");
            CCRegion.destroy("object2");
        }
    });
    try {
        vm0.invoke(asserter);
        vm1.invoke(createRegion);
        vm1.invoke(asserter);
    // vm2.invoke(createClientCache);
    // vm2.invoke(asserter);
    } finally {
        disconnectAllFromDS();
    }
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheServer(org.apache.geode.cache.server.CacheServer) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException)

Example 45 with CacheServer

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

the class ServerLauncherTest method testStartCacheServerWithExistingCacheServer.

@Test
public void testStartCacheServerWithExistingCacheServer() throws IOException {
    final Cache mockCache = mockContext.mock(Cache.class, "Cache");
    final CacheServer mockCacheServer = mockContext.mock(CacheServer.class, "CacheServer");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getCacheServers();
            will(returnValue(Collections.singletonList(mockCacheServer)));
        }
    });
    final ServerLauncher serverLauncher = new Builder().setMemberName("serverOne").setDisableDefaultServer(false).build();
    assertNotNull(serverLauncher);
    assertEquals("serverOne", serverLauncher.getMemberName());
    assertFalse(serverLauncher.isDisableDefaultServer());
    serverLauncher.startCacheServer(mockCache);
}
Also used : Expectations(org.jmock.Expectations) Builder(org.apache.geode.distributed.ServerLauncher.Builder) CacheServer(org.apache.geode.cache.server.CacheServer) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

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