Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1238F17459 for ; Fri, 27 Mar 2015 04:54:46 +0000 (UTC) Received: (qmail 30390 invoked by uid 500); 27 Mar 2015 04:54:45 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 30246 invoked by uid 500); 27 Mar 2015 04:54:45 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 29860 invoked by uid 99); 27 Mar 2015 04:54:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2015 04:54:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3E04CE2F3B; Fri, 27 Mar 2015 04:54:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: apurtell@apache.org To: commits@hbase.apache.org Date: Fri, 27 Mar 2015 04:54:50 -0000 Message-Id: <297155f1f42841f39eadc280fa36f243@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [6/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) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b6b1e3b8 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b6b1e3b8 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b6b1e3b8 Branch: refs/heads/master Commit: b6b1e3b86e7dadb6036e97c17bed6ec11da047fc Parents: a78effc Author: Andrew Purtell Authored: Thu Mar 26 21:54:29 2015 -0700 Committer: Andrew Purtell Committed: Thu Mar 26 21:54:29 2015 -0700 ---------------------------------------------------------------------- .../TestDefaultScanLabelGeneratorStack.java | 27 +- .../TestEnforcingScanLabelGenerator.java | 22 +- ...sibilityLabelReplicationWithExpAsString.java | 30 +- .../visibility/TestVisibilityLabels.java | 156 ++-------- .../TestVisibilityLabelsReplication.java | 36 +-- .../visibility/TestVisibilityLabelsWithACL.java | 41 +-- ...ibilityLabelsWithDefaultVisLabelService.java | 11 +- .../TestVisibilityLabelsWithDeletes.java | 306 +++++++++---------- .../TestVisibilityLabelsWithSLGStack.java | 8 +- .../TestVisibilityLablesWithGroups.java | 36 +-- .../TestVisibilityWithCheckAuths.java | 49 +-- 11 files changed, 228 insertions(+), 494 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/b6b1e3b8/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 061db74..2cd5ff9 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; @@ -33,8 +32,6 @@ import org.apache.hadoop.hbase.HConstants; 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; @@ -106,9 +103,8 @@ public class TestDefaultScanLabelGeneratorStack { SUPERUSER.runAs(new PrivilegedExceptionAction() { public Void run() throws Exception { - Connection connection = ConnectionFactory.createConnection(conf); - 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)); @@ -121,9 +117,6 @@ public class TestDefaultScanLabelGeneratorStack { put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value3); table.put(put); return null; - } finally { - table.close(); - connection.close(); } } }); @@ -131,9 +124,8 @@ public class TestDefaultScanLabelGeneratorStack { // Test that super user can see all the cells. SUPERUSER.runAs(new PrivilegedExceptionAction() { 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); @@ -161,18 +153,14 @@ public class TestDefaultScanLabelGeneratorStack { assertTrue(Bytes.equals(current.getValue(), value3)); return null; - } finally { - table.close(); - connection.close(); } } }); TESTUSER.runAs(new PrivilegedExceptionAction() { 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 scan with no auth attribute Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); @@ -239,9 +227,6 @@ public class TestDefaultScanLabelGeneratorStack { assertFalse(cellScanner2.advance()); return null; - } finally { - table.close(); - connection.close(); } } }); http://git-wip-us.apache.org/repos/asf/hbase/blob/b6b1e3b8/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 df165bd..2fa8afd 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 @@ -101,8 +101,8 @@ public class TestEnforcingScanLabelGenerator { SUPERUSER.runAs(new PrivilegedExceptionAction() { 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)); @@ -115,8 +115,6 @@ public class TestEnforcingScanLabelGenerator { put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value); table.put(put); return null; - } finally { - table.close(); } } }); @@ -124,9 +122,8 @@ public class TestEnforcingScanLabelGenerator { // Test that super user can see all the cells. SUPERUSER.runAs(new PrivilegedExceptionAction() { 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); @@ -134,18 +131,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() { 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 we enforce the defined set Get get = new Get(ROW_1); get.setAuthorizations(new Authorizations(new String[] { SECRET, CONFIDENTIAL })); @@ -160,9 +153,6 @@ public class TestEnforcingScanLabelGenerator { assertTrue("Missing authorization", result.containsColumn(CF, Q2)); assertTrue("Inappropriate filtering", result.containsColumn(CF, Q3)); return null; - } finally { - table.close(); - connection.close(); } } }); http://git-wip-us.apache.org/repos/asf/hbase/blob/b6b1e3b8/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 01e22da..c1d4d01 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,13 +36,11 @@ 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.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; @@ -139,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(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); @@ -174,13 +162,10 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit final boolean nullExpected, final String... auths) throws IOException, InterruptedException { PrivilegedExceptionAction scanAction = new PrivilegedExceptionAction() { - Table table2 = null; public Void run() throws Exception { - Connection connection = null; - try { - connection = ConnectionFactory.createConnection(conf1); - table2 = connection.getTable(TABLE_NAME); + try (Connection connection = ConnectionFactory.createConnection(conf1); + Table table2 = connection.getTable(TABLE_NAME)) { CellScanner cellScanner; Cell current; Get get = new Get(row); @@ -206,13 +191,6 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit doAssert(row, visString); assertTrue(foundNonVisTag); return null; - } finally { - if (table2 != null) { - table2.close(); - } - if(connection != null){ - connection.close(); - } } } }; http://git-wip-us.apache.org/repos/asf/hbase/blob/b6b1e3b8/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 dcd5fbb..93c42ba 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 @@ -114,9 +114,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); @@ -133,21 +132,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)); @@ -169,20 +163,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)); @@ -204,21 +193,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); @@ -239,28 +223,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(); - } } } @@ -277,27 +252,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); @@ -305,10 +274,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(); - } } } @@ -378,26 +343,18 @@ public abstract class TestVisibilityLabels { } TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000); t.join(); - Table table = null; - try { - table = TEST_UTIL.getConnection().getTable(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 regionServerThreads = TEST_UTIL.getHBaseCluster() .getRegionServerThreads(); for (RegionServerThread rsThread : regionServerThreads) { @@ -406,16 +363,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(); - } } } @@ -444,17 +398,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(); - } } } @@ -472,9 +421,7 @@ public abstract class TestVisibilityLabels { } }; SUPERUSER.runAs(action); - Table ht = null; - try { - ht = TEST_UTIL.getConnection().getTable(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); @@ -487,10 +434,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() { @@ -583,11 +526,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()); - Connection connection = null; - Table ht = null; - try { - connection = ConnectionFactory.createConnection(conf); - ht = connection.getTable(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 results = new ArrayList(); @@ -597,13 +537,6 @@ public abstract class TestVisibilityLabels { List curAuths = extractAuths(user, results); assertTrue(curAuths.contains(PRIVATE)); assertEquals(1, curAuths.size()); - } finally { - if (ht != null) { - ht.close(); - } - if (connection != null){ - connection.close(); - } } GetAuthsResponse authsResponse = null; @@ -627,9 +560,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); @@ -649,19 +580,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); @@ -681,19 +606,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); @@ -715,10 +634,6 @@ public abstract class TestVisibilityLabels { table.append(append); result = table.get(get); assertTrue(!result.isEmpty()); - } finally { - if (table != null) { - table.close(); - } } } @@ -779,9 +694,7 @@ public abstract class TestVisibilityLabels { col.setMaxVersions(5); desc.addFamily(col); TEST_UTIL.getHBaseAdmin().createTable(desc); - Table table = null; - try { - table = TEST_UTIL.getConnection().getTable(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); @@ -854,10 +767,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(); - } } } @@ -869,8 +778,7 @@ public abstract class TestVisibilityLabels { HColumnDescriptor col = new HColumnDescriptor(fam); desc.addFamily(col); TEST_UTIL.getHBaseAdmin().createTable(desc); - Table table = TEST_UTIL.getConnection().getTable(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)); @@ -895,8 +803,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/b6b1e3b8/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 c087f4e..bc34ce3 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 @@ -219,12 +219,11 @@ public class TestVisibilityLabelsReplication { @Test public void testVisibilityReplication() throws Exception { - Table table = writeData(TABLE_NAME, "(" + 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(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)); @@ -252,9 +251,7 @@ public class TestVisibilityLabelsReplication { current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row4, 0, row4.length)); - Table table2 = null; - try { - table2 = TEST_UTIL1.getConnection().getTable(TABLE_NAME); + try (Table table2 = TEST_UTIL1.getConnection().getTable(TABLE_NAME);) { s = new Scan(); // Ensure both rows are replicated scanner = table2.getScanner(s); @@ -273,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(); } } } @@ -314,13 +303,9 @@ public class TestVisibilityLabelsReplication { final boolean nullExpected, final String... auths) throws IOException, InterruptedException { PrivilegedExceptionAction scanAction = new PrivilegedExceptionAction() { - Table table2 = null; - Connection connection = null; - public Void run() throws Exception { - try { - connection = ConnectionFactory.createConnection(conf1); - table2 = connection.getTable(TABLE_NAME); + try (Connection connection = ConnectionFactory.createConnection(conf1); + Table table2 = connection.getTable(TABLE_NAME)) { CellScanner cellScanner; Cell current; Get get = new Get(row); @@ -354,13 +339,6 @@ public class TestVisibilityLabelsReplication { doAssert(row, visString); assertTrue(foundNonVisTag); return null; - } finally { - if (table2 != null) { - table2.close(); - } - if(connection != null) { - connection.close(); - } } } }; http://git-wip-us.apache.org/repos/asf/hbase/blob/b6b1e3b8/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 7e7d8a3..3175fcc 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 @@ -34,7 +34,6 @@ 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; @@ -118,7 +117,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); @@ -126,18 +125,14 @@ public class TestVisibilityLabelsWithACL { public Void run() throws Exception { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); - Connection connection = ConnectionFactory.createConnection(conf); - Table t = connection.getTable(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(); - connection.close(); } return null; } @@ -151,19 +146,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 scanAction = new PrivilegedExceptionAction() { public Void run() throws Exception { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); - Table t = TEST_UTIL.getConnection().getTable(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; } @@ -177,18 +170,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 scanAction = new PrivilegedExceptionAction() { public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); - Table t = TEST_UTIL.getConnection().getTable(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; } @@ -203,7 +194,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, @@ -212,14 +203,10 @@ public class TestVisibilityLabelsWithACL { public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); - Connection connection = ConnectionFactory.createConnection(conf); - Table t = connection.getTable(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(); - connection.close(); } return null; } @@ -315,9 +302,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/b6b1e3b8/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 52f86c3..3297002 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 @@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.HConstants; -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; @@ -150,10 +149,10 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili // Scan the visibility label Scan s = new Scan(); s.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL)); - Table ht = TEST_UTIL.getConnection().getTable(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) { @@ -161,10 +160,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/b6b1e3b8/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 b2d0ae5..033299b 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 @@ -26,6 +26,8 @@ import org.apache.hadoop.hbase.HConstants; 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.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; @@ -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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 = TEST_UTIL.getConnection().getTable(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 = TEST_UTIL.getConnection().getTable(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 = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @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 = TEST_UTIL.getConnection().getTable(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 = TEST_UTIL.getConnection().getTable(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 = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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 actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - try (Table table = TEST_UTIL.getConnection().getTable(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/b6b1e3b8/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 371d25a..5abfecc 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 @@ -82,9 +82,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)); @@ -101,10 +99,6 @@ public class TestVisibilityLabelsWithSLGStack { Result next = scanner.next(); assertNotNull(next.getColumnLatestCell(CF, Q1)); assertNull(next.getColumnLatestCell(CF, Q2)); - } finally { - if (table != null) { - table.close(); - } } }