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.tools.hbase;
19  
20  import org.apache.omid.committable.hbase.HBaseCommitTableConfig;
21  import org.apache.omid.timestamp.storage.HBaseTimestampStorageConfig;
22  import org.apache.hadoop.conf.Configuration;
23  import org.apache.hadoop.hbase.HBaseConfiguration;
24  import org.apache.hadoop.hbase.HBaseTestingUtility;
25  import org.apache.hadoop.hbase.TableName;
26  import org.apache.hadoop.hbase.client.HBaseAdmin;
27  import org.testng.annotations.AfterClass;
28  import org.testng.annotations.BeforeClass;
29  import org.testng.annotations.Test;
30  
31  import static org.apache.omid.tools.hbase.OmidTableManager.COMMIT_TABLE_COMMAND_NAME;
32  import static org.apache.omid.tools.hbase.OmidTableManager.TIMESTAMP_TABLE_COMMAND_NAME;
33  import static org.testng.Assert.assertEquals;
34  import static org.testng.Assert.assertTrue;
35  
36  public class TestOmidTableManager {
37  
38      private HBaseTestingUtility hBaseTestUtil;
39      private Configuration hbaseConf;
40      private HBaseAdmin hBaseAdmin;
41  
42      @BeforeClass
43      public void setUpClass() throws Exception {
44          // HBase setup
45          hbaseConf = HBaseConfiguration.create();
46          hbaseConf.setBoolean("hbase.localcluster.assign.random.ports",true);
47          hBaseTestUtil = new HBaseTestingUtility(hbaseConf);
48          hBaseTestUtil.startMiniCluster(1);
49  
50          hBaseAdmin = hBaseTestUtil.getHBaseAdmin();
51      }
52  
53      @AfterClass
54      public void tearDownClass() throws Exception {
55  
56          hBaseAdmin.close();
57  
58          hBaseTestUtil.shutdownMiniCluster();
59  
60      }
61  
62      @Test(timeOut = 20_000)
63      public void testCreateDefaultTimestampTableSucceeds() throws Throwable {
64  
65          String[] args = new String[]{TIMESTAMP_TABLE_COMMAND_NAME};
66  
67          OmidTableManager omidTableManager = new OmidTableManager(args);
68          omidTableManager.executeActionsOnHBase(hbaseConf);
69  
70          TableName tableName = TableName.valueOf(HBaseTimestampStorageConfig.DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME);
71  
72          assertTrue(hBaseAdmin.tableExists(tableName));
73          int numRegions = hBaseAdmin.getTableRegions(tableName).size();
74          assertEquals(numRegions, 1, "Should have only 1 region");
75  
76      }
77  
78      @Test(timeOut = 20_000)
79      public void testCreateDefaultCommitTableSucceeds() throws Throwable {
80  
81          String[] args = new String[]{COMMIT_TABLE_COMMAND_NAME};
82  
83          OmidTableManager omidTableManager = new OmidTableManager(args);
84          omidTableManager.executeActionsOnHBase(hbaseConf);
85  
86          TableName tableName = TableName.valueOf(HBaseCommitTableConfig.DEFAULT_COMMIT_TABLE_NAME);
87  
88          assertTrue(hBaseAdmin.tableExists(tableName));
89          int numRegions = hBaseAdmin.getTableRegions(tableName).size();
90          assertEquals(numRegions, 16, "Should have 16 regions");
91  
92      }
93  
94      @Test(timeOut = 20_000)
95      public void testCreateCustomCommitTableSucceeds() throws Throwable {
96  
97          String[] args = new String[]{COMMIT_TABLE_COMMAND_NAME, "-tableName", "my-commit-table", "-numRegions", "1"};
98  
99          OmidTableManager omidTableManager = new OmidTableManager(args);
100         omidTableManager.executeActionsOnHBase(hbaseConf);
101 
102         TableName tableName = TableName.valueOf("my-commit-table");
103 
104         assertTrue(hBaseAdmin.tableExists(tableName));
105         int numRegions = hBaseAdmin.getTableRegions(tableName).size();
106         assertEquals(numRegions, 1, "Should have only 1 regions");
107     }
108 
109     @Test(expectedExceptions = IllegalArgumentException.class, timeOut = 20_000)
110     public void testExceptionIsThrownWhenSpecifyingAWrongCommand() throws Throwable {
111 
112         String[] args = new String[]{"non-recognized-command"};
113 
114         OmidTableManager omidTableManager = new OmidTableManager(args);
115         omidTableManager.executeActionsOnHBase(hbaseConf);
116 
117     }
118 
119 }