cm.buildKeyspace(definition, true);
cm.setDefaultKeyspace(definition);
ObjectMapper om = cm.getObjectMapper();
om.truncateTables();
CDefinition def1 = om.getKeyspaceDefinition_ONLY_FOR_TESTING().getDefinitions().get("testtype");
//do an insert on an object
Map<String, Object> testObject = Maps.newTreeMap();
testObject.put("foreignid", Long.valueOf(100));
testObject.put("type", Integer.valueOf(101));
testObject.put("instance", Long.valueOf(102));
testObject.put("filtered", Integer.valueOf(103));
testObject.put("data1", "This is data 1");
testObject.put("data2", "This is data 2");
testObject.put("data3", "This is data 3");
UUID key = (UUID)om.insert("testtype", testObject);
testObject.put("foreignid", Long.valueOf(200));
testObject.put("type", Integer.valueOf(201));
testObject.put("instance", Long.valueOf(202));
testObject.put("filtered", Integer.valueOf(203));
//manually insert that object incorrectly into other indexes
List<CQLStatement> insertStatements = Lists.newArrayList();
for(CIndex i : def1.getIndexes().values()){
om.getCqlGenerator_ONLY_FOR_TESTING().addCQLStatmentsForIndexInsert(
keyspace,
true,
insertStatements,
def1,
testObject,
i,
key,
om.getCqlGenerator_ONLY_FOR_TESTING().makeFieldAndValueList(def1, testObject), null, null);
}
for(CQLStatement s: insertStatements){
om.getCqlExecutor().executeSync(s);
}
//manually record those incorrect values in the update table
CQLStatement cql = om.getCqlGenerator_ONLY_FOR_TESTING().makeInsertUpdateIndexStatement(
keyspace,
def1,
key, def1.makeIndexValues(testObject));
om.getCqlExecutor().executeSync(cql);
//now manually record an update back to the original in the update table to simulate an eventual consistency issue
Map<String, Object> testObjectOriginal = Maps.newTreeMap();
testObjectOriginal.put("foreignid", Long.valueOf(100));
testObjectOriginal.put("type", Integer.valueOf(101));
testObjectOriginal.put("instance", Long.valueOf(102));
testObjectOriginal.put("filtered", Integer.valueOf(103));
testObjectOriginal.put("data1", "This is data 1");
testObjectOriginal.put("data2", "This is data 2");
testObjectOriginal.put("data3", "This is data 3");
cql = om.getCqlGenerator_ONLY_FOR_TESTING().makeInsertUpdateIndexStatement(
definition.getName(),
def1,
key, def1.makeIndexValues(testObjectOriginal));
om.getCqlExecutor().executeSync(cql);
//verify that the object returns different values in the static table and on those (or some of those) indexes
Map<String, Object> staticTableObject = om.getByKey("testtype", key);
assertEquals(100L,staticTableObject.get("foreignid"));