Search in sources :

Example 66 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project bigbluebutton by bigbluebutton.

the class MessageSender method start.

public void start() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(32);
    config.setMaxIdle(8);
    config.setMinIdle(1);
    config.setTestOnBorrow(true);
    config.setTestOnReturn(true);
    config.setTestWhileIdle(true);
    config.setNumTestsPerEvictionRun(12);
    config.setMaxWaitMillis(5000);
    config.setTimeBetweenEvictionRunsMillis(60000);
    config.setBlockWhenExhausted(true);
    // Set the name of this client to be able to distinguish when doing
    // CLIENT LIST on redis-cli
    redisPool = new JedisPool(config, host, port, Protocol.DEFAULT_TIMEOUT, null, Protocol.DEFAULT_DATABASE, "BbbWebPub");
    log.info("Redis message publisher starting!");
    try {
        sendMessage = true;
        Runnable messageSender = new Runnable() {

            public void run() {
                while (sendMessage) {
                    try {
                        MessageToSend msg = messages.take();
                        publish(msg.getChannel(), msg.getMessage());
                    } catch (InterruptedException e) {
                        log.warn("Failed to get message from queue.");
                    }
                }
            }
        };
        msgSenderExec.execute(messageSender);
    } catch (Exception e) {
        log.error("Error subscribing to channels: " + e.getMessage());
    }
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisPool(redis.clients.jedis.JedisPool)

Example 67 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project athenz by yahoo.

the class DataSourceFactoryTest method testPoolConfigDefaultValues.

@Test
public void testPoolConfigDefaultValues() {
    GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
    assertNotNull(config);
    assertEquals(config.getMaxTotal(), GenericObjectPoolConfig.DEFAULT_MAX_TOTAL);
    assertEquals(config.getMaxIdle(), GenericObjectPoolConfig.DEFAULT_MAX_IDLE);
    assertEquals(config.getMinIdle(), GenericObjectPoolConfig.DEFAULT_MIN_IDLE);
    assertEquals(config.getMaxWaitMillis(), GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS);
    assertEquals(config.getMinEvictableIdleTimeMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    assertEquals(config.getTimeBetweenEvictionRunsMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    assertTrue(config.getTestWhileIdle());
    assertTrue(config.getTestOnBorrow());
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Test(org.testng.annotations.Test)

Example 68 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project athenz by yahoo.

the class DataSourceFactoryTest method testPoolConfigInvalidValues.

@Test
public void testPoolConfigInvalidValues() {
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "a");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "b");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "c");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "d");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "e");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "f");
    GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
    assertNotNull(config);
    assertEquals(config.getMaxTotal(), GenericObjectPoolConfig.DEFAULT_MAX_TOTAL);
    assertEquals(config.getMaxIdle(), GenericObjectPoolConfig.DEFAULT_MAX_IDLE);
    assertEquals(config.getMinIdle(), GenericObjectPoolConfig.DEFAULT_MIN_IDLE);
    assertEquals(config.getMaxWaitMillis(), GenericObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS);
    assertEquals(config.getMinEvictableIdleTimeMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    assertEquals(config.getTimeBetweenEvictionRunsMillis(), BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    assertTrue(config.getTestWhileIdle());
    assertTrue(config.getTestOnBorrow());
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Test(org.testng.annotations.Test)

Example 69 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project athenz by yahoo.

the class DataSourceFactoryTest method testPoolConfigZeroValues.

@Test
public void testPoolConfigZeroValues() {
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "0");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "0");
    GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
    assertNotNull(config);
    // MaxTotal and MaxIdle are set to -1 if the value is 0
    assertEquals(config.getMaxTotal(), -1);
    assertEquals(config.getMaxIdle(), -1);
    assertEquals(config.getMinIdle(), 0);
    assertEquals(config.getMaxWaitMillis(), 0);
    assertEquals(config.getMinEvictableIdleTimeMillis(), 0);
    assertEquals(config.getTimeBetweenEvictionRunsMillis(), 0);
    assertTrue(config.getTestWhileIdle());
    assertTrue(config.getTestOnBorrow());
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Test(org.testng.annotations.Test)

Example 70 with GenericObjectPoolConfig

use of org.apache.commons.pool2.impl.GenericObjectPoolConfig in project athenz by yahoo.

the class DataSourceFactoryTest method testPoolConfigSpecifiedValues.

@Test
public void testPoolConfigSpecifiedValues() {
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL, "10");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE, "20");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE, "30");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT, "40");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT, "50");
    System.setProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL, "60");
    GenericObjectPoolConfig config = DataSourceFactory.setupPoolConfig();
    assertNotNull(config);
    assertEquals(config.getMaxTotal(), 10);
    assertEquals(config.getMaxIdle(), 20);
    assertEquals(config.getMinIdle(), 30);
    assertEquals(config.getMaxWaitMillis(), 40);
    assertEquals(config.getMinEvictableIdleTimeMillis(), 50);
    assertEquals(config.getTimeBetweenEvictionRunsMillis(), 60);
    assertTrue(config.getTestWhileIdle());
    assertTrue(config.getTestOnBorrow());
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_TOTAL);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MIN_IDLE);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_MAX_WAIT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_TIMEOUT);
    System.clearProperty(DataSourceFactory.ATHENZ_PROP_DBPOOL_EVICT_IDLE_INTERVAL);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) Test(org.testng.annotations.Test)

Aggregations

GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)69 Test (org.junit.Test)50 Jedis (redis.clients.jedis.Jedis)26 ShardedJedis (redis.clients.jedis.ShardedJedis)26 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)26 JedisPool (redis.clients.jedis.JedisPool)17 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)12 ArrayList (java.util.ArrayList)10 JedisShardInfo (redis.clients.jedis.JedisShardInfo)10 URI (java.net.URI)7 Test (org.testng.annotations.Test)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Transaction (redis.clients.jedis.Transaction)4 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)4 BaseTest (com.sohu.tv.test.base.BaseTest)3 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)3 LoadingCacheTest (com.alicp.jetcache.LoadingCacheTest)2 RefreshCacheTest (com.alicp.jetcache.RefreshCacheTest)2 AbstractExternalCacheTest (com.alicp.jetcache.test.external.AbstractExternalCacheTest)2 URISyntaxException (java.net.URISyntaxException)2