1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.transaction;
19
20 import static org.apache.omid.transaction.CellUtils.hasCell;
21 import static org.apache.omid.transaction.CellUtils.hasShadowCell;
22 import static org.testng.Assert.assertTrue;
23
24 import java.util.Arrays;
25
26 import org.apache.hadoop.hbase.client.Get;
27 import org.apache.hadoop.hbase.client.Put;
28 import org.apache.hadoop.hbase.client.Result;
29 import org.apache.hadoop.hbase.util.Bytes;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.testng.ITestContext;
33 import org.testng.annotations.Test;
34
35 @Test(groups = "sharedHBase")
36 public class TestMarkPutAsCommitted extends OmidTestBase {
37
38 private static final Logger LOG = LoggerFactory.getLogger(TestMarkPutAsCommitted.class);
39
40 private static final String TEST_FAMILY = "data";
41
42 static final byte[] row = Bytes.toBytes("test-sc");
43 static final byte[] family = Bytes.toBytes(TEST_FAMILY);
44 private static final byte[] qualifier = Bytes.toBytes("testdata-1");
45 private static final byte[] data1 = Bytes.toBytes("testWrite-1");
46 private static final byte[] data2 = Bytes.toBytes("testWrite-2");
47
48 @Test(timeOut = 60_000)
49 public void testShadowCellsExistanceInAutocommit(ITestContext context) throws Exception {
50
51 TransactionManager tm = newTransactionManager(context);
52
53 TTable table = new TTable(connection, TEST_TABLE);
54
55 HBaseTransaction t1 = (HBaseTransaction) tm.begin();
56
57
58 Put put = new Put(row);
59 put.addColumn(family, qualifier, data1);
60
61 put = TTable.markPutAsCommitted(put, t1.getWriteTimestamp(), t1.getWriteTimestamp());
62
63 table.getHTable().put(put);
64
65
66 assertTrue(hasCell(row, family, qualifier, t1.getStartTimestamp(), new TTableCellGetterAdapter(table)),
67 "Cell should be there");
68 assertTrue(hasShadowCell(row, family, qualifier, t1.getStartTimestamp(), new TTableCellGetterAdapter(table)),
69 "Shadow cell should be there");
70 }
71
72 @Test(timeOut = 60_000)
73 public void testReadAfterAutocommit(ITestContext context) throws Exception {
74
75 TransactionManager tm = newTransactionManager(context);
76
77 TTable table = new TTable(connection, TEST_TABLE);
78
79 HBaseTransaction t1 = (HBaseTransaction) tm.begin();
80
81 Put put = new Put(row);
82 put.addColumn(family, qualifier, data1);
83
84 table.put(t1, put);
85
86 tm.commit(t1);
87
88
89 assertTrue(hasCell(row, family, qualifier, t1.getStartTimestamp(), new TTableCellGetterAdapter(table)),
90 "Cell should be there");
91 assertTrue(hasShadowCell(row, family, qualifier, t1.getStartTimestamp(), new TTableCellGetterAdapter(table)),
92 "Shadow cell should be there");
93
94 Transaction t2 = tm.begin();
95 Get get = new Get(row);
96 get.addColumn(family, qualifier);
97
98 Result getResult = table.get(t2, get);
99 assertTrue(Arrays.equals(data1, getResult.getValue(family, qualifier)), "Values should be the same");
100
101
102 HBaseTransaction t3 = (HBaseTransaction) tm.begin();
103
104 Put put1 = new Put(row);
105 put1.addColumn(family, qualifier, data2);
106
107 put1 = TTable.markPutAsCommitted(put1, t3.getWriteTimestamp(), t3.getWriteTimestamp());
108
109 table.getHTable().put(put1);
110
111
112 assertTrue(hasCell(row, family, qualifier, t1.getStartTimestamp(), new TTableCellGetterAdapter(table)),
113 "Cell should be there");
114 assertTrue(hasShadowCell(row, family, qualifier, t1.getStartTimestamp(), new TTableCellGetterAdapter(table)),
115 "Shadow cell should be there");
116
117 Transaction t4 = tm.begin();
118
119 getResult = table.get(t4, get);
120
121 assertTrue(Arrays.equals(data2, getResult.getValue(family, qualifier)), "Values should be the same");
122 }
123 }