public void testConflict() throws Exception {
Dao<TestRecord> dao = new SpecificAvroDao<TestRecord>(tablePool,
tableName, schemaString, TestRecord.class);
// create key and entity, and do a put
TestRecord entity = createSpecificEntity("part1", "part2");
assertTrue(dao.put(entity));
// now fetch the entity twice. Change one, and do a put. Change the other,
// and the second put should fail.
PartitionKey key = new PartitionKey("part1", "part2");
TestRecord recordRef1 = TestRecord.newBuilder(dao.get(key))
.setField1("part1_1").build();
TestRecord recordRef2 = TestRecord.newBuilder(dao.get(key))
.setField1("part1_2").build();
assertTrue(dao.put(recordRef1));
assertFalse(dao.put(recordRef2));
// Now get the latest version, change it, and put should succeed.
recordRef2 = dao.get(key);
assertEquals("part1_1", recordRef2.getField1());
recordRef2 = TestRecord.newBuilder(recordRef2).setField1("part1_2").build();
assertTrue(dao.put(recordRef2));
// validate the most recent values.
TestRecord finalRecord = dao.get(key);
assertEquals("part1_2", finalRecord.getField1());
// if we put a new entity, there should be a conflict
assertFalse(dao.put(entity));
}