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 93E301745C for ; Fri, 27 Mar 2015 04:54:50 +0000 (UTC) Received: (qmail 29651 invoked by uid 500); 27 Mar 2015 04:54:45 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 29603 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 29591 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 32952E0542; 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:45 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/6] hbase git commit: HBASE-13332 Fix the usage of doAs/runAs in Visibility Controller tests (Srikanth Srungarapu) Repository: hbase Updated Branches: refs/heads/branch-1 e8059b0dc -> 66af9410b refs/heads/branch-1.0 ea03b10b0 -> 8d35d729a refs/heads/master a78effcdc -> b6b1e3b86 http://git-wip-us.apache.org/repos/asf/hbase/blob/8d35d729/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 014bc1b..01e1f82 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 @@ -111,12 +111,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)); @@ -128,8 +129,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; } @@ -138,9 +137,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); @@ -166,10 +164,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; } @@ -197,9 +191,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); @@ -264,9 +257,6 @@ public class TestVisibilityLablesWithGroups { assertTrue(Bytes.equals(current2.getValue(), value3)); assertFalse(cellScanner2.advance()); - } finally { - table.close(); - connection.close(); } return null; } @@ -306,9 +296,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. @@ -328,9 +317,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/8d35d729/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 1d15be6..2b9b762 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 @@ -32,7 +32,8 @@ 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.Append; -import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Connection; +import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse; @@ -126,15 +127,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 = new HTable(conf, 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); @@ -142,8 +141,6 @@ public class TestVisibilityWithCheckAuths { Assert.fail("Testcase should fail with AccesDeniedException"); } catch (Throwable t) { assertTrue(t.getMessage().contains("AccessDeniedException")); - } finally { - table.close(); } return null; } @@ -170,23 +167,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 { - Table table = null; - try { - table = new HTable(conf, 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(); } return null; } @@ -195,14 +187,11 @@ public class TestVisibilityWithCheckAuths { actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - Table table = null; - try { - table = new HTable(conf, 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(); } return null; } @@ -211,9 +200,8 @@ public class TestVisibilityWithCheckAuths { actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { - Table table = null; - try { - table = new HTable(conf, 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)); @@ -221,17 +209,11 @@ public class TestVisibilityWithCheckAuths { Assert.fail("Testcase should fail with AccesDeniedException"); } catch (Throwable t) { assertTrue(t.getMessage().contains("AccessDeniedException")); - } finally { - table.close(); } return null; } }; USER.runAs(actiona); - } finally { - if (table != null) { - table.close(); - } } } }