}
@Test
public void runTestCleanupAfterConflict() throws Exception {
TransactionManager tm = new TransactionManager(hbaseConf);
TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);
TransactionState t1 = tm.beginTransaction();
LOG.info("Transaction created " + t1);
TransactionState t2 = tm.beginTransaction();
LOG.info("Transaction created" + t2);
byte[] row = Bytes.toBytes("test-simple");
byte[] fam = Bytes.toBytes(TEST_FAMILY);
byte[] col = Bytes.toBytes("testdata");
byte[] data1 = Bytes.toBytes("testWrite-1");
byte[] data2 = Bytes.toBytes("testWrite-2");
Put p = new Put(row);
p.add(fam, col, data1);
tt.put(t1, p);
Get g = new Get(row).setMaxVersions();
Result r = tt.get(g);
assertEquals("Unexpected size for read.", 1, r.size());
assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
Bytes.equals(data1, r.getValue(fam, col)));
Put p2 = new Put(row);
p2.add(fam, col, data2);
tt.put(t2, p2);
r = tt.get(g);
assertEquals("Unexpected size for read.", 2, r.size());
r = tt.get(t2, g);
assertEquals("Unexpected size for read.", 1, r.size());
assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
Bytes.equals(data2, r.getValue(fam, col)));
tm.tryCommit(t1);
boolean aborted = false;
try {
tm.tryCommit(t2);
assertTrue("Transaction commited successfully", false);
} catch (CommitUnsuccessfulException e) {
aborted = true;
}
assertTrue("Transaction didn't raise exception", aborted);
r = tt.get(g);
assertEquals("Unexpected size for read.", 1, r.size());
assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
Bytes.equals(data1, r.getValue(fam, col)));
}