You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2015/03/27 05:54:48 UTC
[4/6] hbase git commit: HBASE-13332 Fix the usage of doAs/runAs in
Visibility Controller tests (Srikanth Srungarapu)
HBASE-13332 Fix the usage of doAs/runAs in Visibility Controller tests (Srikanth Srungarapu)
Conflicts:
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestDefaultScanLabelGeneratorStack.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestEnforcingScanLabelGenerator.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabels.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithACL.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDeletes.java
hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityWithCheckAuths.java
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/66af9410
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/66af9410
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/66af9410
Branch: refs/heads/branch-1
Commit: 66af9410b1c0ff64b5ff618fd87858d79681108d
Parents: e8059b0
Author: Andrew Purtell <ap...@apache.org>
Authored: Thu Mar 26 21:54:28 2015 -0700
Committer: Andrew Purtell <ap...@apache.org>
Committed: Thu Mar 26 21:54:28 2015 -0700
----------------------------------------------------------------------
.../TestDefaultScanLabelGeneratorStack.java | 22 +-
.../TestEnforcingScanLabelGenerator.java | 20 +-
...sibilityLabelReplicationWithExpAsString.java | 32 +-
.../visibility/TestVisibilityLabels.java | 154 ++--------
.../TestVisibilityLabelsReplication.java | 36 +--
.../visibility/TestVisibilityLabelsWithACL.java | 39 +--
...ibilityLabelsWithDefaultVisLabelService.java | 11 +-
.../TestVisibilityLabelsWithDeletes.java | 306 +++++++++----------
.../TestVisibilityLabelsWithSLGStack.java | 8 +-
.../TestVisibilityLablesWithGroups.java | 36 +--
.../TestVisibilityWithCheckAuths.java | 40 +--
11 files changed, 242 insertions(+), 462 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestDefaultScanLabelGeneratorStack.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestDefaultScanLabelGeneratorStack.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestDefaultScanLabelGeneratorStack.java
index a8ccbc7..1b3bb14 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestDefaultScanLabelGeneratorStack.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestDefaultScanLabelGeneratorStack.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.security.visibility;
import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.security.PrivilegedExceptionAction;
@@ -34,7 +33,6 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
-import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
@@ -104,8 +102,8 @@ public class TestDefaultScanLabelGeneratorStack {
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
- Table table = TEST_UTIL.createTable(tableName, CF);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = TEST_UTIL.createTable(tableName, CF)) {
Put put = new Put(ROW_1);
put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value1);
put.setCellVisibility(new CellVisibility(SECRET));
@@ -118,8 +116,6 @@ public class TestDefaultScanLabelGeneratorStack {
put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value3);
table.put(put);
return null;
- } finally {
- table.close();
}
}
});
@@ -127,9 +123,8 @@ public class TestDefaultScanLabelGeneratorStack {
// Test that super user can see all the cells.
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
- Connection connection = ConnectionFactory.createConnection(conf);
- Table table = connection.getTable(tableName);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Scan s = new Scan();
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(1);
@@ -157,17 +152,14 @@ public class TestDefaultScanLabelGeneratorStack {
assertTrue(Bytes.equals(current.getValue(), value3));
return null;
- } finally {
- table.close();
- connection.close();
}
}
});
TESTUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
- Table table = new HTable(conf, tableName);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
// Test scan with no auth attribute
Scan s = new Scan();
ResultScanner scanner = table.getScanner(s);
@@ -234,8 +226,6 @@ public class TestDefaultScanLabelGeneratorStack {
assertFalse(cellScanner2.advance());
return null;
- } finally {
- table.close();
}
}
});
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestEnforcingScanLabelGenerator.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestEnforcingScanLabelGenerator.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestEnforcingScanLabelGenerator.java
index 2284f88..326fda7 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestEnforcingScanLabelGenerator.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestEnforcingScanLabelGenerator.java
@@ -100,8 +100,8 @@ public class TestEnforcingScanLabelGenerator {
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
- Table table = TEST_UTIL.createTable(tableName, CF);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = TEST_UTIL.createTable(tableName, CF)) {
Put put = new Put(ROW_1);
put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value);
put.setCellVisibility(new CellVisibility(SECRET));
@@ -114,8 +114,6 @@ public class TestEnforcingScanLabelGenerator {
put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value);
table.put(put);
return null;
- } finally {
- table.close();
}
}
});
@@ -123,9 +121,8 @@ public class TestEnforcingScanLabelGenerator {
// Test that super user can see all the cells.
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
- Connection connection = ConnectionFactory.createConnection(conf);
- Table table = connection.getTable(tableName);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
// Test that super user can see all the cells.
Get get = new Get(ROW_1);
Result result = table.get(get);
@@ -133,17 +130,14 @@ public class TestEnforcingScanLabelGenerator {
assertTrue("Missing authorization", result.containsColumn(CF, Q2));
assertTrue("Missing authorization", result.containsColumn(CF, Q3));
return null;
- } finally {
- table.close();
- connection.close();
}
}
});
TESTUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
- Table table = new HTable(conf, tableName);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
// Test that we enforce the defined set
Get get = new Get(ROW_1);
get.setAuthorizations(new Authorizations(new String[] { SECRET, CONFIDENTIAL }));
@@ -158,8 +152,6 @@ public class TestEnforcingScanLabelGenerator {
assertTrue("Missing authorization", result.containsColumn(CF, Q2));
assertTrue("Inappropriate filtering", result.containsColumn(CF, Q3));
return null;
- } finally {
- table.close();
}
}
});
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
index 9241c2c..dc4a340 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
@@ -36,18 +36,20 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Tag;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.replication.ReplicationAdmin;
import org.apache.hadoop.hbase.codec.KeyValueCodecWithTags;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.visibility.VisibilityController.VisibilityReplication;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.experimental.categories.Category;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
@@ -135,25 +137,15 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
// Wait for the labels table to become available
TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
TEST_UTIL1.startMiniCluster(1);
- HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
- HTableDescriptor table = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
+ HTableDescriptor table = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor desc = new HColumnDescriptor(fam);
desc.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
table.addFamily(desc);
- try {
+ try (HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin()) {
hBaseAdmin.createTable(table);
- } finally {
- if (hBaseAdmin != null) {
- hBaseAdmin.close();
- }
}
- HBaseAdmin hBaseAdmin1 = TEST_UTIL1.getHBaseAdmin();
- try {
+ try (HBaseAdmin hBaseAdmin1 = TEST_UTIL1.getHBaseAdmin()){
hBaseAdmin1.createTable(table);
- } finally {
- if (hBaseAdmin1 != null) {
- hBaseAdmin1.close();
- }
}
addLabels();
setAuths(conf);
@@ -170,11 +162,9 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
final boolean nullExpected, final String... auths) throws IOException,
InterruptedException {
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
- HTable table2 = null;
-
public Void run() throws Exception {
- try {
- table2 = new HTable(conf1, TABLE_NAME_BYTES);
+ try (Connection connection = ConnectionFactory.createConnection(conf1);
+ Table table2 = connection.getTable(TableName.valueOf(TABLE_NAME))) {
CellScanner cellScanner;
Cell current;
Get get = new Get(row);
@@ -200,10 +190,6 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
doAssert(row, visString);
assertTrue(foundNonVisTag);
return null;
- } finally {
- if (table2 != null) {
- table2.close();
- }
}
}
};
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabels.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabels.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabels.java
index 455d632..0e2540a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabels.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabels.java
@@ -42,8 +42,9 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Append;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
@@ -112,9 +113,8 @@ public abstract class TestVisibilityLabels {
@Test
public void testSimpleVisibilityLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL,
- PRIVATE + "|" + CONFIDENTIAL);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL,
+ PRIVATE + "|" + CONFIDENTIAL)) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE));
ResultScanner scanner = table.getScanner(s);
@@ -131,21 +131,16 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testSimpleVisibilityLabelsWithUniCodeCharacters() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName,
- SECRET + "|" + CellVisibility.quote(COPYRIGHT), "(" + CellVisibility.quote(COPYRIGHT) + "&"
- + CellVisibility.quote(ACCENT) + ")|" + CONFIDENTIAL,
- CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName,
+ SECRET + "|" + CellVisibility.quote(COPYRIGHT), "(" + CellVisibility.quote(COPYRIGHT)
+ + "&" + CellVisibility.quote(ACCENT) + ")|" + CONFIDENTIAL,
+ CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET)) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, COPYRIGHT, ACCENT,
UNICODE_VIS_TAG));
@@ -167,20 +162,15 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row3, 0, row3.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testAuthorizationsWithSpecialUnicodeCharacters() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName,
+ try (Table table = createTableAndWriteDataWithLabels(tableName,
CellVisibility.quote(UC1) + "|" + CellVisibility.quote(UC2), CellVisibility.quote(UC1),
- CellVisibility.quote(UNICODE_VIS_TAG));
- try {
+ CellVisibility.quote(UNICODE_VIS_TAG))) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(UC1, UC2, ACCENT,
UNICODE_VIS_TAG));
@@ -202,21 +192,16 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row3, 0, row3.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testVisibilityLabelsWithComplexLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
- + ")" + "&" + "!" + TOPSECRET, "(" + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "("
- + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "(" + PRIVATE + "&" + CONFIDENTIAL
- + "&" + SECRET + ")");
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|"
+ + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET, "(" + PRIVATE + "&" + CONFIDENTIAL + "&"
+ + SECRET + ")", "(" + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "(" + PRIVATE
+ + "&" + CONFIDENTIAL + "&" + SECRET + ")")) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(TOPSECRET, CONFIDENTIAL, PRIVATE, PUBLIC, SECRET));
ResultScanner scanner = table.getScanner(s);
@@ -237,28 +222,19 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row4, 0, row4.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testVisibilityLabelsThatDoesNotPassTheCriteria() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
- + ")", PRIVATE);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName,
+ "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE)){
Scan s = new Scan();
s.setAuthorizations(new Authorizations(PUBLIC));
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3);
assertTrue(next.length == 0);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -275,27 +251,21 @@ public abstract class TestVisibilityLabels {
@Test
public void testVisibilityLabelsInScanThatDoesNotMatchAnyDefinedLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
- + ")", PRIVATE);
- try {
+ try ( Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|"
+ + CONFIDENTIAL + ")", PRIVATE)){
Scan s = new Scan();
s.setAuthorizations(new Authorizations("SAMPLE"));
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3);
assertTrue(next.length == 0);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testVisibilityLabelsWithGet() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL + "&!"
- + PRIVATE, SECRET + "&" + CONFIDENTIAL + "&" + PRIVATE);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ + "&!" + PRIVATE, SECRET + "&" + CONFIDENTIAL + "&" + PRIVATE)) {
Get get = new Get(row1);
get.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
Result result = table.get(get);
@@ -303,10 +273,6 @@ public abstract class TestVisibilityLabels {
Cell cell = result.getColumnLatestCell(fam, qual);
assertTrue(Bytes.equals(value, 0, value.length, cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength()));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -376,26 +342,18 @@ public abstract class TestVisibilityLabels {
}
TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
t.join();
- Table table = null;
- try {
- table = new HTable(TEST_UTIL.getConfiguration(), tableName);
+ try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET));
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3);
assertTrue(next.length == 1);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test(timeout = 60 * 1000)
public void testVisibilityLabelsOnRSRestart() throws Exception {
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
- + ")", PRIVATE);
List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster()
.getRegionServerThreads();
for (RegionServerThread rsThread : regionServerThreads) {
@@ -404,16 +362,13 @@ public abstract class TestVisibilityLabels {
// Start one new RS
RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer();
waitForLabelsRegionAvailability(rs.getRegionServer());
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
+ + ")", PRIVATE);) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET));
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3);
assertTrue(next.length == 1);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -442,17 +397,12 @@ public abstract class TestVisibilityLabels {
@Test
public void testVisibilityLabelsInGetThatDoesNotMatchAnyDefinedLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
- + ")", PRIVATE);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
+ + ")", PRIVATE)) {
Get get = new Get(row1);
get.setAuthorizations(new Authorizations("SAMPLE"));
Result result = table.get(get);
assertTrue(result.isEmpty());
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -470,9 +420,7 @@ public abstract class TestVisibilityLabels {
}
};
SUPERUSER.runAs(action);
- Table ht = null;
- try {
- ht = new HTable(conf, LABELS_TABLE_NAME);
+ try (Table ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);) {
Scan scan = new Scan();
scan.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL));
ResultScanner scanner = ht.getScanner(scan);
@@ -485,10 +433,6 @@ public abstract class TestVisibilityLabels {
assertTrue(auths.contains(SECRET));
assertTrue(auths.contains(CONFIDENTIAL));
assertEquals(2, auths.size());
- } finally {
- if (ht != null) {
- ht.close();
- }
}
action = new PrivilegedExceptionAction<Void>() {
@@ -581,9 +525,8 @@ public abstract class TestVisibilityLabels {
"org.apache.hadoop.hbase.security.visibility.InvalidLabelException: "
+ "Label 'public' is not set for the user testUser"));
assertTrue(resultList.get(2).getException().getValue().isEmpty());
- Table ht = null;
- try {
- ht = new HTable(conf, LABELS_TABLE_NAME);
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table ht = connection.getTable(LABELS_TABLE_NAME)) {
ResultScanner scanner = ht.getScanner(new Scan());
Result result = null;
List<Result> results = new ArrayList<Result>();
@@ -593,10 +536,6 @@ public abstract class TestVisibilityLabels {
List<String> curAuths = extractAuths(user, results);
assertTrue(curAuths.contains(PRIVATE));
assertEquals(1, curAuths.size());
- } finally {
- if (ht != null) {
- ht.close();
- }
}
GetAuthsResponse authsResponse = null;
@@ -620,9 +559,7 @@ public abstract class TestVisibilityLabels {
@Test
public void testLabelsWithCheckAndPut() throws Throwable {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = TEST_UTIL.createTable(tableName, fam);
+ try (Table table = TEST_UTIL.createTable(tableName, fam)) {
byte[] row1 = Bytes.toBytes("row1");
Put put = new Put(row1);
put.add(fam, qual, HConstants.LATEST_TIMESTAMP, value);
@@ -642,19 +579,13 @@ public abstract class TestVisibilityLabels {
assertTrue(Bytes.equals(row2, result.getRow()));
result = scanner.next();
assertNull(result);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testLabelsWithIncrement() throws Throwable {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = TEST_UTIL.createTable(tableName, fam);
+ try (Table table = TEST_UTIL.createTable(tableName, fam)) {
byte[] row1 = Bytes.toBytes("row1");
byte[] val = Bytes.toBytes(1L);
Put put = new Put(row1);
@@ -674,19 +605,13 @@ public abstract class TestVisibilityLabels {
table.increment(increment);
result = table.get(get);
assertTrue(!result.isEmpty());
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testLabelsWithAppend() throws Throwable {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = TEST_UTIL.createTable(tableName, fam);
+ try (Table table = TEST_UTIL.createTable(tableName, fam);) {
byte[] row1 = Bytes.toBytes("row1");
byte[] val = Bytes.toBytes("a");
Put put = new Put(row1);
@@ -708,10 +633,6 @@ public abstract class TestVisibilityLabels {
table.append(append);
result = table.get(get);
assertTrue(!result.isEmpty());
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -772,9 +693,7 @@ public abstract class TestVisibilityLabels {
col.setMaxVersions(5);
desc.addFamily(col);
TEST_UTIL.getHBaseAdmin().createTable(desc);
- Table table = null;
- try {
- table = new HTable(TEST_UTIL.getConfiguration(), tableName);
+ try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
Put put = new Put(r1);
put.add(fam, qual, 3l, v1);
put.add(fam, qual2, 3l, v1);
@@ -847,10 +766,6 @@ public abstract class TestVisibilityLabels {
assertNotNull(cell);
assertTrue(Bytes.equals(v2, 0, v2.length, cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength()));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -862,8 +777,7 @@ public abstract class TestVisibilityLabels {
HColumnDescriptor col = new HColumnDescriptor(fam);
desc.addFamily(col);
TEST_UTIL.getHBaseAdmin().createTable(desc);
- Table table = new HTable(TEST_UTIL.getConfiguration(), tableName);
- try {
+ try (Table table = TEST_UTIL.getConnection().getTable(tableName)){
Put p1 = new Put(row1);
p1.add(fam, qual, value);
p1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
@@ -888,8 +802,6 @@ public abstract class TestVisibilityLabels {
result = table.get(get);
assertFalse(result.containsColumn(fam, qual));
assertTrue(result.containsColumn(fam, qual2));
- } finally {
- table.close();
}
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
index 98a0886..b3f3c1c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
@@ -46,10 +46,11 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.TagRewriteCell;
import org.apache.hadoop.hbase.TagType;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
@@ -217,13 +218,12 @@ public class TestVisibilityLabelsReplication {
@Test
public void testVisibilityReplication() throws Exception {
- TableName tableName = TableName.valueOf(TABLE_NAME);
- Table table = writeData(tableName, "(" + SECRET + "&" + PUBLIC + ")" + "|(" + CONFIDENTIAL
- + ")&(" + TOPSECRET + ")", "(" + PRIVATE + "|" + CONFIDENTIAL + ")&(" + PUBLIC + "|"
- + TOPSECRET + ")", "(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET,
- CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET);
int retry = 0;
- try {
+ try (Table table = writeData(TableName.valueOf(TABLE_NAME),
+ "(" + SECRET + "&" + PUBLIC + ")" + "|(" + CONFIDENTIAL
+ + ")&(" + TOPSECRET + ")", "(" + PRIVATE + "|" + CONFIDENTIAL + ")&(" + PUBLIC + "|"
+ + TOPSECRET + ")", "(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET,
+ CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET);) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, TOPSECRET,
UNICODE_VIS_TAG));
@@ -251,9 +251,7 @@ public class TestVisibilityLabelsReplication {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row4, 0, row4.length));
- HTable table2 = null;
- try {
- table2 = new HTable(TEST_UTIL1.getConfiguration(), TABLE_NAME_BYTES);
+ try (Table table2 = TEST_UTIL1.getConnection().getTable(TableName.valueOf(TABLE_NAME))) {
s = new Scan();
// Ensure both rows are replicated
scanner = table2.getScanner(s);
@@ -272,14 +270,6 @@ public class TestVisibilityLabelsReplication {
verifyGet(row3, expectedVisString[2], expected[2], false, PRIVATE, SECRET);
verifyGet(row3, "", expected[3], true, TOPSECRET, SECRET);
verifyGet(row4, expectedVisString[3], expected[4], false, UNICODE_VIS_TAG, SECRET);
- } finally {
- if (table2 != null) {
- table2.close();
- }
- }
- } finally {
- if (table != null) {
- table.close();
}
}
}
@@ -313,11 +303,9 @@ public class TestVisibilityLabelsReplication {
final boolean nullExpected, final String... auths) throws IOException,
InterruptedException {
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
- HTable table2 = null;
-
public Void run() throws Exception {
- try {
- table2 = new HTable(conf1, TABLE_NAME_BYTES);
+ try (Connection connection = ConnectionFactory.createConnection(conf1);
+ Table table2 = connection.getTable(TableName.valueOf(TABLE_NAME))) {
CellScanner cellScanner;
Cell current;
Get get = new Get(row);
@@ -351,10 +339,6 @@ public class TestVisibilityLabelsReplication {
doAssert(row, visString);
assertTrue(foundNonVisTag);
return null;
- } finally {
- if (table2 != null) {
- table2.close();
- }
}
}
};
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithACL.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithACL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithACL.java
index e3cf3b0..1d5add9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithACL.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithACL.java
@@ -32,8 +32,9 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
@@ -115,7 +116,7 @@ public class TestVisibilityLabelsWithACL {
String user = "user2";
VisibilityClient.setAuths(conf, auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER2.getShortName(), tableName,
null, null, Permission.Action.READ);
@@ -123,16 +124,14 @@ public class TestVisibilityLabelsWithACL {
public Void run() throws Exception {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
- Table t = new HTable(conf, table.getName());
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table t = connection.getTable(table.getName())) {
ResultScanner scanner = t.getScanner(s);
Result result = scanner.next();
assertTrue(!result.isEmpty());
assertTrue(Bytes.equals(Bytes.toBytes("row2"), result.getRow()));
result = scanner.next();
assertNull(result);
- } finally {
- t.close();
}
return null;
}
@@ -146,19 +145,17 @@ public class TestVisibilityLabelsWithACL {
String user = "admin";
VisibilityClient.setAuths(conf, auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
- Table t = new HTable(conf, table.getName());
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table t = connection.getTable(table.getName())) {
ResultScanner scanner = t.getScanner(s);
Result[] result = scanner.next(5);
assertTrue(result.length == 2);
- } finally {
- t.close();
}
return null;
}
@@ -172,18 +169,16 @@ public class TestVisibilityLabelsWithACL {
String user = "admin";
VisibilityClient.setAuths(conf, auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
Get g = new Get(row1);
g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
- Table t = new HTable(conf, table.getName());
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table t = connection.getTable(table.getName())) {
Result result = t.get(g);
assertTrue(!result.isEmpty());
- } finally {
- t.close();
}
return null;
}
@@ -198,7 +193,7 @@ public class TestVisibilityLabelsWithACL {
VisibilityClient.clearAuths(conf, auths, user); // Removing all auths if any.
VisibilityClient.setAuths(conf, auths, "user1");
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET);
+ final Table table = createTableAndWriteDataWithLabels(tableName, SECRET);
SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER1.getShortName(), tableName,
null, null, Permission.Action.READ);
SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER2.getShortName(), tableName,
@@ -207,12 +202,10 @@ public class TestVisibilityLabelsWithACL {
public Void run() throws Exception {
Get g = new Get(row1);
g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
- Table t = new HTable(conf, table.getName());
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table t = connection.getTable(table.getName())) {
Result result = t.get(g);
assertTrue(result.isEmpty());
- } finally {
- t.close();
}
return null;
}
@@ -308,9 +301,9 @@ public class TestVisibilityLabelsWithACL {
assertTrue(authsList.contains(PRIVATE));
}
- private static HTable createTableAndWriteDataWithLabels(TableName tableName, String... labelExps)
+ private static Table createTableAndWriteDataWithLabels(TableName tableName, String... labelExps)
throws Exception {
- HTable table = null;
+ Table table = null;
try {
table = TEST_UTIL.createTable(tableName, fam);
int i = 1;
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java
index 0ef34b1..3cca329 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java
@@ -33,7 +33,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.MediumTests;
-import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
@@ -148,10 +147,10 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili
// Scan the visibility label
Scan s = new Scan();
s.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL));
- Table ht = new HTable(conf, LABELS_TABLE_NAME);
+
int i = 0;
- try {
- ResultScanner scanner = ht.getScanner(s);
+ try (Table ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);
+ ResultScanner scanner = ht.getScanner(s)) {
while (true) {
Result next = scanner.next();
if (next == null) {
@@ -159,10 +158,6 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili
}
i++;
}
- } finally {
- if (ht != null) {
- ht.close();
- }
}
// One label is the "system" label.
Assert.assertEquals("The count should be 13", 13, i);
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDeletes.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDeletes.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDeletes.java
index 2c0f03b..0430525 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDeletes.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDeletes.java
@@ -38,6 +38,8 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
@@ -112,13 +114,14 @@ public class TestVisibilityLabelsWithDeletes {
public void testVisibilityLabelsWithDeleteColumns() throws Throwable {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + TOPSECRET,
- SECRET);
- try {
+
+ try (Table table = createTableAndWriteDataWithLabels(tableName,
+ SECRET + "&" + TOPSECRET, SECRET)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(TOPSECRET + "&" + SECRET));
d.addColumns(fam, qual);
@@ -143,10 +146,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -154,13 +153,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testVisibilityLabelsWithDeleteFamily() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- final Table table = createTableAndWriteDataWithLabels(tableName, SECRET, CONFIDENTIAL + "|"
- + TOPSECRET);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET,
+ CONFIDENTIAL + "|" + TOPSECRET);) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row2);
d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
d.addFamily(fam);
@@ -184,10 +183,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row1, 0, row1.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -196,13 +191,13 @@ public class TestVisibilityLabelsWithDeletes {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
long[] ts = new long[] { 123l, 125l };
- final Table table = createTableAndWriteDataWithLabels(tableName, ts, CONFIDENTIAL + "|"
- + TOPSECRET, SECRET);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, ts,
+ CONFIDENTIAL + "|" + TOPSECRET, SECRET)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
d.deleteFamilyVersion(fam, 123l);
@@ -226,10 +221,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -238,13 +229,13 @@ public class TestVisibilityLabelsWithDeletes {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
long[] ts = new long[] { 123l, 125l };
- final Table table = createTableAndWriteDataWithLabels(tableName, ts, CONFIDENTIAL + "|"
- + TOPSECRET, SECRET);
- try {
+ try (Table table = createTableAndWriteDataWithLabels(tableName, ts,
+ CONFIDENTIAL + "|" + TOPSECRET, SECRET);) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
d.addColumn(fam, qual, 123l);
@@ -268,10 +259,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -284,7 +271,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
SECRET + "&" + TOPSECRET+")"));
@@ -339,7 +327,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d1 = new Delete(row1);
d1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d1.addColumns(fam, qual);
@@ -388,7 +377,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumns(fam, qual);
@@ -440,7 +430,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d1 = new Delete(row1);
d1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d1.addFamily(fam);
@@ -499,7 +490,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addFamily(fam);
@@ -524,7 +516,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET));
d.addFamily(fam);
@@ -573,7 +566,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumns(fam, qual);
@@ -598,7 +592,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET));
d.addColumns(fam, qual);
@@ -646,7 +641,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET));
d.addColumns(fam, qual, 126l);
@@ -655,7 +651,8 @@ public class TestVisibilityLabelsWithDeletes {
throw new IOException(t);
}
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumn(fam, qual, 123l);
@@ -707,14 +704,16 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumn(fam, qual, 123l);
table.delete(d);
}
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET));
d.addColumn(fam, qual, 123l);
@@ -759,7 +758,8 @@ public class TestVisibilityLabelsWithDeletes {
+ SECRET + "&" + TOPSECRET + ")"));
d3.addFamily(fam);
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2, d3));
} catch (Throwable t) {
throw new IOException(t);
@@ -803,7 +803,8 @@ public class TestVisibilityLabelsWithDeletes {
Delete d2 = new Delete(row1);
d2.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d2.addColumns(fam, qual);
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2));
} catch (Throwable t) {
throw new IOException(t);
@@ -992,7 +993,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
SECRET + "&" + TOPSECRET+")"));
@@ -1056,7 +1058,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual);
@@ -1109,9 +1112,7 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteColumnWithLatestTimeStampWhenNoVersionMatches() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPuts(tableName);
+ try (Table table = doPuts(tableName)) {
TEST_UTIL.getHBaseAdmin().flush(tableName);
Put put = new Put(Bytes.toBytes("row1"));
put.add(fam, qual, 128l, value);
@@ -1120,7 +1121,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET ));
d.addColumn(fam, qual);
@@ -1190,10 +1192,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 129l);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
@@ -1201,14 +1199,13 @@ public class TestVisibilityLabelsWithDeletes {
throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPuts(tableName);
+ try (Table table = doPuts(tableName)) {
TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual);
@@ -1261,10 +1258,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1272,14 +1265,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilyLatestTimeStampWithMulipleVersions() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPuts(tableName);
+ try (Table table = doPuts(tableName)) {
TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addFamily(fam);
@@ -1315,10 +1307,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1326,9 +1314,7 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteColumnswithMultipleColumnsWithMultipleVersions() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPutsWithDiffCols(tableName);
+ try (Table table = doPutsWithDiffCols(tableName)) {
TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
@@ -1336,7 +1322,8 @@ public class TestVisibilityLabelsWithDeletes {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumns(fam, qual, 125l);
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
table.delete(d);
} catch (Throwable t) {
throw new IOException(t);
@@ -1378,10 +1365,6 @@ public class TestVisibilityLabelsWithDeletes {
assertEquals(current.getTimestamp(), 127l);
assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(),
current.getQualifierLength(), qual2, 0, qual2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1415,7 +1398,8 @@ public class TestVisibilityLabelsWithDeletes {
d2.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d2.addColumns(fam, qual1, 125l);
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2));
} catch (Throwable t) {
throw new IOException(t);
@@ -1462,7 +1446,8 @@ public class TestVisibilityLabelsWithDeletes {
d2.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d2.addColumns(fam, qual1, 126l);
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2));
} catch (Throwable t) {
throw new IOException(t);
@@ -1483,14 +1468,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilyWithoutCellVisibilityWithMulipleVersions() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPutsWithoutVisibility(tableName);
+ try (Table table = doPutsWithoutVisibility(tableName)) {
TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.addFamily(fam);
table.delete(d);
@@ -1515,10 +1499,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1527,13 +1507,12 @@ public class TestVisibilityLabelsWithDeletes {
throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPutsWithoutVisibility(tableName);
+ try (Table table = doPutsWithoutVisibility(tableName)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addFamily(fam);
@@ -1583,10 +1562,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1594,14 +1569,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilySpecificTimeStampWithMulipleVersions() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPuts(tableName);
+ try (Table table = doPuts(tableName)) {
TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ SECRET + "&" + TOPSECRET + ")"));
@@ -1643,10 +1617,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1654,14 +1624,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testScanAfterCompaction() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = doPuts(tableName);
+ try (Table table = doPuts(tableName)) {
TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
SECRET + "&" + TOPSECRET+")"));
@@ -1701,10 +1670,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1712,14 +1677,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilySpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- // Do not flush here.
- table = doPuts(tableName);
+ // Do not flush here.
+ try (Table table = doPuts(tableName)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -1770,7 +1734,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -1806,10 +1771,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -1833,7 +1794,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.deleteFamilyVersion(fam, 123l);
@@ -1884,7 +1846,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET + ")"));
@@ -1929,7 +1892,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addFamily(fam);
@@ -1981,7 +1945,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET + ")"));
@@ -2027,7 +1992,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addFamily(fam);
@@ -2067,7 +2033,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual, 125l);
@@ -2117,7 +2084,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -2165,14 +2133,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice1() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- // Do not flush here.
- table = doPuts(tableName);
+ // Do not flush here.
+ try (Table table = doPuts(tableName)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")" +
"|(" + TOPSECRET + "&" + SECRET + ")"));
@@ -2223,7 +2190,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual, 127l);
@@ -2268,24 +2236,20 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice2() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- // Do not flush here.
- table = doPuts(tableName);
+
+ // Do not flush here.
+ try (Table table = doPuts(tableName)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -2341,7 +2305,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -2387,10 +2352,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@Test
@@ -2398,14 +2359,13 @@ public class TestVisibilityLabelsWithDeletes {
throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- // Do not flush here.
- table = doPuts(tableName);
+ // Do not flush here.
+ try (Table table = doPuts(tableName)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual, 125l);
@@ -2455,7 +2415,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -2491,10 +2452,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l);
- } finally {
- if (table != null) {
- table.close();
- }
}
}
@@ -2523,7 +2480,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -2574,7 +2532,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")"));
@@ -2626,7 +2585,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.addColumn(fam, qual, 125l);
table.delete(d);
@@ -2649,7 +2609,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.addColumns(fam, qual, 125l);
table.delete(d);
@@ -2673,7 +2634,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.addFamily(fam, 125l);
table.delete(d);
@@ -2697,7 +2659,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.addFamily(fam);
table.delete(d);
@@ -2721,7 +2684,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.addColumns(fam, qual);
table.delete(d);
@@ -2745,7 +2709,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.deleteFamilyVersion(fam, 126l);
table.delete(d);
@@ -2825,7 +2790,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
- try (Table table = new HTable(conf, tableName)) {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.addColumn(fam, qual, 124l);
d.setCellVisibility(new CellVisibility(PRIVATE ));
http://git-wip-us.apache.org/repos/asf/hbase/blob/66af9410/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithSLGStack.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithSLGStack.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithSLGStack.java
index f782896..acf324d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithSLGStack.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithSLGStack.java
@@ -81,9 +81,7 @@ public class TestVisibilityLabelsWithSLGStack {
@Test
public void testWithSAGStack() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
- Table table = null;
- try {
- table = TEST_UTIL.createTable(tableName, CF);
+ try (Table table = TEST_UTIL.createTable(tableName, CF)) {
Put put = new Put(ROW_1);
put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value);
put.setCellVisibility(new CellVisibility(SECRET));
@@ -100,10 +98,6 @@ public class TestVisibilityLabelsWithSLGStack {
Result next = scanner.next();
assertNotNull(next.getColumnLatestCell(CF, Q1));
assertNull(next.getColumnLatestCell(CF, Q2));
- } finally {
- if (table != null) {
- table.close();
- }
}
}