View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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          // Turn off autoflush
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          // Data shouldn't be in DB yet
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          //data should be readable within same transaction
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          // After commit, both the cell and shadow cell should be there.
62          // That's why we check for two elements in the test assertion
63          result = table.getHTable().get(get);
64          assertEquals(result.size(), 2, "Writes were not flushed to DB");
65      }
66  
67  }