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.assertEquals;
21
22 import org.apache.hadoop.hbase.client.Get;
23 import org.apache.hadoop.hbase.client.Put;
24 import org.apache.hadoop.hbase.client.Result;
25 import org.apache.hadoop.hbase.util.Bytes;
26 import org.testng.ITestContext;
27 import org.testng.annotations.Test;
28
29 @Test(groups = "sharedHBase")
30 public class TestAutoFlush extends OmidTestBase {
31
32 @Test(timeOut = 10_000)
33 public void testReadWithSeveralUncommitted(ITestContext context) throws Exception {
34
35 byte[] family = Bytes.toBytes(TEST_FAMILY);
36 byte[] row = Bytes.toBytes("row");
37 byte[] col = Bytes.toBytes("col1");
38 byte[] data = Bytes.toBytes("data");
39 TransactionManager tm = newTransactionManager(context);
40 TTable table = new TTable(connection, TEST_TABLE);
41
42
43 table.setAutoFlush(false);
44
45 Transaction t = tm.begin();
46 Put put = new Put(row);
47 put.addColumn(family, col, data);
48 table.put(t, put);
49
50
51 Get get = new Get(row);
52 Result result = table.getHTable().get(get);
53 assertEquals(result.size(), 0, "Writes are already in DB");
54
55
56 result = table.get(t,get);
57 assertEquals(result.size(), 1, "Writes should be read by same transaction");
58
59 tm.commit(t);
60
61
62
63 result = table.getHTable().get(get);
64 assertEquals(result.size(), 2, "Writes were not flushed to DB");
65 }
66
67 }