use of com.fiftyonred.mock_jedis.MockJedisCluster in project druid by druid-io.
the class RedisClusterCacheTest method setUp.
@Before
public void setUp() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(cacheConfig.getMaxTotalConnections());
poolConfig.setMaxIdle(cacheConfig.getMaxIdleConnections());
poolConfig.setMinIdle(cacheConfig.getMinIdleConnections());
// orginal MockJedisCluster does not provide full support for all public get/set interfaces
// some methods must be overriden for test cases
cache = new RedisClusterCache(new MockJedisCluster(Collections.singleton(new HostAndPort("localhost", 6379))) {
final ConcurrentHashMap<String, byte[]> cacheStorage = new ConcurrentHashMap<>();
@Override
public String setex(final byte[] key, final int seconds, final byte[] value) {
cacheStorage.put(StringUtils.encodeBase64String(key), value);
return null;
}
@Override
public byte[] get(final byte[] key) {
return cacheStorage.get(StringUtils.encodeBase64String(key));
}
@Override
public List<byte[]> mget(final byte[]... keys) {
mgetCount.incrementAndGet();
List<byte[]> ret = new ArrayList<>();
for (byte[] key : keys) {
String k = StringUtils.encodeBase64String(key);
byte[] value = cacheStorage.get(k);
ret.add(value);
}
return ret;
}
}, cacheConfig);
}
Aggregations