HBASE-23949 refactor loadBalancer implements for rsgroup balance by table to achieve...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestMobCloneSnapshotFromClientCloneLinksAfterDelete.java
blobb3b4e061c07680fbf096ffe890ec97473673e0f6
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.hadoop.hbase.client;
20 import java.io.IOException;
21 import java.io.InterruptedIOException;
22 import java.util.Optional;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseTestingUtility;
25 import org.apache.hadoop.hbase.HConstants;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
28 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor;
29 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
30 import org.apache.hadoop.hbase.coprocessor.RegionObserver;
31 import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner;
32 import org.apache.hadoop.hbase.mob.MobConstants;
33 import org.apache.hadoop.hbase.regionserver.FlushLifeCycleTracker;
34 import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils;
35 import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
36 import org.apache.hadoop.hbase.testclassification.ClientTests;
37 import org.apache.hadoop.hbase.testclassification.LargeTests;
38 import org.apache.hadoop.hbase.util.Bytes;
39 import org.junit.BeforeClass;
40 import org.junit.ClassRule;
41 import org.junit.Test;
42 import org.junit.experimental.categories.Category;
44 @Category({ LargeTests.class, ClientTests.class })
45 public class TestMobCloneSnapshotFromClientCloneLinksAfterDelete
46 extends CloneSnapshotFromClientCloneLinksAfterDeleteTestBase {
48 @ClassRule
49 public static final HBaseClassTestRule CLASS_RULE =
50 HBaseClassTestRule.forClass(TestMobCloneSnapshotFromClientCloneLinksAfterDelete.class);
52 private static boolean delayFlush = false;
54 /**
55 * This coprocessor is used to delay the flush.
57 public static class DelayFlushCoprocessor implements RegionCoprocessor, RegionObserver {
59 @Override
60 public Optional<RegionObserver> getRegionObserver() {
61 return Optional.of(this);
64 @Override
65 public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e,
66 FlushLifeCycleTracker tracker) throws IOException {
67 if (delayFlush) {
68 try {
69 if (Bytes.compareTo(e.getEnvironment().getRegionInfo().getStartKey(),
70 HConstants.EMPTY_START_ROW) != 0) {
71 Thread.sleep(100);
73 } catch (InterruptedException e1) {
74 throw new InterruptedIOException(e1.getMessage());
80 protected static void setupConfiguration() {
81 CloneSnapshotFromClientTestBase.setupConfiguration();
82 TEST_UTIL.getConfiguration().setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, 0);
83 TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0);
86 @BeforeClass
87 public static void setUpBeforeClass() throws Exception {
88 setupConfiguration();
89 TEST_UTIL.startMiniCluster(3);
92 @Override
93 protected void createTable() throws IOException, InterruptedException {
94 MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName,
95 SnapshotTestingUtils.getSplitKeys(), getNumReplicas(), DelayFlushCoprocessor.class.getName(),
96 FAMILY);
99 @Override
100 protected int numRowsToLoad() {
101 return 20;
104 @Override
105 protected int countRows(Table table) throws IOException {
106 return MobSnapshotTestingUtils.countMobRows(table);
109 @Test
110 @Override
111 public void testCloneLinksAfterDelete() throws IOException, InterruptedException {
112 // delay the flush to make sure
113 delayFlush = true;
114 SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 20, FAMILY);
115 long tid = System.currentTimeMillis();
116 String snapshotName3 = "snaptb3-" + tid;
117 TableName clonedTableName3 =
118 TableName.valueOf(name.getMethodName() + System.currentTimeMillis());
119 admin.snapshot(snapshotName3, tableName);
120 delayFlush = false;
121 int snapshot3Rows = -1;
122 try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
123 snapshot3Rows = HBaseTestingUtility.countRows(table);
125 admin.cloneSnapshot(snapshotName3, clonedTableName3);
126 admin.deleteSnapshot(snapshotName3);
127 super.testCloneLinksAfterDelete();
128 verifyRowCount(TEST_UTIL, clonedTableName3, snapshot3Rows);
129 admin.disableTable(clonedTableName3);
130 admin.deleteTable(clonedTableName3);