final HTableInterface hTestTable = context().getHTableInterface("test");
{
TRowKey primaryRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("Andrew"));
TRowKey secondaryRowKey = new TRowKey().setTableName(testTable.getTableName()).setRow(Bytes.toBytes("Brad"));
TRowLock secondaryRowLock = new TRowLock(HaeinsaConstants.ROW_LOCK_VERSION, TRowLockState.STABLE, 1380504156137L);
TRowLock primaryRowLock = new TRowLock(HaeinsaConstants.ROW_LOCK_VERSION, TRowLockState.PREWRITTEN, 1380504157100L)
.setCurrentTimestamp(1380504156000L)
.setExpiry(1380504160000L);
primaryRowLock.addToSecondaries(secondaryRowKey);
Put primaryPut = new Put(primaryRowKey.getRow());
primaryPut.add(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER,
primaryRowLock.getCurrentTimestamp(), TRowLocks.serialize(primaryRowLock));
hTestTable.put(primaryPut);
Put secondaryPut = new Put(secondaryRowKey.getRow());
secondaryPut.add(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER,
secondaryRowLock.getCommitTimestamp(), TRowLocks.serialize(secondaryRowLock));
hTestTable.put(secondaryPut);
HaeinsaTransaction tx = tm.begin();
HaeinsaGet get = new HaeinsaGet(primaryRowKey.getRow());
HaeinsaResult result = testTable.get(tx, get);
Assert.assertTrue(result.isEmpty());
Get hPrimaryGet = new Get(primaryRowKey.getRow());
hPrimaryGet.addColumn(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER);
Result primaryResult = hTestTable.get(hPrimaryGet);
TRowLock stablePrimaryRowLock = TRowLocks.deserialize(primaryResult.getValue(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER));
Assert.assertEquals(stablePrimaryRowLock.getState(), TRowLockState.STABLE);
Assert.assertEquals(stablePrimaryRowLock.getCommitTimestamp(), primaryRowLock.getCommitTimestamp());
Get hSecondaryGet = new Get(secondaryRowKey.getRow());
hSecondaryGet.addColumn(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER);
Result secondaryResult = hTestTable.get(hSecondaryGet);
TRowLock stableSecondaryRowLock = TRowLocks.deserialize(secondaryResult.getValue(HaeinsaConstants.LOCK_FAMILY, HaeinsaConstants.LOCK_QUALIFIER));
Assert.assertEquals(stableSecondaryRowLock.getState(), TRowLockState.STABLE);
Assert.assertEquals(stableSecondaryRowLock.getCommitTimestamp(), primaryRowLock.getCommitTimestamp());
}
testTable.close();
hTestTable.close();
}