Search in sources :

Example 56 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class CacheXmlParser method doServer.

/**
   * @since GemFire 5.7
   */
private void doServer(Attributes atts) {
    PoolFactory f = (PoolFactory) stack.peek();
    String host = atts.getValue(HOST).trim();
    int port = parseInt(atts.getValue(PORT));
    f.addServer(host, port);
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory)

Example 57 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class ConnectionPoolFactoryJUnitTest method testCreateDefaultAndInvalidAndLegitAttributes.

@Test
public void testCreateDefaultAndInvalidAndLegitAttributes() {
    PoolFactory cpf = PoolManager.createFactory();
    ((PoolFactoryImpl) cpf).setStartDisabled(true);
    try {
        cpf.create("illegal");
        fail("expected IllegalStateException");
    } catch (IllegalStateException expected) {
    }
    cpf.addServer("localhost", 40907);
    Pool defaultAttr = cpf.create("defaults");
    try {
        // now add a source and try defaults again
        assertEquals(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT, defaultAttr.getFreeConnectionTimeout());
        assertEquals(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS, defaultAttr.getThreadLocalConnections());
        assertEquals(PoolFactory.DEFAULT_READ_TIMEOUT, defaultAttr.getReadTimeout());
        assertEquals(PoolFactory.DEFAULT_MIN_CONNECTIONS, defaultAttr.getMinConnections());
        assertEquals(PoolFactory.DEFAULT_MAX_CONNECTIONS, defaultAttr.getMaxConnections());
        assertEquals(PoolFactory.DEFAULT_RETRY_ATTEMPTS, defaultAttr.getRetryAttempts());
        assertEquals(PoolFactory.DEFAULT_IDLE_TIMEOUT, defaultAttr.getIdleTimeout());
        assertEquals(PoolFactory.DEFAULT_PING_INTERVAL, defaultAttr.getPingInterval());
        assertEquals(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE, defaultAttr.getSocketBufferSize());
    } finally {
        defaultAttr.destroy();
    }
    /*
     * Lets configure each attribute and make sure they are reflected in the attributes
     */
    int connectionTimeout = -1;
    int connectionLifetime = -2;
    boolean threadLocalConnections = false;
    int readTimeout = -1;
    int messageTrackingTimeout = -1;
    int ackInterval = -1;
    int minConnections = -1;
    int maxConnections = -2;
    int retryAttempts = -2;
    int pingInterval = -1;
    int idleTimeout = -2;
    int redundancy = -2;
    int bufferSize = -1;
    /* All of these should fail */
    try {
        cpf.setFreeConnectionTimeout(connectionTimeout);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setLoadConditioningInterval(connectionLifetime);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setReadTimeout(readTimeout);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setMinConnections(minConnections);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setMaxConnections(maxConnections);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setRetryAttempts(retryAttempts);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setPingInterval(pingInterval);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setIdleTimeout(idleTimeout);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setIdleTimeout(idleTimeout);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setSocketBufferSize(bufferSize);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setSubscriptionRedundancy(redundancy);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setSubscriptionMessageTrackingTimeout(messageTrackingTimeout);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    try {
        cpf.setSubscriptionAckInterval(ackInterval);
        assertTrue("This should have failed with IllegalArgumentException", false);
    } catch (IllegalArgumentException iae) {
    // this is what we want
    }
    /* none of those should take effect so this should still match default */
    defaultAttr = cpf.create("default");
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getFreeConnectionTimeout(), PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getLoadConditioningInterval(), PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getThreadLocalConnections(), PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getReadTimeout(), PoolFactory.DEFAULT_READ_TIMEOUT);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getMinConnections(), PoolFactory.DEFAULT_MIN_CONNECTIONS);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getMaxConnections(), PoolFactory.DEFAULT_MAX_CONNECTIONS);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getRetryAttempts(), PoolFactory.DEFAULT_RETRY_ATTEMPTS);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getIdleTimeout(), PoolFactory.DEFAULT_IDLE_TIMEOUT);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getPingInterval(), PoolFactory.DEFAULT_PING_INTERVAL);
    assertEquals("Attribute should match default, but doesn't", defaultAttr.getSocketBufferSize(), PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE);
    /* Lets do a legitimate one now */
    connectionTimeout = 30;
    connectionLifetime = -1;
    threadLocalConnections = true;
    readTimeout = 3;
    minConnections = 6;
    maxConnections = 7;
    retryAttempts = 2;
    pingInterval = 23;
    idleTimeout = 14;
    messageTrackingTimeout = 40;
    ackInterval = 33;
    redundancy = 4;
    bufferSize = 1000;
    cpf.setFreeConnectionTimeout(connectionTimeout);
    cpf.setLoadConditioningInterval(connectionLifetime);
    cpf.setThreadLocalConnections(threadLocalConnections);
    cpf.setReadTimeout(readTimeout);
    cpf.setSubscriptionEnabled(true);
    cpf.setSubscriptionRedundancy(redundancy);
    cpf.setSubscriptionMessageTrackingTimeout(messageTrackingTimeout);
    cpf.setSubscriptionAckInterval(ackInterval);
    cpf.setMinConnections(minConnections);
    cpf.setMaxConnections(maxConnections);
    cpf.setRetryAttempts(retryAttempts);
    cpf.setPingInterval(pingInterval);
    cpf.setIdleTimeout(idleTimeout);
    cpf.setSocketBufferSize(bufferSize);
    Pool cpa = cpf.create("mypool");
    try {
        assertEquals(connectionTimeout, cpa.getFreeConnectionTimeout());
        assertEquals(connectionLifetime, cpa.getLoadConditioningInterval());
        assertEquals(threadLocalConnections, cpa.getThreadLocalConnections());
        assertEquals(true, cpa.getSubscriptionEnabled());
        assertEquals(redundancy, cpa.getSubscriptionRedundancy());
        assertEquals(messageTrackingTimeout, cpa.getSubscriptionMessageTrackingTimeout());
        assertEquals(readTimeout, cpa.getReadTimeout());
        assertEquals(minConnections, cpa.getMinConnections());
        assertEquals(maxConnections, cpa.getMaxConnections());
        assertEquals(ackInterval, cpa.getSubscriptionAckInterval());
        assertEquals(retryAttempts, cpa.getRetryAttempts());
        assertEquals(idleTimeout, cpa.getIdleTimeout());
        assertEquals(pingInterval, cpa.getPingInterval());
        assertEquals(bufferSize, cpa.getSocketBufferSize());
        // validate contacts
        assertEquals(1, cpa.getServers().size());
        assertEquals(0, cpa.getLocators().size());
    } finally {
        cpa.destroy();
    }
    // test reset
    cpf.reset();
    try {
        cpf.create("mypool");
        fail("expected IllegalStateException");
    } catch (IllegalStateException expected) {
    // since reset emptied out the contacts
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) Pool(org.apache.geode.cache.client.Pool) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 58 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class ConnectionPoolImplJUnitTest method testCacheClose.

@Test
public void testCacheClose() throws Exception {
    PoolFactory cpf = PoolManager.createFactory();
    cpf.addLocator("localhost", AvailablePortHelper.getRandomAvailableTCPPort());
    Pool pool1 = cpf.create("pool1");
    Pool pool2 = cpf.create("pool2");
    cache.close();
    assertTrue(pool1.isDestroyed());
    assertTrue(pool2.isDestroyed());
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) Pool(org.apache.geode.cache.client.Pool) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 59 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class ConnectionPoolImplJUnitTest method testProperties.

@Test
public void testProperties() throws Exception {
    int readTimeout = 234234;
    PoolFactory cpf = PoolManager.createFactory();
    cpf.addServer("localhost", port).setReadTimeout(readTimeout).setThreadLocalConnections(true);
    PoolImpl pool = (PoolImpl) cpf.create("myfriendlypool");
    // check non default
    assertEquals("myfriendlypool", pool.getName());
    assertEquals(readTimeout, pool.getReadTimeout());
    assertEquals(true, pool.getThreadLocalConnections());
    assertEquals(1, pool.getServers().size());
    assertEquals(0, pool.getLocators().size());
    {
        InetSocketAddress addr = (InetSocketAddress) pool.getServers().get(0);
        assertEquals(port, addr.getPort());
        assertEquals("localhost", addr.getHostName());
    }
    LiveServerPinger lsp = new LiveServerPinger(pool);
    long NANOS_PER_MS = 1000000L;
    assertEquals(((pool.getPingInterval() + 1) / 2) * NANOS_PER_MS, lsp.pingIntervalNanos);
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) InetSocketAddress(java.net.InetSocketAddress) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 60 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory in project geode by apache.

the class QueryUsingPoolDUnitTest method createPool.

public void createPool(final String poolName, final String[] servers, final int[] ports, final boolean subscriptionEnabled) {
    // Create Cache.
    getCache(true);
    PoolFactory poolFactory = PoolManager.createFactory();
    poolFactory.setSubscriptionEnabled(subscriptionEnabled);
    for (int i = 0; i < servers.length; i++) {
        logger.info("### Adding to Pool. ### Server : " + servers[i] + " Port : " + ports[i]);
        poolFactory.addServer(servers[i], ports[i]);
    }
    poolFactory.setMinConnections(1);
    poolFactory.setMaxConnections(5);
    poolFactory.setRetryAttempts(5);
    poolFactory.create(poolName);
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory)

Aggregations

PoolFactory (org.apache.geode.cache.client.PoolFactory)66 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)21 CacheServer (org.apache.geode.cache.server.CacheServer)16 Properties (java.util.Properties)15 AttributesFactory (org.apache.geode.cache.AttributesFactory)14 Host (org.apache.geode.test.dunit.Host)13 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)12 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)12 Cache (org.apache.geode.cache.Cache)11 Pool (org.apache.geode.cache.client.Pool)11 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)11 PoolFactoryImpl (org.apache.geode.internal.cache.PoolFactoryImpl)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 VM (org.apache.geode.test.dunit.VM)9 Region (org.apache.geode.cache.Region)8 EventID (org.apache.geode.internal.cache.EventID)8 IOException (java.io.IOException)7 ClientCache (org.apache.geode.cache.client.ClientCache)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7