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.testng.Assert.assertFalse;
21 import static org.testng.Assert.assertNotNull;
22 import static org.testng.Assert.assertTrue;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27
28 import org.apache.hadoop.hbase.Cell;
29 import org.apache.hadoop.hbase.CellUtil;
30 import org.apache.hadoop.hbase.client.Get;
31 import org.apache.hadoop.hbase.client.Put;
32 import org.apache.hadoop.hbase.client.Result;
33 import org.apache.hadoop.hbase.util.Bytes;
34 import org.testng.ITestContext;
35 import org.testng.annotations.Test;
36
37 @Test(groups = "sharedHBase")
38 public class TestReadPath extends OmidTestBase {
39
40 final byte[] family = Bytes.toBytes(TEST_FAMILY);
41 final byte[] row = Bytes.toBytes("row");
42 private final byte[] col = Bytes.toBytes("col1");
43 final byte[] data = Bytes.toBytes("data");
44 private final byte[] uncommitted = Bytes.toBytes("uncommitted");
45
46 @Test(timeOut = 10_000)
47 public void testReadInterleaved(ITestContext context) throws Exception {
48 TransactionManager tm = newTransactionManager(context);
49 TTable table = new TTable(connection, TEST_TABLE);
50
51
52 Transaction t1 = tm.begin();
53 Transaction t2 = tm.begin();
54
55 Put put = new Put(row);
56 put.addColumn(family, col, data);
57 table.put(t1, put);
58 tm.commit(t1);
59
60 Get get = new Get(row);
61 Result result = table.get(t2, get);
62 assertFalse(result.containsColumn(family, col), "Should be unable to read column");
63 }
64
65 @Test(timeOut = 10_000)
66 public void testReadWithSeveralUncommitted(ITestContext context) throws Exception {
67 TransactionManager tm = newTransactionManager(context);
68 TTable table = new TTable(connection, TEST_TABLE);
69
70
71 Transaction t = tm.begin();
72 Put put = new Put(row);
73 put.addColumn(family, col, data);
74 table.put(t, put);
75 tm.commit(t);
76 List<Transaction> running = new ArrayList<>();
77
78
79 for (int i = 0; i < 10; ++i) {
80 t = tm.begin();
81 put = new Put(row);
82 put.addColumn(family, col, uncommitted);
83 table.put(t, put);
84 running.add(t);
85 }
86
87
88 t = tm.begin();
89 Get get = new Get(row);
90 Result result = table.get(t, get);
91 Cell cell = result.getColumnLatestCell(family, col);
92 assertNotNull(cell, "KeyValue is null");
93 byte[] value = CellUtil.cloneValue(cell);
94 assertTrue(Arrays.equals(data, value), "Read data doesn't match");
95 tm.commit(t);
96
97 table.close();
98
99 for (Transaction r : running) {
100 tm.rollback(r);
101 }
102
103 }
104
105 }