Search in sources :

Example 1 with CacheServer

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

the class InternalDistributedSystem method createAndStartCacheServers.

/**
   * after an auto-reconnect we may need to recreate a cache server and start it
   */
public void createAndStartCacheServers(List<CacheServerCreation> cacheServerCreation, InternalCache cache) {
    List<CacheServer> servers = cache.getCacheServers();
    // to recreate it.
    if (servers.isEmpty() && cacheServerCreation != null) {
        for (CacheServerCreation bridge : cacheServerCreation) {
            CacheServerImpl impl = (CacheServerImpl) cache.addCacheServer();
            impl.configureFrom(bridge);
        }
    }
    servers = cache.getCacheServers();
    for (CacheServer server : servers) {
        try {
            if (!server.isRunning()) {
                server.start();
            }
        } catch (IOException ex) {
            throw new GemFireIOException(LocalizedStrings.CacheCreation_WHILE_STARTING_CACHE_SERVER_0.toLocalizedString(server), ex);
        }
    }
}
Also used : CacheServerCreation(org.apache.geode.internal.cache.xmlcache.CacheServerCreation) CacheServer(org.apache.geode.cache.server.CacheServer) GemFireIOException(org.apache.geode.GemFireIOException) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException)

Example 2 with CacheServer

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

the class RestAPIsWithSSLDUnitTest method startBridgeServer.

@SuppressWarnings("deprecation")
protected int startBridgeServer(String hostName, int restServicePort, final String locators, final String[] regions, final Properties sslProperties, boolean clusterLevel) {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, locators);
    props.setProperty(START_DEV_REST_API, "true");
    props.setProperty(HTTP_SERVICE_BIND_ADDRESS, hostName);
    props.setProperty(HTTP_SERVICE_PORT, String.valueOf(restServicePort));
    System.setProperty("javax.net.debug", "ssl,handshake");
    props = configureSSL(props, sslProperties, clusterLevel);
    DistributedSystem ds = getSystem(props);
    InternalCache cache = (InternalCache) CacheFactory.create(ds);
    cache.setReadSerialized(true);
    AttributesFactory factory = new AttributesFactory();
    factory.setEnableBridgeConflation(true);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attrs = factory.create();
    for (int i = 0; i < regions.length; i++) {
        cache.createRegion(regions[i], attrs);
    }
    CacheServer server = cache.addCacheServer();
    server.setPort(0);
    try {
        server.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    remoteObjects.put(CACHE_KEY, cache);
    return server.getPort();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Example 3 with CacheServer

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

the class ConnectionPoolDUnitTest method startBridgeServer.

protected void startBridgeServer(int port, int socketBufferSize, long loadPollInterval) throws IOException {
    Cache cache = getCache();
    CacheServer bridge = cache.addCacheServer();
    bridge.setPort(port);
    if (socketBufferSize != -1) {
        bridge.setSocketBufferSize(socketBufferSize);
    }
    bridge.setMaxThreads(getMaxThreads());
    bridge.setLoadPollInterval(loadPollInterval);
    bridge.start();
    bridgeServerPort = bridge.getPort();
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer)

Example 4 with CacheServer

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

the class ConnectionPoolImplJUnitTest method testCreatePool.

@Test
public void testCreatePool() throws Exception {
    CacheServer server1 = cache.addCacheServer();
    int port1 = port;
    server1.setPort(port1);
    server1.start();
    PoolFactory cpf = PoolManager.createFactory();
    cpf.addServer("localhost", port1);
    cpf.setSubscriptionEnabled(true);
    cpf.setSubscriptionRedundancy(0);
    PoolImpl pool = (PoolImpl) cpf.create("pool1");
    ServerLocation location1 = new ServerLocation("localhost", port1);
    Op testOp = new Op() {

        public Object attempt(Connection cnx) throws Exception {
            return cnx.getServer();
        }

        @Override
        public boolean useThreadLocalConnection() {
            return true;
        }
    };
    assertEquals(location1, pool.executeOnPrimary(testOp));
    assertEquals(location1, pool.executeOnQueuesAndReturnPrimaryResult(testOp));
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) CacheServer(org.apache.geode.cache.server.CacheServer) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with CacheServer

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

the class ConnectionPoolImplJUnitTest method testExecuteOp.

@Test
public void testExecuteOp() throws Exception {
    CacheServer server1 = cache.addCacheServer();
    CacheServer server2 = cache.addCacheServer();
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    int port1 = ports[0];
    int port2 = ports[1];
    server1.setPort(port1);
    server2.setPort(port2);
    server1.start();
    server2.start();
    PoolFactory cpf = PoolManager.createFactory();
    cpf.addServer("localhost", port2);
    cpf.addServer("localhost", port1);
    PoolImpl pool = (PoolImpl) cpf.create("pool1");
    ServerLocation location1 = new ServerLocation("localhost", port1);
    ServerLocation location2 = new ServerLocation("localhost", port2);
    Op testOp = new Op() {

        int attempts = 0;

        public Object attempt(Connection cnx) throws Exception {
            if (attempts == 0) {
                attempts++;
                throw new SocketTimeoutException();
            } else {
                return cnx.getServer();
            }
        }

        @Override
        public boolean useThreadLocalConnection() {
            return true;
        }
    };
    // TODO - set retry attempts, and throw in some assertions
    // about how many times we retry
    ServerLocation usedServer = (ServerLocation) pool.execute(testOp);
    assertTrue("expected " + location1 + " or " + location2 + ", got " + usedServer, location1.equals(usedServer) || location2.equals(usedServer));
    testOp = new Op() {

        public Object attempt(Connection cnx) throws Exception {
            throw new SocketTimeoutException();
        }

        @Override
        public boolean useThreadLocalConnection() {
            return true;
        }
    };
    try {
        usedServer = (ServerLocation) pool.execute(testOp);
        fail("Should have failed");
    } catch (ServerConnectivityException expected) {
    // do nothing
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SocketTimeoutException(java.net.SocketTimeoutException) PoolFactory(org.apache.geode.cache.client.PoolFactory) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) SocketTimeoutException(java.net.SocketTimeoutException) CacheServer(org.apache.geode.cache.server.CacheServer) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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