HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / master / TestMasterFileSystem.java
blobf08462424a50d9bced6cef9c41f7f07f4e9d8388
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.master;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
23 import java.util.List;
24 import org.apache.hadoop.fs.FileSystem;
25 import org.apache.hadoop.fs.Path;
26 import org.apache.hadoop.hbase.HBaseClassTestRule;
27 import org.apache.hadoop.hbase.HBaseTestingUtil;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.client.Table;
30 import org.apache.hadoop.hbase.regionserver.HRegion;
31 import org.apache.hadoop.hbase.testclassification.MasterTests;
32 import org.apache.hadoop.hbase.testclassification.MediumTests;
33 import org.apache.hadoop.hbase.util.Bytes;
34 import org.apache.hadoop.hbase.util.CommonFSUtils;
35 import org.junit.AfterClass;
36 import org.junit.BeforeClass;
37 import org.junit.ClassRule;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.experimental.categories.Category;
41 import org.junit.rules.TestName;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 /**
46 * Test the master filesystem in a local cluster
48 @Category({MasterTests.class, MediumTests.class})
49 public class TestMasterFileSystem {
51 @ClassRule
52 public static final HBaseClassTestRule CLASS_RULE =
53 HBaseClassTestRule.forClass(TestMasterFileSystem.class);
55 @Rule
56 public TestName name = new TestName();
58 private static final Logger LOG = LoggerFactory.getLogger(TestMasterFileSystem.class);
60 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
62 @BeforeClass
63 public static void setupTest() throws Exception {
64 UTIL.startMiniCluster();
67 @AfterClass
68 public static void teardownTest() throws Exception {
69 UTIL.shutdownMiniCluster();
72 @Test
73 public void testFsUriSetProperly() throws Exception {
74 HMaster master = UTIL.getMiniHBaseCluster().getMaster();
75 MasterFileSystem fs = master.getMasterFileSystem();
76 Path masterRoot = CommonFSUtils.getRootDir(fs.getConfiguration());
77 Path rootDir = CommonFSUtils.getRootDir(fs.getFileSystem().getConf());
78 // make sure the fs and the found root dir have the same scheme
79 LOG.debug("from fs uri:" + FileSystem.getDefaultUri(fs.getFileSystem().getConf()));
80 LOG.debug("from configuration uri:" + FileSystem.getDefaultUri(fs.getConfiguration()));
81 // make sure the set uri matches by forcing it.
82 assertEquals(masterRoot, rootDir);
85 @Test
86 public void testCheckNoTempDir() throws Exception {
87 final MasterFileSystem masterFileSystem =
88 UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
90 final TableName tableName = TableName.valueOf(name.getMethodName());
91 final byte[] FAM = Bytes.toBytes("fam");
92 final byte[][] splitKeys = new byte[][] {
93 Bytes.toBytes("b"), Bytes.toBytes("c"), Bytes.toBytes("d")
96 UTIL.createTable(tableName, FAM, splitKeys);
98 // get the current store files for the regions
99 List<HRegion> regions = UTIL.getHBaseCluster().getRegions(tableName);
100 // make sure we have 4 regions serving this table
101 assertEquals(4, regions.size());
103 // load the table
104 try (Table table = UTIL.getConnection().getTable(tableName)) {
105 UTIL.loadTable(table, FAM);
108 // disable the table so that we can manipulate the files
109 UTIL.getAdmin().disableTable(tableName);
111 final Path tempDir = masterFileSystem.getTempDir();
112 final Path tempNsDir = CommonFSUtils.getNamespaceDir(tempDir,
113 tableName.getNamespaceAsString());
114 final FileSystem fs = masterFileSystem.getFileSystem();
116 // checks the temporary directory does not exist
117 assertFalse(fs.exists(tempNsDir));
119 UTIL.deleteTable(tableName);