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
{
49 public static final HBaseClassTestRule CLASS_RULE
=
50 HBaseClassTestRule
.forClass(TestMobCloneSnapshotFromClientCloneLinksAfterDelete
.class);
52 private static boolean delayFlush
= false;
55 * This coprocessor is used to delay the flush.
57 public static class DelayFlushCoprocessor
implements RegionCoprocessor
, RegionObserver
{
60 public Optional
<RegionObserver
> getRegionObserver() {
61 return Optional
.of(this);
65 public void preFlush(ObserverContext
<RegionCoprocessorEnvironment
> e
,
66 FlushLifeCycleTracker tracker
) throws IOException
{
69 if (Bytes
.compareTo(e
.getEnvironment().getRegionInfo().getStartKey(),
70 HConstants
.EMPTY_START_ROW
) != 0) {
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);
87 public static void setUpBeforeClass() throws Exception
{
89 TEST_UTIL
.startMiniCluster(3);
93 protected void createTable() throws IOException
, InterruptedException
{
94 MobSnapshotTestingUtils
.createMobTable(TEST_UTIL
, tableName
,
95 SnapshotTestingUtils
.getSplitKeys(), getNumReplicas(), DelayFlushCoprocessor
.class.getName(),
100 protected int numRowsToLoad() {
105 protected int countRows(Table table
) throws IOException
{
106 return MobSnapshotTestingUtils
.countMobRows(table
);
111 public void testCloneLinksAfterDelete() throws IOException
, InterruptedException
{
112 // delay the flush to make sure
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
);
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
);