HBASE-23868 : Replace usages of HColumnDescriptor(byte [] familyName)… (#1222)
[hbase.git] / hbase-backup / src / test / java / org / apache / hadoop / hbase / backup / TestBackupUtils.java
blob01481a0f65b35b129319782f47c7d9585f82ccaa
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.backup;
20 import java.io.IOException;
21 import java.security.PrivilegedAction;
23 import org.apache.hadoop.conf.Configuration;
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.HBaseTestingUtility;
28 import org.apache.hadoop.hbase.backup.util.BackupUtils;
29 import org.apache.hadoop.hbase.testclassification.SmallTests;
30 import org.apache.hadoop.security.UserGroupInformation;
31 import org.junit.Assert;
32 import org.junit.ClassRule;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 @Category(SmallTests.class)
39 public class TestBackupUtils {
40 @ClassRule
41 public static final HBaseClassTestRule CLASS_RULE =
42 HBaseClassTestRule.forClass(TestBackupUtils.class);
43 private static final Logger LOG = LoggerFactory.getLogger(TestBackupUtils.class);
45 protected static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
46 protected static Configuration conf = TEST_UTIL.getConfiguration();
48 @Test
49 public void TestGetBulkOutputDir() {
50 // Create a user who is not the current user
51 String fooUserName = "foo1234";
52 String fooGroupName = "group1";
53 UserGroupInformation
54 ugi = UserGroupInformation.createUserForTesting(fooUserName, new String[]{fooGroupName});
55 // Get user's home directory
56 Path fooHomeDirectory = ugi.doAs(new PrivilegedAction<Path>() {
57 @Override public Path run() {
58 try (FileSystem fs = FileSystem.get(conf)) {
59 return fs.getHomeDirectory();
60 } catch (IOException ioe) {
61 LOG.error("Failed to get foo's home directory", ioe);
63 return null;
65 });
67 Path bulkOutputDir = ugi.doAs(new PrivilegedAction<Path>() {
68 @Override public Path run() {
69 try {
70 return BackupUtils.getBulkOutputDir("test", conf, false);
71 } catch (IOException ioe) {
72 LOG.error("Failed to get bulk output dir path", ioe);
74 return null;
76 });
77 // Make sure the directory is in foo1234's home directory
78 Assert.assertTrue(bulkOutputDir.toString().startsWith(fooHomeDirectory.toString()));