Search in sources :

Example 21 with PoolFactoryImpl

use of org.apache.geode.internal.cache.PoolFactoryImpl 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 22 with PoolFactoryImpl

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

the class Bug37805DUnitTest method getClientPool.

private Pool getClientPool(String host, int server1Port, boolean establishCallbackConnection, int redundancyLevel) {
    PoolFactory pf = PoolManager.createFactory();
    pf.addServer(host, server1Port).setSubscriptionEnabled(establishCallbackConnection).setSubscriptionRedundancy(redundancyLevel);
    return ((PoolFactoryImpl) pf).getPoolAttributes();
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Example 23 with PoolFactoryImpl

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

the class CacheServerTestUtil method createPool.

public static void createPool(PoolAttributes poolAttr) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    DistributedSystem ds = new CacheServerTestUtil().getSystem(props);
    ;
    PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
    pf.init(poolAttr);
    PoolImpl p = (PoolImpl) pf.create("CacheServerTestUtil");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setPoolName(p.getName());
    RegionAttributes attrs = factory.create();
    pool = p;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) DistributedSystem(org.apache.geode.distributed.DistributedSystem) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Example 24 with PoolFactoryImpl

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

the class Bug36829DUnitTest method getClientPool.

private Pool getClientPool(String host, int server1Port, boolean establishCallbackConnection, int redundancyLevel) {
    PoolFactory pf = PoolManager.createFactory();
    pf.addServer(host, server1Port).setSubscriptionEnabled(establishCallbackConnection).setSubscriptionRedundancy(redundancyLevel);
    return ((PoolFactoryImpl) pf).getPoolAttributes();
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Example 25 with PoolFactoryImpl

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

the class CqDataUsingPoolDUnitTest method getClientPool.

private Pool getClientPool(String host, int serverPort) {
    PoolFactory pf = PoolManager.createFactory();
    pf.addServer(host, serverPort).setSubscriptionAckInterval(1).setSubscriptionEnabled(true);
    return ((PoolFactoryImpl) pf).getPoolAttributes();
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Aggregations

PoolFactoryImpl (org.apache.geode.internal.cache.PoolFactoryImpl)27 PoolFactory (org.apache.geode.cache.client.PoolFactory)10 Test (org.junit.Test)9 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)7 Pool (org.apache.geode.cache.client.Pool)6 RegionAttributes (org.apache.geode.cache.RegionAttributes)5 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Host (org.apache.geode.test.dunit.Host)4 VM (org.apache.geode.test.dunit.VM)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 DiskStore (org.apache.geode.cache.DiskStore)2 ServerLoad (org.apache.geode.cache.server.ServerLoad)2 IgnoredException (org.apache.geode.test.dunit.IgnoredException)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2