@Test(expected = PoolException.class)
  public void testGetResourceCreationUnsuccessful() throws Exception {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), 3333);
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.afterPropertiesSet();
    pool.getResource();
  }
  @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();
  }
  @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();
  }
  @Test
  public void testCreateWithDbIndex() {

    pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
    pool.setDatabase(1);
    pool.afterPropertiesSet();
    assertNotNull(pool.getResource());
  }
  @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();
  }
  @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();
  }
  @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();
  }
  @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();
  }
  /** @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())));
  }
  @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();
  }
  @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();
    }
  }
  @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();
    }
  }