logger.info("Redis:");
createService(VCAP_REDIS_SERVICE, "redis", "2.2");
int tunnelPort = LOCAL_PORT + 3;
createTunnelServer(VCAP_REDIS_SERVICE, tunnelPort);
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
connectionFactory.setHostName(LOCAL_HOST);
connectionFactory.setPort(tunnelPort);
connectionFactory.setPassword(svc_passwd);
connectionFactory.setUsePool(true);
connectionFactory.afterPropertiesSet();
RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.afterPropertiesSet();
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
// Test data
ObjectMapper objectMapper = new ObjectMapper();
Map<String,Object> dataMap = null;
try {
dataMap = objectMapper.readValue(new File("data/load.json"), Map.class);
} catch (IOException e) {
e.printStackTrace();
}
List<Map<String, Object>> l = (List<Map<String, Object>>) dataMap.get("records");
Map<String, String> values = new HashMap<String, String>();
List<String> ids = new ArrayList<String>();
for (Map<String, Object> m : l) {
Map<String, Object> rec = (Map<String, Object>) m.get("record");
String id = "rec-" + rec.get("_id");
values.put(id, (String) rec.get("name"));
ids.add(id);
}
valueOps.multiSet(values);
List<String> names = valueOps.multiGet(ids);
Assert.assertEquals("Did not load the data correctly", 200, names.size());
connectionFactory.destroy();
stopTunnelServer();
removeService(VCAP_REDIS_SERVICE);
logger.info("Time elapsed: " + (System.currentTimeMillis() - start) / 1000.0d + " sec");
}