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 org.apache.hadoop.hbase.client.Get;
21  import org.apache.hadoop.hbase.client.Put;
22  import org.apache.hadoop.hbase.client.Result;
23  import org.apache.hadoop.hbase.util.Bytes;
24  import org.testng.ITestContext;
25  import org.testng.annotations.Test;
26  
27  import static org.testng.Assert.assertEquals;
28  
29  @Test(groups = "sharedHBase")
30  public class TestAutoFlush extends OmidTestBase {
31  
32      @Test
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(hbaseConf, 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.add(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          tm.commit(t);
56  
57          // After commit, both the cell and shadow cell should be there.
58          // That's why we check for two elements in the test assertion
59          result = table.getHTable().get(get);
60          assertEquals(result.size(), 2, "Writes were not flushed to DB");
61      }
62  
63  }