//Rebuild the keyspace and get the object mapper
cm.buildKeyspace(definition, true);
logger.debug("Built keyspace: {}", definition.getName());
cm.setDefaultKeyspace(definition);
ObjectMapper om = cm.getObjectMapper();
om.setLogCql(true);
//Set up test data
int nDataItems = 200;
List<Map<String, Object>> values2 = Lists.newArrayList();
Integer ttl = 4;
// insert additional data, we are testing for counts > 50
for (int i = 0; i < nDataItems; i++) {
Map<String, Object> value = Maps.newHashMap();
value.put("account_id", "00000003-0000-0030-0040-000000030000");
value.put("user_id", "00000003-0000-0030-0040-000000030000");
value.put("field2", "Value" + (i + 8));
values2.add(value);
}
List<Map<String, Object>> updatedValues2 = Lists.newArrayList();
for (Map<String, Object> baseValue : values2) {
Map<String, Object> value = JsonUtil.rhombusMapFromJsonMap(baseValue, definition.getDefinitions().get("object2"));
value.put("_ttl", ttl);
updatedValues2.add(value);
}
Map<String, List<Map<String, Object>>> multiInsertMap = Maps.newHashMap();
multiInsertMap.put("object2", updatedValues2);
//Insert data with 4-second TTL
om.insertBatchMixed(multiInsertMap);
// Sleep for five seconds
Thread.sleep(5000);
//Count the number of inserts we made
SortedMap<String, Object> indexValues = Maps.newTreeMap();
indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
Criteria criteria = new Criteria();
criteria.setIndexKeys(indexValues);
// Should be zero.
long count = om.count("object2", criteria);
assertEquals(0, count);
// Good. Now let's make sure we aren't crazy.
values2 = Lists.newArrayList();
for (int i = 0; i < nDataItems; i++) {
Map<String, Object> value = Maps.newHashMap();
value.put("account_id", "00000003-0000-0030-0040-000000030000");
value.put("user_id", "00000003-0000-0030-0040-000000030000");
value.put("field2", "Value" + (i + 8));
value.put("_ttl", ttl);
values2.add(value);
}
Integer shortTimeToLive = 4;
Integer longTimeToLive = 6;
int numThatShouldBeExcluded = 15;
int numThatShouldRemain = nDataItems - numThatShouldBeExcluded;
int j = 0;
updatedValues2 = Lists.newArrayList();
for (Map<String, Object> baseValue : values2) {
if (j < numThatShouldBeExcluded) {
ttl = shortTimeToLive;
}
else {
ttl = longTimeToLive;
}
j++;
Map<String, Object> value = JsonUtil.rhombusMapFromJsonMap(baseValue, definition.getDefinitions().get("object2"));
value.put("_ttl", ttl);
updatedValues2.add(value);
}
multiInsertMap = Maps.newHashMap();
multiInsertMap.put("object2", updatedValues2);
//Insert data with 4-second TTL
om.insertBatchMixed(multiInsertMap);
// Sleep for five seconds
Thread.sleep(5000);
//Count the number of inserts we made
indexValues = Maps.newTreeMap();
indexValues.put("account_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
indexValues.put("user_id", UUID.fromString("00000003-0000-0030-0040-000000030000"));
criteria = new Criteria();
criteria.setIndexKeys(indexValues);
// Should be 185
count = om.count("object2", criteria);
assertEquals(numThatShouldRemain, count);
cm.teardown();
}