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.hadoop.hbase.client;
19  
20  import java.io.IOException;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.hbase.HBaseTestingUtility;
25  import org.apache.hadoop.hbase.TableName;
26  import org.apache.hadoop.hbase.mob.MobConstants;
27  import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils;
28  import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
29  import org.apache.hadoop.hbase.testclassification.LargeTests;
30  import org.junit.BeforeClass;
31  import org.junit.experimental.categories.Category;
32  
33  /**
34   * Test clone snapshots from the client
35   */
36  @Category({LargeTests.class})
37  public class TestMobCloneSnapshotFromClient extends TestCloneSnapshotFromClient {
38    private static final Log LOG = LogFactory.getLog(TestMobCloneSnapshotFromClient.class);
39  
40    protected static void setupConfiguration() {
41      TestCloneSnapshotFromClient.setupConfiguration();
42      TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0);
43    }
44  
45    @BeforeClass
46    public static void setUpBeforeClass() throws Exception {
47      setupConfiguration();
48      TEST_UTIL.startMiniCluster(3);
49    }
50  
51    @Override
52    protected void createTableAndSnapshots() throws Exception {
53      // create Table and disable it
54      MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY);
55      admin.disableTable(tableName);
56  
57      // take an empty snapshot
58      admin.snapshot(emptySnapshot, tableName);
59  
60      Connection c = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
61      Table table = c.getTable(tableName);
62      try {
63        // enable table and insert data
64        admin.enableTable(tableName);
65        SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
66        snapshot0Rows = MobSnapshotTestingUtils.countMobRows(table);
67        admin.disableTable(tableName);
68  
69        // take a snapshot
70        admin.snapshot(snapshotName0, tableName);
71  
72        // enable table and insert more data
73        admin.enableTable(tableName);
74        SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
75        snapshot1Rows = MobSnapshotTestingUtils.countMobRows(table);
76        admin.disableTable(tableName);
77  
78        // take a snapshot of the updated table
79        admin.snapshot(snapshotName1, tableName);
80  
81        // re-enable table
82        admin.enableTable(tableName);
83      } finally {
84        table.close();
85      }
86    }
87  
88    @Override
89    protected void verifyRowCount(final HBaseTestingUtility util, final TableName tableName,
90        long expectedRows) throws IOException {
91      MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows);
92    }
93  }