HBASE-23665: Split unit tests from TestTableName into a separate test-only class. (#1032)

Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
This commit is contained in:
Bharath Vissapragada 2020-01-15 09:16:28 -08:00 committed by Nick Dimiduk
parent cb78b103a7
commit fd05aabf02
10 changed files with 231 additions and 234 deletions

View File

@ -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;
}
}

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,99 +20,36 @@ package org.apache.hadoop.hbase;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail; import static org.junit.Assert.assertThrows;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
/** /**
* Returns a {@code byte[]} containing the name of the currently running test method. * Tests for various kinds of TableNames.
*/ */
@Category({MiscTests.class, MediumTests.class}) @Category({MiscTests.class, SmallTests.class})
public class TestTableName extends TestWatcher { public class TestTableName {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestTableName.class); HBaseClassTestRule.forClass(TestTableName.class);
private TableName tableName; private static String[] emptyNames = {"", " "};
private static String[] invalidNamespace = {":a", "%:a"};
/** private static String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok",
* Invoked when a test is about to start
*/
@Override
protected void starting(Description description) {
tableName = TableName.valueOf(description.getMethodName());
}
public TableName getTableName() {
return tableName;
}
String[] emptyNames = {"", " "};
String[] invalidNamespace = {":a", "%:a"};
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", "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", "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"}; "trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"};
String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal", "spaces not ok", private static String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal",
"-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash", "spaces not ok", "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
"new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"}; "new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"};
@Test(expected = IllegalArgumentException.class)
public void testInvalidNamespace() {
for (String tn : invalidNamespace) {
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
fail("invalid namespace " + tn
+ " should have failed with IllegalArgumentException for namespace");
}
}
@Test(expected = IllegalArgumentException.class)
public void testEmptyNamespaceName() {
for (String nn : emptyNames) {
TableName.isLegalNamespaceName(Bytes.toBytes(nn));
fail("invalid Namespace name " + nn + " should have failed with IllegalArgumentException");
}
}
@Test(expected = IllegalArgumentException.class)
public void testEmptyTableName() {
for (String tn : emptyNames) {
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
fail("invalid tablename " + tn + " should have failed with IllegalArgumentException");
}
}
@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));
fail("invalid tablename " + tn + " should have failed");
} catch (Exception e) {
// expected
}
}
}
static class Names { static class Names {
String ns; String ns;
byte[] nsb; byte[] nsb;
@ -147,7 +84,6 @@ public class TestTableName extends TestWatcher {
if (!tn.equals(names.tn)) { if (!tn.equals(names.tn)) {
return false; return false;
} }
return true; return true;
} }
@ -159,7 +95,7 @@ public class TestTableName extends TestWatcher {
} }
} }
Names[] names = new Names[] { private static Names[] names = new Names[] {
new Names("n1", "n1"), new Names("n1", "n1"),
new Names("n2", "n2"), new Names("n2", "n2"),
new Names("table1", "table1"), new Names("table1", "table1"),
@ -172,9 +108,41 @@ public class TestTableName extends TestWatcher {
new Names("n2", "table2") new Names("n2", "table2")
}; };
@Test @Test public void testInvalidNamespace() {
public void testValueOf() { for (String tn : invalidNamespace) {
assertThrows(IllegalArgumentException.class,
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
}
}
@Test public void testEmptyNamespaceName() {
for (String nn : emptyNames) {
assertThrows(IllegalArgumentException.class,
() -> TableName.isLegalNamespaceName(Bytes.toBytes(nn)));
}
}
@Test public void testEmptyTableName() {
for (String tn : emptyNames) {
assertThrows(IllegalArgumentException.class,
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
}
}
@Test public void testLegalHTableNames() {
for (String tn : legalTableNames) {
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
}
}
@Test public void testIllegalHTableNames() {
for (String tn : illegalTableNames) {
assertThrows(Exception.class,
() -> TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn)));
}
}
@Test public void testValueOf() {
Map<String, TableName> inCache = new HashMap<>(); Map<String, TableName> inCache = new HashMap<>();
// fill cache // fill cache
for (Names name : names) { for (Names name : names) {
@ -188,7 +156,6 @@ public class TestTableName extends TestWatcher {
assertSame(inCache.get(name.nn), validateNames(TableName.valueOf( assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(
ByteBuffer.wrap(name.nsb), ByteBuffer.wrap(name.tnb)), name)); ByteBuffer.wrap(name.nsb), ByteBuffer.wrap(name.tnb)), name));
} }
} }
private TableName validateNames(TableName expected, Names names) { private TableName validateNames(TableName expected, Names names) {
@ -200,5 +167,4 @@ public class TestTableName extends TestWatcher {
assertArrayEquals(expected.getNamespace(), names.nsb); assertArrayEquals(expected.getNamespace(), names.nsb);
return expected; return expected;
} }
} }

View File

@ -30,7 +30,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TestTableName; import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
@ -68,7 +68,7 @@ public class TestScannerRetriableFailure {
private static final String FAMILY_NAME_STR = "f"; private static final String FAMILY_NAME_STR = "f";
private static final byte[] FAMILY_NAME = Bytes.toBytes(FAMILY_NAME_STR); 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 implements RegionCoprocessor, RegionObserver { public static class FaultyScannerObserver implements RegionCoprocessor, RegionObserver {
private int faults = 0; private int faults = 0;
@ -116,7 +116,7 @@ public class TestScannerRetriableFailure {
@Test @Test
public void testFaultyScanner() throws Exception { public void testFaultyScanner() throws Exception {
TableName tableName = TEST_TABLE.getTableName(); TableName tableName = testTable.getTableName();
Table table = UTIL.createTable(tableName, FAMILY_NAME); Table table = UTIL.createTable(tableName, FAMILY_NAME);
try { try {
final int NUM_ROWS = 100; final int NUM_ROWS = 100;

View File

@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -34,8 +33,8 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.TestTableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
@ -105,7 +104,7 @@ public class TestAccessController2 extends SecureTestUtil {
private static User TESTGROUP2_USER1; private static User TESTGROUP2_USER1;
@Rule @Rule
public TestTableName TEST_TABLE = new TestTableName(); public TableNameTestRule testTable = new TableNameTestRule();
private String namespace = "testNamespace"; private String namespace = "testNamespace";
private String tname = namespace + ":testtable1"; private String tname = namespace + ":testtable1";
private TableName tableName = TableName.valueOf(tname); private TableName tableName = TableName.valueOf(tname);
@ -187,7 +186,7 @@ public class TestAccessController2 extends SecureTestUtil {
verifyAllowed(new AccessTestAction() { verifyAllowed(new AccessTestAction() {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
HTableDescriptor desc = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor desc = new HTableDescriptor(testTable.getTableName());
desc.addFamily(new HColumnDescriptor(TEST_FAMILY)); desc.addFamily(new HColumnDescriptor(TEST_FAMILY));
try (Connection connection = try (Connection connection =
ConnectionFactory.createConnection(TEST_UTIL.getConfiguration(), testUser)) { ConnectionFactory.createConnection(TEST_UTIL.getConfiguration(), testUser)) {
@ -198,11 +197,11 @@ public class TestAccessController2 extends SecureTestUtil {
return null; return null;
} }
}, testUser); }, 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 // Verify that owner permissions have been granted to the test user on the
// table just created // table just created
List<UserPermission> perms = PermissionStorage List<UserPermission> perms = PermissionStorage
.getTablePermissions(conf, TEST_TABLE.getTableName()).get(testUser.getShortName()); .getTablePermissions(conf, testTable.getTableName()).get(testUser.getShortName());
assertNotNull(perms); assertNotNull(perms);
assertFalse(perms.isEmpty()); assertFalse(perms.isEmpty());
// Should be RWXCA // Should be RWXCA
@ -220,7 +219,7 @@ public class TestAccessController2 extends SecureTestUtil {
AccessTestAction createAction = new AccessTestAction() { AccessTestAction createAction = new AccessTestAction() {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
HTableDescriptor desc = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor desc = new HTableDescriptor(testTable.getTableName());
desc.addFamily(new HColumnDescriptor(TEST_FAMILY)); desc.addFamily(new HColumnDescriptor(TEST_FAMILY));
try (Connection connection = try (Connection connection =
ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) { ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
@ -261,13 +260,13 @@ public class TestAccessController2 extends SecureTestUtil {
User nsCreate = User.createUserForTesting(conf, "nsCreate", new String[0]); User nsCreate = User.createUserForTesting(conf, "nsCreate", new String[0]);
User nsAdmin = User.createUserForTesting(conf, "nsAdmin", new String[0]); User nsAdmin = User.createUserForTesting(conf, "nsAdmin", new String[0]);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsRead.getShortName(), SecureTestUtil.grantOnNamespace(TEST_UTIL, nsRead.getShortName(),
TEST_TABLE.getTableName().getNamespaceAsString(), Action.READ); testTable.getTableName().getNamespaceAsString(), Action.READ);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsWrite.getShortName(), SecureTestUtil.grantOnNamespace(TEST_UTIL, nsWrite.getShortName(),
TEST_TABLE.getTableName().getNamespaceAsString(), Action.WRITE); testTable.getTableName().getNamespaceAsString(), Action.WRITE);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsCreate.getShortName(), SecureTestUtil.grantOnNamespace(TEST_UTIL, nsCreate.getShortName(),
TEST_TABLE.getTableName().getNamespaceAsString(), Action.CREATE); testTable.getTableName().getNamespaceAsString(), Action.CREATE);
SecureTestUtil.grantOnNamespace(TEST_UTIL, nsAdmin.getShortName(), SecureTestUtil.grantOnNamespace(TEST_UTIL, nsAdmin.getShortName(),
TEST_TABLE.getTableName().getNamespaceAsString(), Action.ADMIN); testTable.getTableName().getNamespaceAsString(), Action.ADMIN);
// Table users // Table users
User tableRead = User.createUserForTesting(conf, "tableRead", new String[0]); User tableRead = User.createUserForTesting(conf, "tableRead", new String[0]);
@ -275,13 +274,13 @@ public class TestAccessController2 extends SecureTestUtil {
User tableCreate = User.createUserForTesting(conf, "tableCreate", new String[0]); User tableCreate = User.createUserForTesting(conf, "tableCreate", new String[0]);
User tableAdmin = User.createUserForTesting(conf, "tableAdmin", new String[0]); User tableAdmin = User.createUserForTesting(conf, "tableAdmin", new String[0]);
SecureTestUtil.grantOnTable(TEST_UTIL, tableRead.getShortName(), 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(), 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(), 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(), 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); grantGlobal(TEST_UTIL, TESTGROUP_1_NAME, Action.WRITE);
try { try {

View File

@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.security.access;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.HashMap; import java.util.HashMap;
@ -31,8 +30,8 @@ import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.TestTableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
@ -71,7 +70,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
private static final Logger LOG = LoggerFactory.getLogger(TestCellACLWithMultipleVersions.class); private static final Logger LOG = LoggerFactory.getLogger(TestCellACLWithMultipleVersions.class);
@Rule @Rule
public TestTableName TEST_TABLE = new TestTableName(); public TableNameTestRule testTable = new TableNameTestRule();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1"); private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2"); private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");
@ -133,7 +132,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1);
hcd.setMaxVersions(4); hcd.setMaxVersions(4);
htd.setOwner(USER_OWNER); htd.setOwner(USER_OWNER);
@ -148,7 +147,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") }); 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"); LOG.info("Sleeping a second because of HBASE-12581");
Threads.sleep(1000); Threads.sleep(1000);
} }
@ -163,7 +162,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
Put p; Put p;
// with ro ACL // with ro ACL
p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO); p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
@ -195,7 +194,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
Get get = new Get(TEST_ROW); Get get = new Get(TEST_ROW);
get.readVersions(10); get.readVersions(10);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells(); return t.get(get).listCells();
} }
} }
@ -207,7 +206,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
Get get = new Get(TEST_ROW); Get get = new Get(TEST_ROW);
get.readVersions(10); get.readVersions(10);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells(); return t.get(get).listCells();
} }
} }
@ -223,7 +222,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
Put p; Put p;
p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO); p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
p.setACL(writePerms); p.setACL(writePerms);
@ -269,7 +268,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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" // with rw ACL for "user1"
Put p = new Put(TEST_ROW1); Put p = new Put(TEST_ROW1);
p.addColumn(TEST_FAMILY1, TEST_Q1, ZERO); p.addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
@ -294,7 +293,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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" // with rw ACL for "user1", "user2" and "@group"
Put p = new Put(TEST_ROW1); Put p = new Put(TEST_ROW1);
p.addColumn(TEST_FAMILY1, TEST_Q1, ZERO); p.addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
@ -322,7 +321,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(TEST_ROW1);
d.addColumns(TEST_FAMILY1, TEST_Q1); d.addColumns(TEST_FAMILY1, TEST_Q1);
d.addColumns(TEST_FAMILY1, TEST_Q2); d.addColumns(TEST_FAMILY1, TEST_Q2);
@ -345,7 +344,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(TEST_ROW2);
d.addFamily(TEST_FAMILY1); d.addFamily(TEST_FAMILY1);
t.delete(d); t.delete(d);
@ -362,7 +361,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(row);
d.addColumns(TEST_FAMILY1, q1); d.addColumns(TEST_FAMILY1, q1);
d.addColumns(TEST_FAMILY1, q2); d.addColumns(TEST_FAMILY1, q2);
@ -386,7 +385,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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 // Store a read write ACL without a timestamp, server will use current time
Put p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2, ONE); Put p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2, ONE);
Map<String, Permission> readAndWritePerms = Map<String, Permission> readAndWritePerms =
@ -416,7 +415,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1); Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1);
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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(); return t.get(get).listCells();
} }
} }
@ -428,7 +427,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2); Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2);
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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(); return t.get(get).listCells();
} }
} }
@ -462,7 +461,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Delete delete = new Delete(TEST_ROW).addFamily(fam); Delete delete = new Delete(TEST_ROW).addFamily(fam);
try (Connection connection = ConnectionFactory.createConnection(conf)) { try (Connection connection = ConnectionFactory.createConnection(conf)) {
try (Table t = connection.getTable(TEST_TABLE.getTableName())) { try (Table t = connection.getTable(testTable.getTableName())) {
t.delete(delete); t.delete(delete);
} }
} }
@ -478,7 +477,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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 // This version (TS = 123) with rw ACL for USER_OTHER and USER_OTHER2
Put p = new Put(TEST_ROW); Put p = new Put(TEST_ROW);
p.addColumn(TEST_FAMILY1, TEST_Q1, 123L, ZERO); p.addColumn(TEST_FAMILY1, TEST_Q1, 123L, ZERO);
@ -517,7 +516,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(TEST_ROW, 124L);
d.addColumns(TEST_FAMILY1, TEST_Q1); d.addColumns(TEST_FAMILY1, TEST_Q1);
t.delete(d); t.delete(d);
@ -532,7 +531,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(TEST_ROW);
d.addColumns(TEST_FAMILY1, TEST_Q2, 124L); d.addColumns(TEST_FAMILY1, TEST_Q2, 124L);
t.delete(d); t.delete(d);
@ -557,7 +556,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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 = Map<String, Permission> permsU1andOwner =
prepareCellPermissions( prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ, new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@ -611,7 +610,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(TEST_ROW1);
d.addColumn(TEST_FAMILY1, TEST_Q1, 123); d.addColumn(TEST_FAMILY1, TEST_Q1, 123);
d.addColumn(TEST_FAMILY1, TEST_Q2); d.addColumn(TEST_FAMILY1, TEST_Q2);
@ -633,7 +632,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(row, 127);
d.addColumns(TEST_FAMILY1, q1); d.addColumns(TEST_FAMILY1, q1);
d.addColumns(TEST_FAMILY1, q2); d.addColumns(TEST_FAMILY1, q2);
@ -663,7 +662,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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 = Map<String, Permission> permsU1andOwner =
prepareCellPermissions( prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ, new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@ -700,7 +699,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Increment inc = new Increment(TEST_ROW1);
inc.setTimeRange(0, 123); inc.setTimeRange(0, 123);
inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L); inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L);
@ -722,7 +721,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Increment inc = new Increment(row);
inc.setTimeRange(0, 127); inc.setTimeRange(0, 127);
inc.addColumn(TEST_FAMILY1, q1, 2L); inc.addColumn(TEST_FAMILY1, q1, 2L);
@ -751,7 +750,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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 = Map<String, Permission> permsU1andOwner =
prepareCellPermissions( prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ, new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@ -794,7 +793,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Put p = new Put(TEST_ROW1);
p.addColumn(TEST_FAMILY1, TEST_Q1, 125, ZERO); p.addColumn(TEST_FAMILY1, TEST_Q1, 125, ZERO);
p.addColumn(TEST_FAMILY1, TEST_Q2, ZERO); p.addColumn(TEST_FAMILY1, TEST_Q2, ZERO);
@ -818,7 +817,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Put p = new Put(row);
// column Q1 covers version at 123 fr which user2 do not have permission // column Q1 covers version at 123 fr which user2 do not have permission
p.addColumn(TEST_FAMILY1, q1, 124, value); p.addColumn(TEST_FAMILY1, q1, 124, value);
@ -847,7 +846,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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 = Map<String, Permission> permsU1andOwner =
prepareCellPermissions( prepareCellPermissions(
new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ, new String[] { user1.getShortName(), USER_OWNER.getShortName() }, Action.READ,
@ -900,7 +899,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(TEST_ROW1);
d.addColumns(TEST_FAMILY1, TEST_Q1, 120); d.addColumns(TEST_FAMILY1, TEST_Q1, 120);
t.checkAndMutate(TEST_ROW1, TEST_FAMILY1).qualifier(TEST_Q1) t.checkAndMutate(TEST_ROW1, TEST_FAMILY1).qualifier(TEST_Q1)
@ -937,7 +936,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(row);
d.addColumn(TEST_FAMILY1, q1, 120); d.addColumn(TEST_FAMILY1, q1, 120);
t.checkAndMutate(row, TEST_FAMILY1).qualifier(q1).ifEquals(value).thenDelete(d); t.checkAndMutate(row, TEST_FAMILY1).qualifier(q1).ifEquals(value).thenDelete(d);
@ -954,7 +953,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf)) { 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); Delete d = new Delete(row);
d.addColumns(TEST_FAMILY1, TEST_Q1); d.addColumns(TEST_FAMILY1, TEST_Q1);
t.checkAndMutate(row, TEST_FAMILY1).qualifier(TEST_Q1).ifEquals(value).thenDelete(d); t.checkAndMutate(row, TEST_FAMILY1).qualifier(TEST_Q1).ifEquals(value).thenDelete(d);
@ -971,11 +970,11 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
public void tearDown() throws Exception { public void tearDown() throws Exception {
// Clean the _acl_ table // Clean the _acl_ table
try { try {
TEST_UTIL.deleteTable(TEST_TABLE.getTableName()); TEST_UTIL.deleteTable(testTable.getTableName());
} catch (TableNotFoundException ex) { } catch (TableNotFoundException ex) {
// Test deleted the table, no problem // Test deleted the table, no problem
LOG.info("Test deleted table " + TEST_TABLE.getTableName()); LOG.info("Test deleted table " + testTable.getTableName());
} }
assertEquals(0, PermissionStorage.getTablePermissions(conf, TEST_TABLE.getTableName()).size()); assertEquals(0, PermissionStorage.getTablePermissions(conf, testTable.getTableName()).size());
} }
} }

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.hbase.security.access; package org.apache.hadoop.hbase.security.access;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -31,8 +30,8 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.TestTableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
@ -62,7 +61,6 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists; import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
@Category({SecurityTests.class, LargeTests.class}) @Category({SecurityTests.class, LargeTests.class})
@ -75,7 +73,7 @@ public class TestCellACLs extends SecureTestUtil {
private static final Logger LOG = LoggerFactory.getLogger(TestCellACLs.class); private static final Logger LOG = LoggerFactory.getLogger(TestCellACLs.class);
@Rule @Rule
public TestTableName TEST_TABLE = new TestTableName(); public TableNameTestRule testTable = new TableNameTestRule();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] TEST_FAMILY = Bytes.toBytes("f1"); private static final byte[] TEST_FAMILY = Bytes.toBytes("f1");
private static final byte[] TEST_ROW = Bytes.toBytes("cellpermtest"); private static final byte[] TEST_ROW = Bytes.toBytes("cellpermtest");
@ -137,13 +135,13 @@ public class TestCellACLs extends SecureTestUtil {
public void setUp() throws Exception { public void setUp() throws Exception {
// Create the test table (owner added to the _acl_ table) // Create the test table (owner added to the _acl_ table)
Admin admin = TEST_UTIL.getAdmin(); Admin admin = TEST_UTIL.getAdmin();
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY);
hcd.setMaxVersions(4); hcd.setMaxVersions(4);
htd.setOwner(USER_OWNER); htd.setOwner(USER_OWNER);
htd.addFamily(hcd); htd.addFamily(hcd);
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") }); 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"); LOG.info("Sleeping a second because of HBASE-12581");
Threads.sleep(1000); Threads.sleep(1000);
} }
@ -155,7 +153,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
Put p; Put p;
// with ro ACL // with ro ACL
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO); p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO);
@ -182,7 +180,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1); Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells(); return t.get(get).listCells();
} }
} }
@ -193,7 +191,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2); Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells(); return t.get(get).listCells();
} }
} }
@ -204,7 +202,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3); Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells(); return t.get(get).listCells();
} }
} }
@ -215,7 +213,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q4); Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q4);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
return t.get(get).listCells(); return t.get(get).listCells();
} }
} }
@ -245,7 +243,7 @@ public class TestCellACLs extends SecureTestUtil {
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } )); scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
scan.addFamily(TEST_FAMILY); scan.addFamily(TEST_FAMILY);
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName()); Table t = connection.getTable(testTable.getTableName());
try { try {
ResultScanner scanner = t.getScanner(scan); ResultScanner scanner = t.getScanner(scan);
Result result = null; Result result = null;
@ -284,7 +282,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, 1L); Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, 1L);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
t.increment(i); t.increment(i);
} }
return null; return null;
@ -296,7 +294,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L); Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q2, 1L);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
t.increment(i); t.increment(i);
} }
return null; return null;
@ -310,7 +308,7 @@ public class TestCellACLs extends SecureTestUtil {
// Tag this increment with an ACL that denies write permissions to USER_OTHER and GROUP // Tag this increment with an ACL that denies write permissions to USER_OTHER and GROUP
i.setACL(prepareCellPermissions(usersAndGroups, Action.READ)); i.setACL(prepareCellPermissions(usersAndGroups, Action.READ));
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
t.increment(i); t.increment(i);
} }
return null; return null;
@ -322,7 +320,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3, 1L); Increment i = new Increment(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q3, 1L);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
t.increment(i); t.increment(i);
} }
return null; return null;
@ -347,7 +345,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Delete delete = new Delete(TEST_ROW).addFamily(TEST_FAMILY); Delete delete = new Delete(TEST_ROW).addFamily(TEST_FAMILY);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
t.delete(delete); t.delete(delete);
} }
return null; return null;
@ -359,7 +357,7 @@ public class TestCellACLs extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
Delete delete = new Delete(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1); Delete delete = new Delete(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1);
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
t.delete(delete); t.delete(delete);
} }
return null; return null;
@ -378,10 +376,10 @@ public class TestCellACLs extends SecureTestUtil {
@Test @Test
public void testCoveringCheck() throws Exception { public void testCoveringCheck() throws Exception {
// Grant read access to USER_OTHER // 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); null, Action.READ);
// Grant read access to GROUP // 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); null, Action.READ);
// A write by USER_OTHER should be denied. // A write by USER_OTHER should be denied.
@ -396,7 +394,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
Put p; Put p;
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO); p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO);
t.put(p); t.put(p);
@ -421,7 +419,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
Put p; Put p;
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, value); p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, value);
t.put(p); t.put(p);
@ -436,7 +434,7 @@ public class TestCellACLs extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try (Connection connection = ConnectionFactory.createConnection(conf); 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)); return t.get(new Get(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1));
} }
} }
@ -455,11 +453,11 @@ public class TestCellACLs extends SecureTestUtil {
public void tearDown() throws Exception { public void tearDown() throws Exception {
// Clean the _acl_ table // Clean the _acl_ table
try { try {
TEST_UTIL.deleteTable(TEST_TABLE.getTableName()); TEST_UTIL.deleteTable(testTable.getTableName());
} catch (TableNotFoundException ex) { } catch (TableNotFoundException ex) {
// Test deleted the table, no problem // Test deleted the table, no problem
LOG.info("Test deleted table " + TEST_TABLE.getTableName()); LOG.info("Test deleted table " + testTable.getTableName());
} }
assertEquals(0, PermissionStorage.getTablePermissions(conf, TEST_TABLE.getTableName()).size()); assertEquals(0, PermissionStorage.getTablePermissions(conf, testTable.getTableName()).size());
} }
} }

View File

@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.security.access;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Coprocessor; import org.apache.hadoop.hbase.Coprocessor;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
@ -28,8 +27,8 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.TestTableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
@ -65,7 +64,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
private static final Logger LOG = LoggerFactory.getLogger(TestScanEarlyTermination.class); private static final Logger LOG = LoggerFactory.getLogger(TestScanEarlyTermination.class);
@Rule @Rule
public TestTableName TEST_TABLE = new TestTableName(); public TableNameTestRule testTable = new TableNameTestRule();
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1"); private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2"); private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");
@ -116,7 +115,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
Admin admin = TEST_UTIL.getAdmin(); Admin admin = TEST_UTIL.getAdmin();
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
htd.setOwner(USER_OWNER); htd.setOwner(USER_OWNER);
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY1);
hcd.setMaxVersions(10); hcd.setMaxVersions(10);
@ -130,25 +129,25 @@ public class TestScanEarlyTermination extends SecureTestUtil {
htd.setConfiguration(AccessControlConstants.CF_ATTRIBUTE_EARLY_OUT, "true"); htd.setConfiguration(AccessControlConstants.CF_ATTRIBUTE_EARLY_OUT, "true");
admin.createTable(htd); admin.createTable(htd);
TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE.getTableName()); TEST_UTIL.waitUntilAllRegionsAssigned(testTable.getTableName());
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
// Clean the _acl_ table // Clean the _acl_ table
try { try {
TEST_UTIL.deleteTable(TEST_TABLE.getTableName()); TEST_UTIL.deleteTable(testTable.getTableName());
} catch (TableNotFoundException ex) { } catch (TableNotFoundException ex) {
// Test deleted the table, no problem // Test deleted the table, no problem
LOG.info("Test deleted table " + TEST_TABLE.getTableName()); LOG.info("Test deleted table " + testTable.getTableName());
} }
assertEquals(0, PermissionStorage.getTablePermissions(conf, TEST_TABLE.getTableName()).size()); assertEquals(0, PermissionStorage.getTablePermissions(conf, testTable.getTableName()).size());
} }
@Test @Test
public void testEarlyScanTermination() throws Exception { public void testEarlyScanTermination() throws Exception {
// Grant USER_OTHER access to TEST_FAMILY1 only // 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); null, Action.READ);
// Set up test data // Set up test data
@ -158,7 +157,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
// force a new RS connection // force a new RS connection
conf.set("testkey", TEST_UTIL.getRandomUUID().toString()); conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName()); Table t = connection.getTable(testTable.getTableName());
try { try {
Put put = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO); Put put = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
t.put(put); t.put(put);
@ -185,7 +184,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
// force a new RS connection // force a new RS connection
conf.set("testkey", TEST_UTIL.getRandomUUID().toString()); conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName()); Table t = connection.getTable(testTable.getTableName());
try { try {
Scan scan = new Scan().addFamily(TEST_FAMILY1); Scan scan = new Scan().addFamily(TEST_FAMILY1);
Result result = t.getScanner(scan).next(); Result result = t.getScanner(scan).next();
@ -211,7 +210,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
// force a new RS connection // force a new RS connection
conf.set("testkey", TEST_UTIL.getRandomUUID().toString()); conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName()); Table t = connection.getTable(testTable.getTableName());
try { try {
Scan scan = new Scan(); Scan scan = new Scan();
Result result = t.getScanner(scan).next(); Result result = t.getScanner(scan).next();
@ -235,7 +234,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
// force a new RS connection // force a new RS connection
conf.set("testkey", TEST_UTIL.getRandomUUID().toString()); conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName()); Table t = connection.getTable(testTable.getTableName());
try { try {
Scan scan = new Scan().addFamily(TEST_FAMILY2); Scan scan = new Scan().addFamily(TEST_FAMILY2);
Result result = t.getScanner(scan).next(); Result result = t.getScanner(scan).next();
@ -251,7 +250,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
}, USER_OTHER); }, USER_OTHER);
// Now grant USER_OTHER access to TEST_FAMILY2:TEST_Q2 // 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); TEST_Q2, Action.READ);
// A scan of FAMILY1 and FAMILY2 will produce combined results. In FAMILY2 // A scan of FAMILY1 and FAMILY2 will produce combined results. In FAMILY2
@ -263,7 +262,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
// force a new RS connection // force a new RS connection
conf.set("testkey", TEST_UTIL.getRandomUUID().toString()); conf.set("testkey", TEST_UTIL.getRandomUUID().toString());
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName()); Table t = connection.getTable(testTable.getTableName());
try { try {
Scan scan = new Scan(); Scan scan = new Scan();
Result result = t.getScanner(scan).next(); Result result = t.getScanner(scan).next();

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.hbase.security.access; package org.apache.hadoop.hbase.security.access;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.util.List; import java.util.List;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
@ -33,8 +32,8 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.TestTableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
@ -78,7 +77,6 @@ import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists; import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
@Category({SecurityTests.class, LargeTests.class}) @Category({SecurityTests.class, LargeTests.class})
@ -105,7 +103,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
private static RegionServerCoprocessorEnvironment RSCP_ENV; private static RegionServerCoprocessorEnvironment RSCP_ENV;
private RegionCoprocessorEnvironment RCP_ENV; private RegionCoprocessorEnvironment RCP_ENV;
@Rule public TestTableName TEST_TABLE = new TestTableName(); @Rule public TableNameTestRule testTable = new TableNameTestRule();
// default users // default users
@ -177,15 +175,15 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
public void setUp() throws Exception { public void setUp() throws Exception {
// Create the test table (owner added to the _acl_ table) // Create the test table (owner added to the _acl_ table)
Admin admin = TEST_UTIL.getAdmin(); Admin admin = TEST_UTIL.getAdmin();
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY);
hcd.setMaxVersions(100); hcd.setMaxVersions(100);
htd.addFamily(hcd); htd.addFamily(hcd);
htd.setOwner(USER_OWNER); htd.setOwner(USER_OWNER);
admin.createTable(htd, new byte[][] { Bytes.toBytes("s") }); admin.createTable(htd, new byte[][] { Bytes.toBytes("s") });
TEST_UTIL.waitUntilAllRegionsAssigned(TEST_TABLE.getTableName()); TEST_UTIL.waitUntilAllRegionsAssigned(testTable.getTableName());
HRegion region = TEST_UTIL.getHBaseCluster().getRegions(TEST_TABLE.getTableName()).get(0); HRegion region = TEST_UTIL.getHBaseCluster().getRegions(testTable.getTableName()).get(0);
RegionCoprocessorHost rcpHost = region.getCoprocessorHost(); RegionCoprocessorHost rcpHost = region.getCoprocessorHost();
RCP_ENV = rcpHost.createEnvironment(ACCESS_CONTROLLER, RCP_ENV = rcpHost.createEnvironment(ACCESS_CONTROLLER,
Coprocessor.PRIORITY_HIGHEST, 1, TEST_UTIL.getConfiguration()); Coprocessor.PRIORITY_HIGHEST, 1, TEST_UTIL.getConfiguration());
@ -199,44 +197,44 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
Permission.Action.WRITE); Permission.Action.WRITE);
grantOnTable(TEST_UTIL, USER_RW.getShortName(), grantOnTable(TEST_UTIL, USER_RW.getShortName(),
TEST_TABLE.getTableName(), TEST_FAMILY, null, testTable.getTableName(), TEST_FAMILY, null,
Permission.Action.READ, Permission.Action.READ,
Permission.Action.WRITE); Permission.Action.WRITE);
// USER_CREATE is USER_RW plus CREATE permissions // USER_CREATE is USER_RW plus CREATE permissions
grantOnTable(TEST_UTIL, USER_CREATE.getShortName(), grantOnTable(TEST_UTIL, USER_CREATE.getShortName(),
TEST_TABLE.getTableName(), null, null, testTable.getTableName(), null, null,
Permission.Action.CREATE, Permission.Action.CREATE,
Permission.Action.READ, Permission.Action.READ,
Permission.Action.WRITE); Permission.Action.WRITE);
grantOnTable(TEST_UTIL, USER_RO.getShortName(), grantOnTable(TEST_UTIL, USER_RO.getShortName(),
TEST_TABLE.getTableName(), TEST_FAMILY, null, testTable.getTableName(), TEST_FAMILY, null,
Permission.Action.READ); Permission.Action.READ);
grantOnTable(TEST_UTIL, USER_QUAL.getShortName(), grantOnTable(TEST_UTIL, USER_QUAL.getShortName(),
TEST_TABLE.getTableName(), TEST_FAMILY, TEST_Q1, testTable.getTableName(), TEST_FAMILY, TEST_Q1,
Permission.Action.READ, Permission.Action.READ,
Permission.Action.WRITE); Permission.Action.WRITE);
assertEquals(5, PermissionStorage assertEquals(5, PermissionStorage
.getTablePermissions(TEST_UTIL.getConfiguration(), TEST_TABLE.getTableName()).size()); .getTablePermissions(TEST_UTIL.getConfiguration(), testTable.getTableName()).size());
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
// Clean the _acl_ table // Clean the _acl_ table
try { try {
deleteTable(TEST_UTIL, TEST_TABLE.getTableName()); deleteTable(TEST_UTIL, testTable.getTableName());
} catch (TableNotFoundException ex) { } catch (TableNotFoundException ex) {
// Test deleted the table, no problem // 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 // Verify all table/namespace permissions are erased
assertEquals(0, PermissionStorage assertEquals(0, PermissionStorage
.getTablePermissions(TEST_UTIL.getConfiguration(), TEST_TABLE.getTableName()).size()); .getTablePermissions(TEST_UTIL.getConfiguration(), testTable.getTableName()).size());
assertEquals(0, PermissionStorage.getNamespacePermissions(TEST_UTIL.getConfiguration(), assertEquals(0, PermissionStorage.getNamespacePermissions(TEST_UTIL.getConfiguration(),
TEST_TABLE.getTableName().getNamespaceAsString()).size()); testTable.getTableName().getNamespaceAsString()).size());
} }
@Test @Test
@ -278,7 +276,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableAdmin = new AccessTestAction() { AccessTestAction checkTableAdmin = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null, checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
Permission.Action.ADMIN); Permission.Action.ADMIN);
return null; return null;
} }
@ -290,7 +288,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableCreate = new AccessTestAction() { AccessTestAction checkTableCreate = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
checkTablePerms(TEST_UTIL, TEST_TABLE.getTableName(), null, null, checkTablePerms(TEST_UTIL, testTable.getTableName(), null, null,
Permission.Action.CREATE); Permission.Action.CREATE);
return null; return null;
} }
@ -302,7 +300,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableRead = new AccessTestAction() { AccessTestAction checkTableRead = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { 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.READ);
return null; return null;
} }
@ -314,7 +312,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableReadWrite = new AccessTestAction() { AccessTestAction checkTableReadWrite = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { 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); Permission.Action.READ, Permission.Action.WRITE);
return null; return null;
} }
@ -326,7 +324,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkColumnRead = new AccessTestAction() { AccessTestAction checkColumnRead = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { 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.READ);
return null; return null;
} }
@ -338,7 +336,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkColumnReadWrite = new AccessTestAction() { AccessTestAction checkColumnReadWrite = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { 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); Permission.Action.READ, Permission.Action.WRITE);
return null; return null;
} }
@ -350,7 +348,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkQualifierRead = new AccessTestAction() { AccessTestAction checkQualifierRead = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { 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.READ);
return null; return null;
} }
@ -362,7 +360,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkQualifierReadWrite = new AccessTestAction() { AccessTestAction checkQualifierReadWrite = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { 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); Permission.Action.READ, Permission.Action.WRITE);
return null; return null;
} }
@ -376,9 +374,9 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
public Void run() throws Exception { public Void run() throws Exception {
checkTablePerms(TEST_UTIL, checkTablePerms(TEST_UTIL,
new Permission[] { new Permission[] {
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY) Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
.withQualifier(TEST_Q1).withActions(Action.READ).build(), .withQualifier(TEST_Q1).withActions(Action.READ).build(),
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY) Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
.withQualifier(TEST_Q2).withActions(Action.READ).build() }); .withQualifier(TEST_Q2).withActions(Action.READ).build() });
return null; return null;
} }
@ -392,10 +390,10 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
public Void run() throws Exception { public Void run() throws Exception {
checkTablePerms(TEST_UTIL, checkTablePerms(TEST_UTIL,
new Permission[] { new Permission[] {
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY) Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
.withQualifier(TEST_Q1) .withQualifier(TEST_Q1)
.withActions(Permission.Action.READ, Permission.Action.WRITE).build(), .withActions(Permission.Action.READ, Permission.Action.WRITE).build(),
Permission.newBuilder(TEST_TABLE.getTableName()).withFamily(TEST_FAMILY) Permission.newBuilder(testTable.getTableName()).withFamily(TEST_FAMILY)
.withQualifier(TEST_Q2) .withQualifier(TEST_Q2)
.withActions(Permission.Action.READ, Permission.Action.WRITE).build() }); .withActions(Permission.Action.READ, Permission.Action.WRITE).build() });
return null; return null;
@ -420,7 +418,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
AccessTestAction checkTableRead = new AccessTestAction() { AccessTestAction checkTableRead = new AccessTestAction() {
@Override @Override
public Void run() throws Exception { 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.READ);
return null; return null;
} }
@ -434,7 +432,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()); 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)); t.get(new Get(TEST_ROW).addFamily(TEST_FAMILY));
} }
return null; return null;
@ -445,7 +443,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
// Grant read perms to the test user // 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); null, Permission.Action.READ);
// Now both the permission check and actual op will succeed // Now both the permission check and actual op will succeed
@ -455,7 +453,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
// Revoke read perms from the test user // 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); null, Permission.Action.READ);
// Now the permission check will indicate revocation but the actual op will still succeed // Now the permission check will indicate revocation but the actual op will still succeed
@ -472,7 +470,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() { verifyAllowed(new AccessTestAction() {
@Override @Override
public Object run() throws Exception { 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_FAMILY));
ACCESS_CONTROLLER.preCreateTable(ObserverContextImpl.createAndPrepare(CP_ENV), htd, ACCESS_CONTROLLER.preCreateTable(ObserverContextImpl.createAndPrepare(CP_ENV), htd,
null); null);
@ -484,11 +482,11 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() { verifyAllowed(new AccessTestAction() {
@Override @Override
public Object run() throws Exception { 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_FAMILY));
htd.addFamily(new HColumnDescriptor(TEST_FAMILY2)); htd.addFamily(new HColumnDescriptor(TEST_FAMILY2));
ACCESS_CONTROLLER.preModifyTable(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preModifyTable(ObserverContextImpl.createAndPrepare(CP_ENV),
TEST_TABLE.getTableName(), testTable.getTableName(),
null, // not needed by AccessController null, // not needed by AccessController
htd); htd);
return null; return null;
@ -500,7 +498,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteTable(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preDeleteTable(ObserverContextImpl.createAndPrepare(CP_ENV),
TEST_TABLE.getTableName()); testTable.getTableName());
return null; return null;
} }
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE); }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@ -510,7 +508,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
ACCESS_CONTROLLER.preTruncateTable(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preTruncateTable(ObserverContextImpl.createAndPrepare(CP_ENV),
TEST_TABLE.getTableName()); testTable.getTableName());
return null; return null;
} }
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE); }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@ -520,7 +518,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
ACCESS_CONTROLLER.preEnableTable(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preEnableTable(ObserverContextImpl.createAndPrepare(CP_ENV),
TEST_TABLE.getTableName()); testTable.getTableName());
return null; return null;
} }
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE); }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@ -530,7 +528,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
ACCESS_CONTROLLER.preDisableTable(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preDisableTable(ObserverContextImpl.createAndPrepare(CP_ENV),
TEST_TABLE.getTableName()); testTable.getTableName());
return null; return null;
} }
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE); }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@ -539,7 +537,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() { verifyAllowed(new AccessTestAction() {
@Override @Override
public Object run() throws Exception { 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 srcServer = ServerName.valueOf("1.1.1.1", 1, 0);
ServerName destServer = ServerName.valueOf("2.2.2.2", 2, 0); ServerName destServer = ServerName.valueOf("2.2.2.2", 2, 0);
ACCESS_CONTROLLER.preMove(ObserverContextImpl.createAndPrepare(CP_ENV), region, ACCESS_CONTROLLER.preMove(ObserverContextImpl.createAndPrepare(CP_ENV), region,
@ -552,7 +550,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() { verifyAllowed(new AccessTestAction() {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName()); HRegionInfo region = new HRegionInfo(testTable.getTableName());
ACCESS_CONTROLLER.preAssign(ObserverContextImpl.createAndPrepare(CP_ENV), region); ACCESS_CONTROLLER.preAssign(ObserverContextImpl.createAndPrepare(CP_ENV), region);
return null; return null;
} }
@ -562,7 +560,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
verifyAllowed(new AccessTestAction() { verifyAllowed(new AccessTestAction() {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
HRegionInfo region = new HRegionInfo(TEST_TABLE.getTableName()); HRegionInfo region = new HRegionInfo(testTable.getTableName());
ACCESS_CONTROLLER.preUnassign(ObserverContextImpl.createAndPrepare(CP_ENV), region, ACCESS_CONTROLLER.preUnassign(ObserverContextImpl.createAndPrepare(CP_ENV), region,
true); true);
return null; return null;
@ -593,7 +591,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo"); SnapshotDescription snapshot = new SnapshotDescription("foo");
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
ACCESS_CONTROLLER.preSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV),
snapshot, htd); snapshot, htd);
return null; return null;
@ -616,7 +614,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo"); SnapshotDescription snapshot = new SnapshotDescription("foo");
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preCloneSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV),
snapshot, htd); snapshot, htd);
return null; return null;
@ -628,7 +626,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo"); SnapshotDescription snapshot = new SnapshotDescription("foo");
HTableDescriptor htd = new HTableDescriptor(TEST_TABLE.getTableName()); HTableDescriptor htd = new HTableDescriptor(testTable.getTableName());
ACCESS_CONTROLLER.preRestoreSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preRestoreSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV),
snapshot, htd); snapshot, htd);
return null; return null;
@ -651,7 +649,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
List<TableName> tableNamesList = Lists.newArrayList(); List<TableName> tableNamesList = Lists.newArrayList();
tableNamesList.add(TEST_TABLE.getTableName()); tableNamesList.add(testTable.getTableName());
List<TableDescriptor> descriptors = Lists.newArrayList(); List<TableDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preGetTableDescriptors(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preGetTableDescriptors(ObserverContextImpl.createAndPrepare(CP_ENV),
tableNamesList, descriptors, ".+"); tableNamesList, descriptors, ".+");
@ -730,7 +728,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
public Object run() throws Exception { public Object run() throws Exception {
ACCESS_CONTROLLER.preSplitRegion( ACCESS_CONTROLLER.preSplitRegion(
ObserverContextImpl.createAndPrepare(CP_ENV), ObserverContextImpl.createAndPrepare(CP_ENV),
TEST_TABLE.getTableName(), testTable.getTableName(),
Bytes.toBytes("ss")); Bytes.toBytes("ss"));
return null; return null;
} }
@ -751,7 +749,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
ACCESS_CONTROLLER.preSetTableQuota(ObserverContextImpl.createAndPrepare(CP_ENV), ACCESS_CONTROLLER.preSetTableQuota(ObserverContextImpl.createAndPrepare(CP_ENV),
TEST_TABLE.getTableName(), null); testTable.getTableName(), null);
return null; return null;
} }
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE); }, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
@ -939,7 +937,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
try(Connection connection = ConnectionFactory.createConnection(conf); try(Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName())) { Table t = connection.getTable(testTable.getTableName())) {
Put p; Put p;
// with ro ACL // with ro ACL
p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO); p = new Put(TEST_ROW).addColumn(TEST_FAMILY, TEST_Q1, ZERO);
@ -971,7 +969,7 @@ public class TestWithDisabledAuthorization extends SecureTestUtil {
scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } )); scan.setStopRow(Bytes.add(TEST_ROW, new byte[]{ 0 } ));
scan.addFamily(TEST_FAMILY); scan.addFamily(TEST_FAMILY);
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(TEST_TABLE.getTableName()); Table t = connection.getTable(testTable.getTableName());
try { try {
ResultScanner scanner = t.getScanner(scan); ResultScanner scanner = t.getScanner(scan);
Result result = null; Result result = null;

View File

@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TestTableName; import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.client.SnapshotDescription; import org.apache.hadoop.hbase.client.SnapshotDescription;
import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
@ -53,7 +53,7 @@ public class TestSnapshotClientRetries {
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotClientRetries.class); private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotClientRetries.class);
@Rule public TestTableName TEST_TABLE = new TestTableName(); @Rule public TableNameTestRule testTable = new TableNameTestRule();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -70,15 +70,15 @@ public class TestSnapshotClientRetries {
@Test(expected=SnapshotExistsException.class) @Test(expected=SnapshotExistsException.class)
public void testSnapshotAlreadyExist() throws Exception { public void testSnapshotAlreadyExist() throws Exception {
final String snapshotName = "testSnapshotAlreadyExist"; final String snapshotName = "testSnapshotAlreadyExist";
TEST_UTIL.createTable(TEST_TABLE.getTableName(), "f"); TEST_UTIL.createTable(testTable.getTableName(), "f");
TEST_UTIL.getAdmin().snapshot(snapshotName, TEST_TABLE.getTableName()); TEST_UTIL.getAdmin().snapshot(snapshotName, testTable.getTableName());
snapshotAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName()); snapshotAndAssertOneRetry(snapshotName, testTable.getTableName());
} }
@Test(expected=SnapshotDoesNotExistException.class) @Test(expected=SnapshotDoesNotExistException.class)
public void testCloneNonExistentSnapshot() throws Exception { public void testCloneNonExistentSnapshot() throws Exception {
final String snapshotName = "testCloneNonExistentSnapshot"; final String snapshotName = "testCloneNonExistentSnapshot";
cloneAndAssertOneRetry(snapshotName, TEST_TABLE.getTableName()); cloneAndAssertOneRetry(snapshotName, testTable.getTableName());
} }
public static class MasterSyncObserver implements MasterCoprocessor, MasterObserver { public static class MasterSyncObserver implements MasterCoprocessor, MasterObserver {

View File

@ -31,7 +31,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TestTableName; import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.HMaster;
@ -75,7 +75,7 @@ public class TestSnapshotWhenChoreCleaning {
private static Table TABLE; private static Table TABLE;
@Rule @Rule
public TestTableName TEST_TABLE = new TestTableName(); public TableNameTestRule testTable = new TableNameTestRule();
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {