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
.master
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertTrue
;
22 import static org
.junit
.Assert
.fail
;
24 import java
.util
.List
;
26 import org
.apache
.hadoop
.fs
.FileSystem
;
27 import org
.apache
.hadoop
.fs
.Path
;
28 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
29 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
30 import org
.apache
.hadoop
.hbase
.TableName
;
31 import org
.apache
.hadoop
.hbase
.client
.Table
;
32 import org
.apache
.hadoop
.hbase
.regionserver
.HRegion
;
33 import org
.apache
.hadoop
.hbase
.testclassification
.MasterTests
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
35 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
36 import org
.apache
.hadoop
.hbase
.util
.FSUtils
;
37 import org
.apache
.hadoop
.hbase
.util
.HFileArchiveTestingUtil
;
38 import org
.junit
.AfterClass
;
39 import org
.junit
.BeforeClass
;
40 import org
.junit
.ClassRule
;
41 import org
.junit
.Rule
;
42 import org
.junit
.Test
;
43 import org
.junit
.experimental
.categories
.Category
;
44 import org
.junit
.rules
.TestName
;
45 import org
.slf4j
.Logger
;
46 import org
.slf4j
.LoggerFactory
;
49 * Test the master filesystem in a local cluster
51 @Category({MasterTests
.class, MediumTests
.class})
52 public class TestMasterFileSystem
{
55 public static final HBaseClassTestRule CLASS_RULE
=
56 HBaseClassTestRule
.forClass(TestMasterFileSystem
.class);
59 public TestName name
= new TestName();
61 private static final Logger LOG
= LoggerFactory
.getLogger(TestMasterFileSystem
.class);
63 private static final HBaseTestingUtility UTIL
= new HBaseTestingUtility();
66 public static void setupTest() throws Exception
{
67 UTIL
.startMiniCluster();
71 public static void teardownTest() throws Exception
{
72 UTIL
.shutdownMiniCluster();
76 public void testFsUriSetProperly() throws Exception
{
77 HMaster master
= UTIL
.getMiniHBaseCluster().getMaster();
78 MasterFileSystem fs
= master
.getMasterFileSystem();
79 Path masterRoot
= FSUtils
.getRootDir(fs
.getConfiguration());
80 Path rootDir
= FSUtils
.getRootDir(fs
.getFileSystem().getConf());
81 // make sure the fs and the found root dir have the same scheme
82 LOG
.debug("from fs uri:" + FileSystem
.getDefaultUri(fs
.getFileSystem().getConf()));
83 LOG
.debug("from configuration uri:" + FileSystem
.getDefaultUri(fs
.getConfiguration()));
84 // make sure the set uri matches by forcing it.
85 assertEquals(masterRoot
, rootDir
);
89 public void testCheckTempDir() throws Exception
{
90 final MasterFileSystem masterFileSystem
=
91 UTIL
.getMiniHBaseCluster().getMaster().getMasterFileSystem();
93 final TableName tableName
= TableName
.valueOf(name
.getMethodName());
94 final byte[] FAM
= Bytes
.toBytes("fam");
95 final byte[][] splitKeys
= new byte[][] {
96 Bytes
.toBytes("b"), Bytes
.toBytes("c"), Bytes
.toBytes("d")
99 UTIL
.createTable(tableName
, FAM
, splitKeys
);
101 // get the current store files for the regions
102 List
<HRegion
> regions
= UTIL
.getHBaseCluster().getRegions(tableName
);
103 // make sure we have 4 regions serving this table
104 assertEquals(4, regions
.size());
107 try (Table table
= UTIL
.getConnection().getTable(tableName
)) {
108 UTIL
.loadTable(table
, FAM
);
111 // disable the table so that we can manipulate the files
112 UTIL
.getAdmin().disableTable(tableName
);
114 final Path tableDir
= FSUtils
.getTableDir(masterFileSystem
.getRootDir(), tableName
);
115 final Path tempDir
= masterFileSystem
.getTempDir();
116 final Path tempTableDir
= FSUtils
.getTableDir(tempDir
, tableName
);
117 final FileSystem fs
= masterFileSystem
.getFileSystem();
119 // move the table to the temporary directory
120 if (!fs
.rename(tableDir
, tempTableDir
)) {
124 masterFileSystem
.checkTempDir(tempDir
, UTIL
.getConfiguration(), fs
);
126 // check if the temporary directory exists and is empty
127 assertTrue(fs
.exists(tempDir
));
128 assertEquals(0, fs
.listStatus(tempDir
).length
);
130 // check for the existence of the archive directory
131 for (HRegion region
: regions
) {
132 Path archiveDir
= HFileArchiveTestingUtil
.getRegionArchiveDir(UTIL
.getConfiguration(),
134 assertTrue(fs
.exists(archiveDir
));
137 UTIL
.deleteTable(tableName
);