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 CC77B1744B for ; Fri, 27 Mar 2015 04:54:45 +0000 (UTC) Received: (qmail 30160 invoked by uid 500); 27 Mar 2015 04:54:45 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 29962 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 29851 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 3B987E2F3A; 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:49 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/6] hbase git commit: HBASE-13332 Fix the usage of doAs/runAs in Visibility Controller tests (Srikanth Srungarapu) http://git-wip-us.apache.org/repos/asf/hbase/blob/b6b1e3b8/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLablesWithGroups.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLablesWithGroups.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLablesWithGroups.java index 9e122c9..f0881fd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLablesWithGroups.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLablesWithGroups.java @@ -112,12 +112,13 @@ public class TestVisibilityLablesWithGroups { @Test public void testGroupAuths() throws Exception { final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - - // create the table and put data. + // create the table + TEST_UTIL.createTable(tableName, CF); + // put the data. 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 = connection.getTable(tableName)) { Put put = new Put(ROW_1); put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value1); put.setCellVisibility(new CellVisibility(SECRET)); @@ -129,8 +130,6 @@ public class TestVisibilityLablesWithGroups { put = new Put(ROW_1); put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value3); table.put(put); - } finally { - table.close(); } return null; } @@ -139,9 +138,8 @@ public class TestVisibilityLablesWithGroups { // 'admin' user is part of 'supergroup', thus 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); @@ -167,10 +165,6 @@ public class TestVisibilityLablesWithGroups { current.getRowLength(), ROW_1, 0, ROW_1.length)); assertTrue(Bytes.equals(current.getQualifier(), Q3)); assertTrue(Bytes.equals(current.getValue(), value3)); - - } finally { - table.close(); - connection.close(); } return null; } @@ -198,9 +192,8 @@ public class TestVisibilityLablesWithGroups { // Test that test user can see what 'testgroup' has been authorized to. 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); @@ -265,9 +258,6 @@ public class TestVisibilityLablesWithGroups { assertTrue(Bytes.equals(current2.getValue(), value3)); assertFalse(cellScanner2.advance()); - } finally { - table.close(); - connection.close(); } return null; } @@ -307,9 +297,8 @@ public class TestVisibilityLablesWithGroups { // Test that test user cannot see the cells with the labels anymore. 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)) { Scan s1 = new Scan(); // test user is not entitled to 'CONFIDENTIAL' anymore since we dropped // testgroup's label. test user has no auth labels now. @@ -329,9 +318,6 @@ public class TestVisibilityLablesWithGroups { assertTrue(Bytes.equals(current1.getValue(), value3)); assertFalse(cellScanner1.advance()); - } finally { - table.close(); - connection.close(); } return null; } http://git-wip-us.apache.org/repos/asf/hbase/blob/b6b1e3b8/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityWithCheckAuths.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityWithCheckAuths.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityWithCheckAuths.java index 457d2eb..67d9c63 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityWithCheckAuths.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityWithCheckAuths.java @@ -33,7 +33,6 @@ 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.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse; @@ -129,15 +128,13 @@ public class TestVisibilityWithCheckAuths { HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(colDesc); hBaseAdmin.createTable(desc); - Table table = null; try { TEST_UTIL.getHBaseAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - Table table = null; - try { - table = TEST_UTIL.getConnection().getTable(tableName); + try (Connection connection = ConnectionFactory.createConnection(conf); + Table table = connection.getTable(tableName)) { Put p = new Put(row1); p.setCellVisibility(new CellVisibility(PUBLIC + "&" + TOPSECRET)); p.add(fam, qual, 125l, value); @@ -145,8 +142,6 @@ public class TestVisibilityWithCheckAuths { Assert.fail("Testcase should fail with AccesDeniedException"); } catch (Throwable t) { assertTrue(t.getMessage().contains("AccessDeniedException")); - } finally { - table.close(); } return null; } @@ -173,25 +168,18 @@ public class TestVisibilityWithCheckAuths { }; SUPERUSER.runAs(action); final 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)) { final byte[] row1 = Bytes.toBytes("row1"); final byte[] val = Bytes.toBytes("a"); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - Connection connection = ConnectionFactory.createConnection(conf); - Table table = null; - try { - table = connection.getTable(tableName); + try (Connection connection = ConnectionFactory.createConnection(conf); + Table table = connection.getTable(tableName)) { Put put = new Put(row1); put.add(fam, qual, HConstants.LATEST_TIMESTAMP, val); put.setCellVisibility(new CellVisibility(TOPSECRET)); table.put(put); - } finally { - table.close(); - connection.close(); } return null; } @@ -200,16 +188,11 @@ public class TestVisibilityWithCheckAuths { actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - Connection connection = ConnectionFactory.createConnection(conf); - Table table = null; - try { - table = TEST_UTIL.getConnection().getTable(tableName); + try (Connection connection = ConnectionFactory.createConnection(conf); + Table table = connection.getTable(tableName)) { Append append = new Append(row1); append.add(fam, qual, Bytes.toBytes("b")); table.append(append); - } finally { - table.close(); - connection.close(); } return null; } @@ -218,11 +201,8 @@ public class TestVisibilityWithCheckAuths { actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - Table table = null; - Connection connection = null; - try { - connection = ConnectionFactory.createConnection(conf); - table = connection.getTable(tableName); + try (Connection connection = ConnectionFactory.createConnection(conf); + Table table = connection.getTable(tableName)) { Append append = new Append(row1); append.add(fam, qual, Bytes.toBytes("c")); append.setCellVisibility(new CellVisibility(PUBLIC)); @@ -230,22 +210,11 @@ public class TestVisibilityWithCheckAuths { Assert.fail("Testcase should fail with AccesDeniedException"); } catch (Throwable t) { assertTrue(t.getMessage().contains("AccessDeniedException")); - } finally { - if (table != null) { - table.close(); - } - if (connection != null) { - connection.close(); - } } return null; } }; USER.runAs(actiona); - } finally { - if (table != null) { - table.close(); - } } } }