コード例 #1
0
  @Test(expected = PoolException.class)
  public void testGetResourceCreationUnsuccessful() throws Exception {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), 3333);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    pool.getResource();
  }
コード例 #2
0
  @Test(expected = PoolException.class)
  public void testCreateWithPasswordNoPassword() {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.setPassword("notthepassword");
    pool.afterPropertiesSet();
    pool.getResource();
  }
コード例 #3
0
  @Test(expected = PoolException.class)
  public void testCreateWithDbIndexInvalid() {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.setDatabase(17);
    pool.afterPropertiesSet();
    pool.getResource();
  }
コード例 #4
0
  @Test
  public void testCreateWithDbIndex() {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.setDatabase(1);
    pool.afterPropertiesSet();
    assertNotNull(pool.getResource());
  }
コード例 #5
0
  @Ignore("Redis must have requirepass set to run this test")
  @Test(expected = PoolException.class)
  public void testCreateInvalidPassword() {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.setPassword("bad");
    pool.afterPropertiesSet();
    pool.getResource();
  }
コード例 #6
0
  @Test
  public void testGetResource() {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    client.ping();
    client.close();
  }
コード例 #7
0
  @Test
  public void testGetResourceValidate() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setTestOnBorrow(true);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    client.close();
  }
コード例 #8
0
  @Ignore("Redis must have requirepass set to run this test")
  @Test
  public void testCreatePassword() {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.setPassword("foo");
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> conn = pool.getResource();
    conn.ping();
    conn.close();
  }
コード例 #9
0
  /** @see DATAREDIS-524 */
  @Test
  public void testCreateSentinelWithPassword() {

    pool =
        new DefaultLettucePool(
            new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234")));
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.setPassword("foo");
    pool.afterPropertiesSet();

    RedisURI redisUri = (RedisURI) getField(pool.getClient(), "redisURI");

    assertThat(redisUri.getPassword(), is(equalTo(pool.getPassword().toCharArray())));
  }
コード例 #10
0
  @Test
  public void testReturnResource() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    pool.returnResource(client);
    assertNotNull(pool.getResource());
    client.close();
  }
コード例 #11
0
  @Test
  public void testGetResourcePoolExhausted() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    try {
      pool.getResource();
      fail("PoolException should be thrown when pool exhausted");
    } catch (PoolException e) {
    } finally {
      client.close();
    }
  }
コード例 #12
0
  @Test
  public void testReturnBrokenResource() {

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    RedisAsyncConnection<byte[], byte[]> client = pool.getResource();
    assertNotNull(client);
    pool.returnBrokenResource(client);
    RedisAsyncConnection<byte[], byte[]> client2 = pool.getResource();
    assertNotSame(client, client2);
    try {
      client.ping();
      fail("Broken resouce connection should be closed");
    } catch (RedisException e) {
    } finally {
      client.close();
      client2.close();
    }
  }