Package redis.clients.jedis

Examples of redis.clients.jedis.JedisSentinelPool$MasterListener


    public void initializeWithNotAvailableSentinelsShouldThrowException() {
  Set<String> wrongSentinels = new HashSet<String>();
  wrongSentinels.add(new HostAndPort("localhost", 65432).toString());
  wrongSentinels.add(new HostAndPort("localhost", 65431).toString());

  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME,
    wrongSentinels);
  pool.destroy();
    }
View Full Code Here


    }

    @Test(expected = JedisException.class)
    public void initializeWithNotMonitoredMasterNameShouldThrowException() {
  final String wrongMasterName = "wrongMasterName";
  JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName,
    sentinels);
  pool.destroy();
    }
View Full Code Here

    @Test
    public void checkCloseableConnections() throws Exception {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();

  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.close();
  assertTrue(pool.isClosed());
    }
View Full Code Here

  assertTrue(pool.isClosed());
    }

    @Test
    public void ensureSafeTwiceFailover() throws InterruptedException {
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    new GenericObjectPoolConfig(), 1000, "foobared", 2);

  forceFailover(pool);
  // after failover sentinel needs a bit of time to stabilize before a new
  // failover
View Full Code Here

    @Test
    public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis jedis = pool.getResource();
  Jedis jedis2 = null;

  try {
      jedis.set("hello", "jedis");
      Transaction t = jedis.multi();
      t.set("hello", "world");
      pool.returnResource(jedis);

      jedis2 = pool.getResource();

      assertTrue(jedis == jedis2);
      assertEquals("jedis", jedis2.get("hello"));
  } catch (JedisConnectionException e) {
      if (jedis2 != null) {
    pool.returnBrokenResource(jedis2);
    jedis2 = null;
      }
  } finally {
      if (jedis2 != null)
    pool.returnResource(jedis2);

      pool.destroy();
  }
    }
View Full Code Here

    @Test
    public void checkResourceIsCloseable() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis jedis = pool.getResource();
  try {
      jedis.set("hello", "jedis");
  } finally {
      jedis.close();
  }

  Jedis jedis2 = pool.getResource();
  try {
      assertEquals(jedis, jedis2);
  } finally {
      jedis2.close();
  }
View Full Code Here

    @Test
    public void returnResourceWithNullResource() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis nullJedis = null;
  pool.returnResource(nullJedis);
  pool.destroy();
    }
View Full Code Here

    @Test
    public void returnBrokenResourceWithNullResource() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis nullJedis = null;
  pool.returnBrokenResource(nullJedis);
  pool.destroy();
    }
View Full Code Here

  private void initializeDatabaseConnection() throws LifecycleException {
    try {
      if (getSentinelMaster() != null) {
        Set<String> sentinelSet = getSentinelSet();
        if (sentinelSet != null && sentinelSet.size() > 0) {
          connectionPool = new JedisSentinelPool(getSentinelMaster(), sentinelSet, this.connectionPoolConfig, getTimeout(), getPassword());
        } else {
          throw new LifecycleException("Error configuring Redis Sentinel connection pool: expected both `sentinelMaster` and `sentiels` to be configured");
        }
      } else {
        connectionPool = new JedisPool(this.connectionPoolConfig, getHost(), getPort(), getTimeout(), getPassword());
View Full Code Here

   * @param config
   * @return
   * @since 1.4
   */
  protected Pool<Jedis> createRedisSentinelPool(RedisSentinelConfiguration config) {
    return new JedisSentinelPool(config.getMaster().getName(), convertToJedisSentinelSet(config.getSentinels()),
        getPoolConfig() != null ? getPoolConfig() : new JedisPoolConfig(), getShardInfo().getTimeout(), getShardInfo()
            .getPassword());
  }
View Full Code Here

TOP

Related Classes of redis.clients.jedis.JedisSentinelPool$MasterListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.