/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.util.test;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * 
 */
public abstract class AbstractRedisTestCase {
  private JedisPool _jedisPool;
  private String _redisPrefix;
  
  @BeforeClass
  public void launchJedisPool() {
    _jedisPool = new JedisPool("localhost");
    _redisPrefix = System.getProperty("user.name") + "_" + System.currentTimeMillis();
  }
  
  @AfterClass
  public void clearJedisPool() {
    if (_jedisPool == null) {
      return;
    }
    _jedisPool.destroy();
  }
  
  @BeforeMethod
  public void clearRedisDb() {
    Jedis jedis = _jedisPool.getResource();
    jedis.flushDB();
    _jedisPool.returnResource(jedis);
  }

  /**
   * Gets the jedisPool.
   * @return the jedisPool
   */
  protected JedisPool getJedisPool() {
    return _jedisPool;
  }

  /**
   * Gets the redisPrefix.
   * @return the redisPrefix
   */
  protected String getRedisPrefix() {
    return _redisPrefix;
  }

}

@@ -433,120 +433,1042 @@
 %7B%0A  
-private JedisPool _jedisPool;%0A  private String _redisPrefix;%0A  %0A  @BeforeClass%0A  public void launchJedisPool() %7B
+/**%0A   * Set this property to control which host the test cases will connect to.%0A   * Defaults to localhost.%0A   */%0A  public static final String REDIS_HOST_PROPERTY_NAME = %22test.redis.host%22;%0A  /**%0A   * Set this property to control which port the test cases will connec to.%0A   * Defaults to 6379.%0A   */%0A  public static final String REDIS_PORT_PROPERTY_NAME = %22test.redis.port%22;%0A  %0A  private static final String DEFAULT_REDIS_HOST = %22localhost%22;%0A  private static final int DEFAULT_REDIS_PORT = 6379;%0A  %0A  private JedisPool _jedisPool;%0A  private String _redisPrefix;%0A  %0A  @BeforeClass%0A  public void launchJedisPool() %7B%0A    String redisHost = DEFAULT_REDIS_HOST;%0A    String redisHostProperty = System.getProperty(REDIS_HOST_PROPERTY_NAME);%0A    if (redisHostProperty != null) %7B%0A      redisHost = redisHostProperty;%0A    %7D%0A    int redisPort = DEFAULT_REDIS_PORT;%0A    String redisPortProperty = System.getProperty(REDIS_PORT_PROPERTY_NAME);%0A    if (redisPortProperty != null) %7B%0A      redisPort = Integer.parseInt(redisPortProperty);%0A    %7D%0A    
 %0A   
@@ -1495,27 +1495,36 @@
 disPool(
-%22localhost%22
+redisHost, redisPort
 );%0A    _

Use properties to control redis parameters.