HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestMobCloneSnapshotFromClientCloneLinksAfterDelete.java
blobe352303f76ec58f369290e0afe0b038a6c088d03
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.HBaseTestingUtil;
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.regionserver.storefiletracker.StoreFileTrackerFactory;
35 import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils;
36 import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
37 import org.apache.hadoop.hbase.testclassification.ClientTests;
38 import org.apache.hadoop.hbase.testclassification.LargeTests;
39 import org.apache.hadoop.hbase.util.Bytes;
40 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
41 import org.junit.BeforeClass;
42 import org.junit.ClassRule;
43 import org.junit.Test;
44 import org.junit.experimental.categories.Category;
46 @Category({ LargeTests.class, ClientTests.class })
47 public class TestMobCloneSnapshotFromClientCloneLinksAfterDelete
48 extends CloneSnapshotFromClientCloneLinksAfterDeleteTestBase {
50 @ClassRule
51 public static final HBaseClassTestRule CLASS_RULE =
52 HBaseClassTestRule.forClass(TestMobCloneSnapshotFromClientCloneLinksAfterDelete.class);
54 private static boolean delayFlush = false;
56 /**
57 * This coprocessor is used to delay the flush.
59 public static class DelayFlushCoprocessor implements RegionCoprocessor, RegionObserver {
61 @Override
62 public Optional<RegionObserver> getRegionObserver() {
63 return Optional.of(this);
66 @Override
67 public void preFlush(ObserverContext<RegionCoprocessorEnvironment> e,
68 FlushLifeCycleTracker tracker) throws IOException {
69 if (delayFlush) {
70 try {
71 if (Bytes.compareTo(e.getEnvironment().getRegionInfo().getStartKey(),
72 HConstants.EMPTY_START_ROW) != 0) {
73 Thread.sleep(100);
75 } catch (InterruptedException e1) {
76 throw new InterruptedIOException(e1.getMessage());
82 protected static void setupConfiguration() {
83 CloneSnapshotFromClientTestBase.setupConfiguration();
84 TEST_UTIL.getConfiguration().setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, 0);
85 TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0);
88 @BeforeClass
89 public static void setUpBeforeClass() throws Exception {
90 setupConfiguration();
91 TEST_UTIL.startMiniCluster(3);
94 @Override
95 protected void createTable() throws IOException, InterruptedException {
96 MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName,
97 SnapshotTestingUtils.getSplitKeys(), getNumReplicas(),
98 StoreFileTrackerFactory.Trackers.DEFAULT.name(), DelayFlushCoprocessor.class.getName(),
99 FAMILY);
102 @Override
103 protected int numRowsToLoad() {
104 return 20;
107 @Override
108 protected int countRows(Table table) throws IOException {
109 return MobSnapshotTestingUtils.countMobRows(table);
112 @Test
113 @Override
114 public void testCloneLinksAfterDelete() throws IOException, InterruptedException {
115 // delay the flush to make sure
116 delayFlush = true;
117 SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 20, FAMILY);
118 long tid = EnvironmentEdgeManager.currentTime();
119 String snapshotName3 = "snaptb3-" + tid;
120 TableName clonedTableName3 =
121 TableName.valueOf(name.getMethodName() + EnvironmentEdgeManager.currentTime());
122 admin.snapshot(snapshotName3, tableName);
123 delayFlush = false;
124 int snapshot3Rows = -1;
125 try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
126 snapshot3Rows = HBaseTestingUtil.countRows(table);
128 admin.cloneSnapshot(snapshotName3, clonedTableName3);
129 admin.deleteSnapshot(snapshotName3);
130 super.testCloneLinksAfterDelete();
131 verifyRowCount(TEST_UTIL, clonedTableName3, snapshot3Rows);
132 admin.disableTable(clonedTableName3);
133 admin.deleteTable(clonedTableName3);