You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nd...@apache.org on 2020/01/17 17:53:19 UTC
[hbase] branch branch-1 updated: HBASE-23665: Split unit tests from
TestTableName into a separate test-only class. (#1032) (#1051)
This is an automated email from the ASF dual-hosted git repository.
ndimiduk pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-1 by this push:
new 71bfac3 HBASE-23665: Split unit tests from TestTableName into a separate test-only class. (#1032) (#1051)
71bfac3 is described below
commit 71bfac3353090318fa56173bd6fad678114aefa0
Author: Bharath Vissapragada <bh...@apache.org>
AuthorDate: Fri Jan 17 09:52:31 2020 -0800
HBASE-23665: Split unit tests from TestTableName into a separate test-only class. (#1032) (#1051)
Signed-off-by: Nick Dimiduk <nd...@apache.org>
---
.../org/apache/hadoop/hbase/TableNameTestRule.java | 38 +++++
.../org/apache/hadoop/hbase/TestTableName.java | 186 +++++++++++++++++++++
.../regionserver/TestScannerRetriableFailure.java | 31 ++--
.../security/access/TestAccessController2.java | 29 ++--
.../access/TestCellACLWithMultipleVersions.java | 80 +++++----
.../hadoop/hbase/security/access/TestCellACLs.java | 49 +++---
.../security/access/TestScanEarlyTermination.java | 36 ++--
.../access/TestWithDisabledAuthorization.java | 117 +++++++------
.../hbase/snapshot/TestSnapshotClientRetries.java | 14 +-
.../snapshot/TestSnapshotWhenChoreCleaning.java | 8 +-
10 files changed, 395 insertions(+), 193 deletions(-)
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TableNameTestRule.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TableNameTestRule.java
new file mode 100644
index 0000000..b565426
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TableNameTestRule.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+/**
+ * Returns a {@code TableName} based on currently running test method name.
+ */
+public class TableNameTestRule extends TestWatcher {
+
+ private TableName tableName;
+
+ @Override
+ protected void starting(Description description) {
+ tableName = TableName.valueOf(description.getMethodName());
+ }
+
+ public TableName getTableName() {
+ return tableName;
+ }
+}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
new file mode 100644
index 0000000..eb1fabd
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTableName.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests for various kinds of TableNames.
+ */
+@Category({MiscTests.class, SmallTests.class})
+public class TestTableName {
+
+ private static String[] emptyNames = {"", " "};
+ private static String[] invalidNamespace = {":a", "%:a"};
+ private static String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok",
+ "with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02",
+ "dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2",
+ "trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"};
+ private static String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal",
+ "spaces not ok", "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
+ "new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"};
+
+ static class Names {
+ String ns;
+ byte[] nsb;
+ String tn;
+ byte[] tnb;
+ String nn;
+ byte[] nnb;
+
+ Names(String ns, String tn) {
+ this.ns = ns;
+ nsb = Bytes.toBytes(ns);
+ this.tn = tn;
+ tnb = Bytes.toBytes(tn);
+ nn = this.ns + ":" + this.tn;
+ nnb = Bytes.toBytes(nn);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Names names = (Names) o;
+
+ if (!ns.equals(names.ns)) {
+ return false;
+ }
+ if (!tn.equals(names.tn)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = ns.hashCode();
+ result = 31 * result + tn.hashCode();
+ return result;
+ }
+ }
+
+ private static Names[] names = new Names[] {
+ new Names("n1", "n1"),
+ new Names("n2", "n2"),
+ new Names("table1", "table1"),
+ new Names("table2", "table2"),
+ new Names("table2", "table1"),
+ new Names("table1", "table2"),
+ new Names("n1", "table1"),
+ new Names("n1", "table1"),
+ new Names("n2", "table2"),
+ new Names("n2", "table2")
+ };
+
+ @Test public void testInvalidNamespace() {
+ for (String tn : invalidNamespace) {
+ try {
+ TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
+ } catch (IllegalArgumentException ie) {
+ // expected, pass
+ continue;
+ }
+ fail("Exception not thrown for ns: " + tn);
+ }
+ }
+
+ @Test public void testEmptyNamespaceName() {
+ for (String nn : emptyNames) {
+ try {
+ TableName.isLegalNamespaceName(Bytes.toBytes(nn));
+ } catch (IllegalArgumentException iae) {
+ // expected, pass
+ continue;
+ }
+ fail("Exception not thrown for ns: " + nn);
+ }
+ }
+
+ @Test public void testEmptyTableName() {
+ for (String tn : emptyNames) {
+ try {
+ TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
+ } catch (IllegalArgumentException iae) {
+ // expected, pass
+ continue;
+ }
+ fail("Exception not thrown for table name: " + tn);
+ }
+ }
+
+ @Test public void testLegalHTableNames() {
+ for (String tn : legalTableNames) {
+ TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
+ }
+ }
+
+ @Test public void testIllegalHTableNames() {
+ for (String tn : illegalTableNames) {
+ try {
+ TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
+ } catch (Exception e) {
+ // expected, pass
+ continue;
+ }
+ fail("Exception not thrown for table name: " + tn);
+ }
+ }
+
+ @Test public void testValueOf() {
+ Map<String, TableName> inCache = new HashMap<>();
+ // fill cache
+ for (Names name : names) {
+ inCache.put(name.nn, TableName.valueOf(name.ns, name.tn));
+ }
+ for (Names name : names) {
+ assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.ns, name.tn), name));
+ assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.nsb, name.tnb), name));
+ assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.nn), name));
+ assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(name.nnb), name));
+ assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(
+ ByteBuffer.wrap(name.nsb), ByteBuffer.wrap(name.tnb)), name));
+ }
+ }
+
+ private TableName validateNames(TableName expected, Names names) {
+ assertEquals(expected.getNameAsString(), names.nn);
+ assertArrayEquals(expected.getName(), names.nnb);
+ assertEquals(expected.getQualifierAsString(), names.tn);
+ assertArrayEquals(expected.getQualifier(), names.tnb);
+ assertEquals(expected.getNamespaceAsString(), names.ns);
+ assertArrayEquals(expected.getNamespace(), names.nsb);
+ return expected;
+ }
+}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerRetriableFailure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerRetriableFailure.java
index b0b0636..350307e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerRetriableFailure.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerRetriableFailure.java
@@ -18,10 +18,10 @@
package org.apache.hadoop.hbase.regionserver;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -29,34 +29,25 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
-import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
+import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.testclassification.LargeTests;
-import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.FSUtils;
-import org.apache.hadoop.hbase.util.FSVisitor;
-import org.apache.hadoop.hbase.util.TestTableName;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
@Category(LargeTests.class)
public class TestScannerRetriableFailure {
private static final Log LOG = LogFactory.getLog(TestScannerRetriableFailure.class);
@@ -66,7 +57,7 @@ public class TestScannerRetriableFailure {
private static final String FAMILY_NAME_STR = "f";
private static final byte[] FAMILY_NAME = Bytes.toBytes(FAMILY_NAME_STR);
- @Rule public TestTableName TEST_TABLE = new TestTableName();
+ @Rule public TableNameTestRule testTable = new TableNameTestRule();
public static class FaultyScannerObserver extends BaseRegionObserver {
private int faults = 0;
@@ -109,7 +100,7 @@ public class TestScannerRetriableFailure {
@Test(timeout=180000)
public void testFaultyScanner() throws Exception {
- TableName tableName = TEST_TABLE.getTableName();
+ TableName tableName = testTable.getTableName();
Table table = UTIL.createTable(tableName, FAMILY_NAME);
try {
final int NUM_ROWS = 100;
@@ -158,7 +149,9 @@ public class TestScannerRetriableFailure {
while (true) {
Result result = scanner.next();
- if (result == null) break;
+ if (result == null) {
+ break;
+ }
count++;
}
assertEquals(numRows, count);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java
index 1beef16..ae56a20 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
import java.util.Arrays;
import java.util.List;
@@ -36,6 +35,7 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
@@ -53,7 +53,6 @@ import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.access.Permission.Action;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.TestTableName;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.junit.After;
@@ -98,7 +97,7 @@ public class TestAccessController2 extends SecureTestUtil {
private static User TESTGROUP2_USER1;
@Rule
- public TestTableName TEST_TABLE = new TestTableName();
+ public TableNameTestRule testTable = new TableNameTestRule();
private String namespace = "testNamespace";
private String tname = namespace + ":testtable1";
private TableName tableName = TableName.valueOf(tname);
@@ -179,7 +178,7 @@ public class TestAccessController2 extends SecureTestUtil {
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
- HTableDescriptor desc = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor desc = new HTableDescriptor(testTable.getTableName());
desc.addFamily(new HColumnDescriptor(TEST_FAMILY));
try (Connection connection =
ConnectionFactory.createConnection(TEST_UTIL.getConfiguration(), testUser)) {
@@ -190,11 +189,11 @@ public class TestAccessController2 extends SecureTestUtil {
return null;
}
}, testUser);
- TEST_UTIL.waitTableAvailable(TEST_TABLE.getTableName());
+ TEST_UTIL.waitTableAvailable(testTable.getTableName());
// Verify that owner permissions have been granted to the test user on the
// table just created
List<TablePermission> perms =
- AccessControlLists.getTablePermissions(conf, TEST_TABLE.getTableName())
+ AccessControlLists.getTablePermissions(conf, testTable.getTableName())
.get(testUser.getShortName());
assertNotNull(perms);
assertFalse(perms.isEmpty());
@@ -213,7 +212,7 @@ public class TestAccessController2 extends SecureTestUtil {
AccessTestAction createAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
- HTableDescriptor desc = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor desc = new HTableDescriptor(testTable.getTableName());
desc.addFamily(new HColumnDescriptor(TEST_FAMILY));
try (Connection connection =
ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
@@ -254,13 +253,13 @@ public class TestAccessController2 extends SecureTestUtil {
User nsCreate = User.createUserForTesting(conf, "nsCreate", new String[0]);
User nsAdmin = User.createUserForTesting(conf, "nsAdmin", new String[0]);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsRead.getShortName(),
- TEST_TABLE.getTableName().getNamespaceAsString(), Action.READ);
+ testTable.getTableName().getNamespaceAsString(), Action.READ);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsWrite.getShortName(),
- TEST_TABLE.getTableName().getNamespaceAsString(), Action.WRITE);
+ testTable.getTableName().getNamespaceAsString(), Action.WRITE);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsCreate.getShortName(),
- TEST_TABLE.getTableName().getNamespaceAsString(), Action.CREATE);
+ testTable.getTableName().getNamespaceAsString(), Action.CREATE);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsAdmin.getShortName(),
- TEST_TABLE.getTableName().getNamespaceAsString(), Action.ADMIN);
+ testTable.getTableName().getNamespaceAsString(), Action.ADMIN);
// Table users
User tableRead = User.createUserForTesting(conf, "tableRead", new String[0]);
@@ -268,13 +267,13 @@ public class TestAccessController2 extends SecureTestUtil {
User tableCreate = User.createUserForTesting(conf, "tableCreate", new String[0]);
User tableAdmin = User.createUserForTesting(conf, "tableAdmin", new String[0]);
SecureTestUtil.grantOnTable(TEST_UTIL, tableRead.getShortName(),
- TEST_TABLE.getTableName(), null, null, Action.READ);
+ testTable.getTableName(), null, null, Action.READ);
SecureTestUtil.grantOnTable(TEST_UTIL, tableWrite.getShortName(),
- TEST_TABLE.getTableName(), null, null, Action.WRITE);
+ testTable.getTableName(), null, null, Action.WRITE);
SecureTestUtil.grantOnTable(TEST_UTIL, tableCreate.getShortName(),
- TEST_TABLE.getTableName(), null, null, Action.CREATE);
+ testTable.getTableName(), null, null, Action.CREATE);
SecureTestUtil.grantOnTable(TEST_UTIL, tableAdmin.getShortName(),
- TEST_TABLE.getTableName(), null, null, Action.ADMIN);
+ testTable.getTableName(), null, null, Action.ADMIN);
grantGlobal(TEST_UTIL, TESTGROUP_1_NAME, Action.WRITE);
try {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLWithMultipleVersions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLWithMultipleVersions.java
index c9a37d0..5eef312 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLWithMultipleVersions.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLWithMultipleVersions.java
@@ -19,12 +19,10 @@ package org.apache.hadoop.hbase.security.access;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-
import java.io.IOException;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -33,7 +31,7 @@ import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
@@ -46,9 +44,9 @@ import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.access.Permission.Action;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.apache.hadoop.hbase.util.TestTableName;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@@ -71,7 +69,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
}
@Rule
- public TestTableName TEST_TABLE = new TestTableName();
+ public TableNameTestRule testTable = new TableNameTestRule();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");
@@ -134,7 +132,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Before
public void setUp() throws Exception {
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1);
hcd.setMaxVersions(4);
htd.setOwner(USER_OWNER);
@@ -145,7 +143,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
htd.addFamily(hcd);
// Create the test table (owner added to the _acl_ table)
TEST_UTIL.createTable(htd, new byte[][] { Bytes.toBytes("s") });
- TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE.getTableName());
+ TEST_UTIL.waitUntilAllRegionsAssigned(testTable.getTableName());
LOG.info("Sleeping a second because of HBASE-12581");
Threads.sleep(1000);
}
@@ -160,7 +158,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try(Connection conn = ConnectionFactory.createConnection(conf);
- Table t = conn.getTable(TEST_TABLE.getTableName())) {
+ Table t = conn.getTable(testTable.getTableName())) {
Put p;
// with ro ACL
p = new Put(TEST_ROW).add(TEST_FAMILY1, TEST_Q1, ZERO);
@@ -192,7 +190,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
Get get = new Get(TEST_ROW);
get.setMaxVersions(10);
try(Connection conn = ConnectionFactory.createConnection(conf);
- Table t = conn.getTable(TEST_TABLE.getTableName())) {
+ Table t = conn.getTable(testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -204,7 +202,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
Get get = new Get(TEST_ROW);
get.setMaxVersions(10);
try(Connection conn = ConnectionFactory.createConnection(conf);
- Table t = conn.getTable(TEST_TABLE.getTableName())) {
+ Table t = conn.getTable(testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -220,7 +218,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try(Connection conn = ConnectionFactory.createConnection(conf);
- Table t = conn.getTable(TEST_TABLE.getTableName())) {
+ Table t = conn.getTable(testTable.getTableName())) {
Put p;
p = new Put(TEST_ROW).add(TEST_FAMILY1, TEST_Q1, ZERO);
p.setACL(writePerms);
@@ -266,7 +264,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
// with rw ACL for "user1"
Put p = new Put(TEST_ROW1);
p.add(TEST_FAMILY1, TEST_Q1, ZERO);
@@ -291,7 +289,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
// with rw ACL for "user1", "user2" and "@group"
Put p = new Put(TEST_ROW1);
p.add(TEST_FAMILY1, TEST_Q1, ZERO);
@@ -319,7 +317,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(TEST_ROW1);
d.deleteColumns(TEST_FAMILY1, TEST_Q1);
d.deleteColumns(TEST_FAMILY1, TEST_Q2);
@@ -342,7 +340,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(TEST_ROW2);
d.deleteFamily(TEST_FAMILY1);
t.delete(d);
@@ -359,7 +357,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(row);
d.addColumns(TEST_FAMILY1, q1);
d.addColumns(TEST_FAMILY1, q2);
@@ -383,7 +381,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
// Store a read write ACL without a timestamp, server will use current time
Put p = new Put(TEST_ROW).add(TEST_FAMILY1, TEST_Q2, ONE);
Map<String, Permission> readAndWritePerms =
@@ -413,7 +411,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1);
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -425,7 +423,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2);
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -459,7 +457,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public Object run() throws Exception {
Delete delete = new Delete(TEST_ROW).addFamily(fam);
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
t.delete(delete);
}
}
@@ -475,7 +473,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
// This version (TS = 123) with rw ACL for USER_OTHER and USER_OTHER2
Put p = new Put(TEST_ROW);
p.add(TEST_FAMILY1, TEST_Q1, 123L, ZERO);
@@ -514,7 +512,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(TEST_ROW, 124L);
d.deleteColumns(TEST_FAMILY1, TEST_Q1);
t.delete(d);
@@ -529,7 +527,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(TEST_ROW);
d.deleteColumns(TEST_FAMILY1, TEST_Q2, 124L);
t.delete(d);
@@ -554,7 +552,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Map<String, Permission> permsU1andOwner =
prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@@ -608,7 +606,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(TEST_ROW1);
d.deleteColumn(TEST_FAMILY1, TEST_Q1, 123);
d.deleteColumn(TEST_FAMILY1, TEST_Q2);
@@ -630,7 +628,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(row, 127);
d.addColumns(TEST_FAMILY1, q1);
d.addColumns(TEST_FAMILY1, q2);
@@ -660,7 +658,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Map<String, Permission> permsU1andOwner =
prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@@ -697,7 +695,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Increment inc = new Increment(TEST_ROW1);
inc.setTimeRange(0, 123);
inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L);
@@ -719,7 +717,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Increment inc = new Increment(row);
inc.setTimeRange(0, 127);
inc.addColumn(TEST_FAMILY1, q1, 2L);
@@ -748,7 +746,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Map<String, Permission> permsU1andOwner =
prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@@ -759,8 +757,8 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
USER_OWNER.getShortName() }, Action.READ, Action.WRITE);
permsU2andGUandOwner.put(user2.getShortName(), new Permission(Permission.Action.READ,
Permission.Action.WRITE));
- permsU2andGUandOwner.put(USER_OWNER.getShortName(), new Permission(Permission.Action.READ,
- Permission.Action.WRITE));
+ permsU2andGUandOwner.put(USER_OWNER.getShortName(),
+ new Permission(Permission.Action.READ, Permission.Action.WRITE));
Put p = new Put(TEST_ROW1);
p.add(TEST_FAMILY1, TEST_Q1, 123, ZERO);
p.setACL(permsU1andOwner);
@@ -791,7 +789,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Put p = new Put(TEST_ROW1);
p.add(TEST_FAMILY1, TEST_Q1, 125, ZERO);
p.add(TEST_FAMILY1, TEST_Q2, ZERO);
@@ -815,7 +813,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Put p = new Put(row);
// column Q1 covers version at 123 fr which user2 do not have permission
p.addColumn(TEST_FAMILY1, q1, 124, value);
@@ -844,7 +842,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Map<String, Permission> permsU1andOwner =
prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@@ -897,7 +895,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(TEST_ROW1);
d.deleteColumns(TEST_FAMILY1, TEST_Q1, 120);
t.checkAndDelete(TEST_ROW1, TEST_FAMILY1, TEST_Q1, ZERO, d);
@@ -933,7 +931,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(row);
d.addColumn(TEST_FAMILY1, q1, 120);
t.checkAndDelete(row, TEST_FAMILY1, q1, value, d);
@@ -950,7 +948,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
- try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ try (Table t = connection.getTable(testTable.getTableName())) {
Delete d = new Delete(row);
d.addColumns(TEST_FAMILY1, TEST_Q1);
t.checkAndDelete(row, TEST_FAMILY1, TEST_Q1, value, d);
@@ -967,11 +965,11 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public void tearDown() throws Exception {
// Clean the _acl_ table
try {
- TEST_UTIL.deleteTable(TEST_TABLE.getTableName());
+ TEST_UTIL.deleteTable(testTable.getTableName());
} catch (TableNotFoundException ex) {
// Test deleted the table, no problem
- LOG.info("Test deleted table " + TEST_TABLE.getTableName());
+ LOG.info("Test deleted table " + testTable.getTableName());
}
- assertEquals(0, AccessControlLists.getTablePermissions(conf, TEST_TABLE.getTableName()).size());
+ assertEquals(0, AccessControlLists.getTablePermissions(conf, testTable.getTableName()).size());
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLs.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLs.java
index e078a37..516dd61 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLs.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLs.java
@@ -18,7 +18,6 @@
package org.apache.hadoop.hbase.security.access;
import static org.junit.Assert.assertEquals;
-
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -33,6 +32,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.HTable;
@@ -52,7 +52,6 @@ import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.access.Permission.Action;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.TestTableName;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@@ -77,7 +76,7 @@ public class TestCellACLs extends SecureTestUtil {
}
@Rule
- public TestTableName TEST_TABLE = new TestTableName();
+ public TableNameTestRule testTable = new TableNameTestRule();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] TEST_FAMILY = Bytes.toBytes("f1");
private static final byte[] TEST_ROW = Bytes.toBytes("cellpermtest");
@@ -140,13 +139,13 @@ public class TestCellACLs extends SecureTestUtil {
public void setUp() throws Exception {
// Create the test table (owner added to the _acl_ table)
Admin admin = TEST_UTIL.getHBaseAdmin();
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY);
hcd.setMaxVersions(4);
htd.setOwner(USER_OWNER);
htd.addFamily(hcd);
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") });
- TEST_UTIL.waitTableEnabled(TEST_TABLE.getTableName());
+ TEST_UTIL.waitTableEnabled(testTable.getTableName());
LOG.info("Sleeping a second because of HBASE-12581");
Threads.sleep(1000);
}
@@ -158,7 +157,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName());) {
+ testTable.getTableName());) {
Put p;
// with ro ACL
p = new Put(TEST_ROW).add(TEST_FAMILY, TEST_Q1, ZERO);
@@ -185,7 +184,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -196,7 +195,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -207,7 +206,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -218,7 +217,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q4);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
return t.get(get).listCells();
}
}
@@ -248,7 +247,7 @@ public class TestCellACLs extends SecureTestUtil {
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
scan.addFamily(TEST_FAMILY);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
ResultScanner scanner = t.getScanner(scan);
Result result = null;
do {
@@ -283,7 +282,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, 1L);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
t.increment(i);
}
return null;
@@ -295,7 +294,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
t.increment(i);
}
return null;
@@ -309,7 +308,7 @@ public class TestCellACLs extends SecureTestUtil {
// Tag this increment with an ACL that denies write permissions to USER_OTHER
i.setACL(USER_OTHER.getShortName(), new Permission(Action.READ));
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
t.increment(i);
}
return null;
@@ -321,7 +320,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3, 1L);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
t.increment(i);
}
return null;
@@ -346,7 +345,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Delete delete = new Delete(TEST_ROW).addFamily(TEST_FAMILY);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
t.delete(delete);
}
return null;
@@ -358,7 +357,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception {
Delete delete = new Delete(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1);
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
t.delete(delete);
}
return null;
@@ -377,10 +376,10 @@ public class TestCellACLs extends SecureTestUtil {
@Test (timeout=120000)
public void testCoveringCheck() throws Exception {
// Grant read access to USER_OTHER
- grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY,
+ grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), testTable.getTableName(), TEST_FAMILY,
null, Action.READ);
// Grant read access to GROUP
- grantOnTable(TEST_UTIL, AuthUtil.toGroupEntry(GROUP), TEST_TABLE.getTableName(), TEST_FAMILY,
+ grantOnTable(TEST_UTIL, AuthUtil.toGroupEntry(GROUP), testTable.getTableName(), TEST_FAMILY,
null, Action.READ);
// A write by USER_OTHER should be denied.
@@ -395,7 +394,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Table t = new HTable(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName())) {
+ testTable.getTableName())) {
Put p;
p = new Put(TEST_ROW).add(TEST_FAMILY, TEST_Q1, ZERO);
t.put(p);
@@ -420,7 +419,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf);
- Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ Table t = connection.getTable(testTable.getTableName())) {
Put p;
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, value);
t.put(p);
@@ -435,7 +434,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override
public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf);
- Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ Table t = connection.getTable(testTable.getTableName())) {
return t.get(new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1));
}
}
@@ -455,11 +454,11 @@ public class TestCellACLs extends SecureTestUtil {
public void tearDown() throws Exception {
// Clean the _acl_ table
try {
- TEST_UTIL.deleteTable(TEST_TABLE.getTableName());
+ TEST_UTIL.deleteTable(testTable.getTableName());
} catch (TableNotFoundException ex) {
// Test deleted the table, no problem
- LOG.info("Test deleted table " + TEST_TABLE.getTableName());
+ LOG.info("Test deleted table " + testTable.getTableName());
}
- assertEquals(0, AccessControlLists.getTablePermissions(conf, TEST_TABLE.getTableName()).size());
+ assertEquals(0, AccessControlLists.getTablePermissions(conf, testTable.getTableName()).size());
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestScanEarlyTermination.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestScanEarlyTermination.java
index 5b0160a..b30200c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestScanEarlyTermination.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestScanEarlyTermination.java
@@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hbase.security.access;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.UUID;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -29,7 +29,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.HTable;
@@ -41,8 +41,8 @@ import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.access.Permission.Action;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.TestTableName;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.After;
@@ -64,7 +64,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
}
@Rule
- public TestTableName TEST_TABLE = new TestTableName();
+ public TableNameTestRule testTable = new TableNameTestRule();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");
@@ -115,7 +115,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
@Before
public void setUp() throws Exception {
Admin admin = TEST_UTIL.getHBaseAdmin();
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
htd.setOwner(USER_OWNER);
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1);
hcd.setMaxVersions(10);
@@ -129,25 +129,25 @@ public class TestScanEarlyTermination extends SecureTestUtil {
htd.setConfiguration(AccessControlConstants.CF_ATTRIBUTE_EARLY_OUT, "true");
admin.createTable(htd);
- TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE.getTableName());
+ TEST_UTIL.waitUntilAllRegionsAssigned(testTable.getTableName());
}
@After
public void tearDown() throws Exception {
// Clean the _acl_ table
try {
- TEST_UTIL.deleteTable(TEST_TABLE.getTableName());
+ TEST_UTIL.deleteTable(testTable.getTableName());
} catch (TableNotFoundException ex) {
// Test deleted the table, no problem
- LOG.info("Test deleted table " + TEST_TABLE.getTableName());
+ LOG.info("Test deleted table " + testTable.getTableName());
}
- assertEquals(0, AccessControlLists.getTablePermissions(conf, TEST_TABLE.getTableName()).size());
+ assertEquals(0, AccessControlLists.getTablePermissions(conf, testTable.getTableName()).size());
}
@Test
public void testEarlyScanTermination() throws Exception {
// Grant USER_OTHER access to TEST_FAMILY1 only
- grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY1,
+ grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), testTable.getTableName(), TEST_FAMILY1,
null, Action.READ);
// Set up test data
@@ -156,7 +156,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
public Object run() throws Exception {
// force a new RS connection
conf.set("testkey", UUID.randomUUID().toString());
- Table t = new HTable(conf, TEST_TABLE.getTableName());
+ Table t = new HTable(conf, testTable.getTableName());
try {
Put put = new Put(TEST_ROW).add(TEST_FAMILY1, TEST_Q1, ZERO);
t.put(put);
@@ -181,7 +181,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
public Object run() throws Exception {
// force a new RS connection
conf.set("testkey", UUID.randomUUID().toString());
- Table t = new HTable(conf, TEST_TABLE.getTableName());
+ Table t = new HTable(conf, testTable.getTableName());
try {
Scan scan = new Scan().addFamily(TEST_FAMILY1);
Result result = t.getScanner(scan).next();
@@ -205,7 +205,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
public Object run() throws Exception {
// force a new RS connection
conf.set("testkey", UUID.randomUUID().toString());
- Table t = new HTable(conf, TEST_TABLE.getTableName());
+ Table t = new HTable(conf, testTable.getTableName());
try {
Scan scan = new Scan();
Result result = t.getScanner(scan).next();
@@ -227,7 +227,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
public Object run() throws Exception {
// force a new RS connection
conf.set("testkey", UUID.randomUUID().toString());
- Table t = new HTable(conf, TEST_TABLE.getTableName());
+ Table t = new HTable(conf, testTable.getTableName());
try {
Scan scan = new Scan().addFamily(TEST_FAMILY2);
Result result = t.getScanner(scan).next();
@@ -242,7 +242,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
}, USER_OTHER);
// Now grant USER_OTHER access to TEST_FAMILY2:TEST_Q2
- grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY2,
+ grantOnTable(TEST_UTIL, USER_OTHER.getShortName(), testTable.getTableName(), TEST_FAMILY2,
TEST_Q2, Action.READ);
// A scan of FAMILY1 and FAMILY2 will produce combined results. In FAMILY2
@@ -253,7 +253,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
public Object run() throws Exception {
// force a new RS connection
conf.set("testkey", UUID.randomUUID().toString());
- Table t = new HTable(conf, TEST_TABLE.getTableName());
+ Table t = new HTable(conf, testTable.getTableName());
try {
Scan scan = new Scan();
Result result = t.getScanner(scan).next();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
index e64c6c8..b3018e0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestWithDisabledAuthorization.java
@@ -17,24 +17,25 @@
*/
package org.apache.hadoop.hbase.security.access;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import com.google.common.collect.Lists;
import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Append;
@@ -69,7 +70,6 @@ import org.apache.hadoop.hbase.security.access.Permission.Action;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
-import org.apache.hadoop.hbase.util.TestTableName;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.After;
@@ -80,8 +80,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import com.google.common.collect.Lists;
-
@Category(LargeTests.class)
public class TestWithDisabledAuthorization extends SecureTestUtil {
private static final Log LOG = LogFactory.getLog(TestWithDisabledAuthorization.class);
@@ -108,7 +106,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
private static RegionServerCoprocessorEnvironment RSCP_ENV;
private RegionCoprocessorEnvironment RCP_ENV;
- @Rule public TestTableName TEST_TABLE = new TestTableName();
+ @Rule public TableNameTestRule testTable = new TableNameTestRule();
// default users
@@ -182,15 +180,15 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
public void setUp() throws Exception {
// Create the test table (owner added to the _acl_ table)
Admin admin = TEST_UTIL.getHBaseAdmin();
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY);
hcd.setMaxVersions(100);
htd.addFamily(hcd);
htd.setOwner(USER_OWNER);
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") });
- TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE.getTableName());
+ TEST_UTIL.waitUntilAllRegionsAssigned(testTable.getTableName());
- Region region = TEST_UTIL.getHBaseCluster().getRegions(TEST_TABLE.getTableName()).get(0);
+ Region region = TEST_UTIL.getHBaseCluster().getRegions(testTable.getTableName()).get(0);
RegionCoprocessorHost rcpHost = region.getCoprocessorHost();
RCP_ENV = rcpHost.createEnvironment(AccessController.class, ACCESS_CONTROLLER,
Coprocessor.PRIORITY_HIGHEST, 1, TEST_UTIL.getConfiguration());
@@ -204,44 +202,44 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
Permission.Action.WRITE);
grantOnTable(TEST_UTIL, USER_RW.getShortName(),
- TEST_TABLE.getTableName(), TEST_FAMILY, null,
+ testTable.getTableName(), TEST_FAMILY, null,
Permission.Action.READ,
Permission.Action.WRITE);
// USER_CREATE is USER_RW plus CREATE permissions
grantOnTable(TEST_UTIL, USER_CREATE.getShortName(),
- TEST_TABLE.getTableName(), null, null,
+ testTable.getTableName(), null, null,
Permission.Action.CREATE,
Permission.Action.READ,
Permission.Action.WRITE);
grantOnTable(TEST_UTIL, USER_RO.getShortName(),
- TEST_TABLE.getTableName(), TEST_FAMILY, null,
+ testTable.getTableName(), TEST_FAMILY, null,
Permission.Action.READ);
grantOnTable(TEST_UTIL, USER_QUAL.getShortName(),
- TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
+ testTable.getTableName(), TEST_FAMILY, TEST_Q1,
Permission.Action.READ,
Permission.Action.WRITE);
assertEquals(5, AccessControlLists.getTablePermissions(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName()).size());
+ testTable.getTableName()).size());
}
@After
public void tearDown() throws Exception {
// Clean the _acl_ table
try {
- deleteTable(TEST_UTIL, TEST_TABLE.getTableName());
+ deleteTable(TEST_UTIL, testTable.getTableName());
} catch (TableNotFoundException ex) {
// Test deleted the table, no problem
- LOG.info("Test deleted table " + TEST_TABLE.getTableName());
+ LOG.info("Test deleted table " + testTable.getTableName());
}
// Verify all table/namespace permissions are erased
assertEquals(0, AccessControlLists.getTablePermissions(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName()).size());
+ testTable.getTableName()).size());
assertEquals(0, AccessControlLists.getNamespacePermissions(TEST_UTIL.getConfiguration(),
- TEST_TABLE.getTableName().getNamespaceAsString()).size());
+ testTable.getTableName().getNamespaceAsString()).size());
}
@Test
@@ -286,7 +284,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableAdmin = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
Permission.Action.ADMIN);
return null;
}
@@ -298,7 +296,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableCreate = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
Permission.Action.CREATE);
return null;
}
@@ -310,7 +308,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableRead = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
Permission.Action.READ);
return null;
}
@@ -322,7 +320,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableReadWrite = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
Permission.Action.READ, Permission.Action.WRITE);
return null;
}
@@ -334,7 +332,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkColumnRead = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, null,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, null,
Permission.Action.READ);
return null;
}
@@ -347,7 +345,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkColumnReadWrite = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, null,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, null,
Permission.Action.READ, Permission.Action.WRITE);
return null;
}
@@ -360,7 +358,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkQualifierRead = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, TEST_Q1,
Permission.Action.READ);
return null;
}
@@ -373,7 +371,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkQualifierReadWrite = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, TEST_Q1,
Permission.Action.READ, Permission.Action.WRITE);
return null;
}
@@ -386,10 +384,10 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkMultiQualifierRead = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), new Permission[] {
- new TablePermission(TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), new Permission[] {
+ new TablePermission(testTable.getTableName(), TEST_FAMILY, TEST_Q1,
Permission.Action.READ),
- new TablePermission(TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q2,
+ new TablePermission(testTable.getTableName(), TEST_FAMILY, TEST_Q2,
Permission.Action.READ), });
return null;
}
@@ -402,10 +400,10 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkMultiQualifierReadWrite = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), new Permission[] {
- new TablePermission(TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), new Permission[] {
+ new TablePermission(testTable.getTableName(), TEST_FAMILY, TEST_Q1,
Permission.Action.READ, Permission.Action.WRITE),
- new TablePermission(TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q2,
+ new TablePermission(testTable.getTableName(), TEST_FAMILY, TEST_Q2,
Permission.Action.READ, Permission.Action.WRITE), });
return null;
}
@@ -430,7 +428,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableRead = new AccessTestAction() {
@Override
public Void run() throws Exception {
- checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), TEST_FAMILY, null,
+ checkTablePerms(TEST_UTIL, testTable.getTableName(), TEST_FAMILY, null,
Permission.Action.READ);
return null;
}
@@ -444,7 +442,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Void run() throws Exception {
try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
- Table t = conn.getTable(TEST_TABLE.getTableName())) {
+ Table t = conn.getTable(testTable.getTableName())) {
t.get(new Get(TEST_ROW).addFamily(TEST_FAMILY));
}
return null;
@@ -455,7 +453,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
// Grant read perms to the test user
- grantOnTable(TEST_UTIL, tblUser.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY,
+ grantOnTable(TEST_UTIL, tblUser.getShortName(), testTable.getTableName(), TEST_FAMILY,
null, Permission.Action.READ);
// Now both the permission check and actual op will succeed
@@ -465,7 +463,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
// Revoke read perms from the test user
- revokeFromTable(TEST_UTIL, tblUser.getShortName(), TEST_TABLE.getTableName(), TEST_FAMILY,
+ revokeFromTable(TEST_UTIL, tblUser.getShortName(), testTable.getTableName(), TEST_FAMILY,
null, Permission.Action.READ);
// Now the permission check will indicate revocation but the actual op will still succeed
@@ -482,7 +480,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
ACCESS_CONTROLLER.preCreateTable(ObserverContext.createAndPrepare(CP_ENV, null), htd,
null);
@@ -494,11 +492,11 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
htd.addFamily(new HColumnDescriptor(TEST_FAMILY2));
ACCESS_CONTROLLER.preModifyTable(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName(), htd);
+ testTable.getTableName(), htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -508,7 +506,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteTable(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName());
+ testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -518,7 +516,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preTruncateTable(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName());
+ testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -529,7 +527,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
public Object run() throws Exception {
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
ACCESS_CONTROLLER.preAddColumn(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName(), hcd);
+ testTable.getTableName(), hcd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -540,7 +538,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
public Object run() throws Exception {
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
ACCESS_CONTROLLER.preModifyColumn(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName(), hcd);
+ testTable.getTableName(), hcd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -550,7 +548,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteColumn(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName(), TEST_FAMILY2);
+ testTable.getTableName(), TEST_FAMILY2);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -560,7 +558,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preEnableTable(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName());
+ testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -570,7 +568,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDisableTable(ObserverContext.createAndPrepare(CP_ENV, null),
- TEST_TABLE.getTableName());
+ testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@@ -579,7 +577,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
- HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
+ HRegionInfo region = new HRegionInfo(testTable.getTableName());
ServerName srcServer = ServerName.valueOf("1.1.1.1", 1, 0);
ServerName destServer = ServerName.valueOf("2.2.2.2", 2, 0);
ACCESS_CONTROLLER.preMove(ObserverContext.createAndPrepare(CP_ENV, null), region,
@@ -592,7 +590,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
- HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
+ HRegionInfo region = new HRegionInfo(testTable.getTableName());
ACCESS_CONTROLLER.preAssign(ObserverContext.createAndPrepare(CP_ENV, null), region);
return null;
}
@@ -602,7 +600,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
- HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName());
+ HRegionInfo region = new HRegionInfo(testTable.getTableName());
ACCESS_CONTROLLER.preUnassign(ObserverContext.createAndPrepare(CP_ENV, null), region,
true);
return null;
@@ -635,7 +633,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
SnapshotDescription snapshot = SnapshotDescription.newBuilder()
.setName("foo")
.build();
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
ACCESS_CONTROLLER.preSnapshot(ObserverContext.createAndPrepare(CP_ENV, null),
snapshot, htd);
return null;
@@ -649,7 +647,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
SnapshotDescription snapshot = SnapshotDescription.newBuilder()
.setName("foo")
.build();
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContext.createAndPrepare(CP_ENV, null),
snapshot, htd);
return null;
@@ -663,7 +661,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
SnapshotDescription snapshot = SnapshotDescription.newBuilder()
.setName("foo")
.build();
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
ACCESS_CONTROLLER.preRestoreSnapshot(ObserverContext.createAndPrepare(CP_ENV, null),
snapshot, htd);
return null;
@@ -688,7 +686,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Object run() throws Exception {
List<TableName> tableNamesList = Lists.newArrayList();
- tableNamesList.add(TEST_TABLE.getTableName());
+ tableNamesList.add(testTable.getTableName());
List<HTableDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preGetTableDescriptors(ObserverContext.createAndPrepare(CP_ENV, null),
tableNamesList, descriptors, ".+");
@@ -761,7 +759,6 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
-
}
/** Test region server observer */
@@ -780,7 +777,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
- HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName());
+ HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
Region region_a = mock(Region.class);
when(region_a.getTableDesc()).thenReturn(htd);
Region region_b = mock(Region.class);
@@ -969,7 +966,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override
public Object run() throws Exception {
try(Connection connection = ConnectionFactory.createConnection(conf);
- Table t = connection.getTable(TEST_TABLE.getTableName())) {
+ Table t = connection.getTable(testTable.getTableName())) {
Put p;
// with ro ACL
p = new Put(TEST_ROW).add(TEST_FAMILY, TEST_Q1, ZERO);
@@ -1001,7 +998,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
scan.addFamily(TEST_FAMILY);
Connection connection = ConnectionFactory.createConnection(conf);
- Table t = connection.getTable(TEST_TABLE.getTableName());
+ Table t = connection.getTable(testTable.getTableName());
try {
ResultScanner scanner = t.getScanner(scan);
Result result = null;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java
index 8ebeb97..0e058a0 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotClientRetries.java
@@ -19,22 +19,20 @@
package org.apache.hadoop.hbase.snapshot;
import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.coprocessor.BaseMasterObserver;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.apache.hadoop.hbase.util.TestTableName;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -46,7 +44,7 @@ public class TestSnapshotClientRetries {
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Log LOG = LogFactory.getLog(TestSnapshotClientRetries.class);
- @Rule public TestTableName TEST_TABLE = new TestTableName();
+ @Rule public TableNameTestRule testTable = new TableNameTestRule();
@Before
public void setUp() throws Exception {
@@ -63,15 +61,15 @@ public class TestSnapshotClientRetries {
@Test(timeout = 60000, expected=SnapshotExistsException.class)
public void testSnapshotAlreadyExist() throws Exception {
final String snapshotName = "testSnapshotAlreadyExist";
- TEST_UTIL.createTable(TEST_TABLE.getTableName(), "f");
- TEST_UTIL.getHBaseAdmin().snapshot(snapshotName, TEST_TABLE.getTableName());
- snapshotAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName());
+ TEST_UTIL.createTable(testTable.getTableName(), "f");
+ TEST_UTIL.getHBaseAdmin().snapshot(snapshotName, testTable.getTableName());
+ snapshotAndAssertOneRetry(snapshotName, testTable.getTableName());
}
@Test(timeout = 60000, expected=SnapshotDoesNotExistException.class)
public void testCloneNonExistentSnapshot() throws Exception {
final String snapshotName = "testCloneNonExistentSnapshot";
- cloneAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName());
+ cloneAndAssertOneRetry(snapshotName, testTable.getTableName());
}
public static class MasterSyncObserver extends BaseMasterObserver {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java
index 755f0fe..47d3048 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestSnapshotWhenChoreCleaning.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.snapshot;
+import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
@@ -25,7 +26,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
-
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
@@ -42,17 +42,14 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hbase.util.FSVisitor;
import org.apache.hadoop.hbase.util.FSVisitor.StoreFileVisitor;
-import org.apache.hadoop.hbase.util.TestTableName;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Lists;
/**
* Test Case for HBASE-21387
@@ -70,9 +67,6 @@ public class TestSnapshotWhenChoreCleaning {
private static final byte[] VALUE = Bytes.toBytes("value");
private static Table TABLE;
- @Rule
- public TestTableName TEST_TABLE = new TestTableName();
-
@BeforeClass
public static void setUp() throws Exception {
// Set the hbase.snapshot.thread.pool.max to 1;