You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2015/03/27 05:54:47 UTC
[3/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/66af9410/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<Void>() {
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<Void>() {
public Void run() throws Exception {
- Connection connection = ConnectionFactory.createConnection(conf);
- Table table = connection.getTable(tableName);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Scan s = new Scan();
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(1);
@@ -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<Void>() {
public Void run() throws Exception {
- Connection connection = ConnectionFactory.createConnection(conf);
- Table table = connection.getTable(tableName);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
// Test 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<Void>() {
public Void run() throws Exception {
- Connection connection = ConnectionFactory.createConnection(conf);
- Table table = connection.getTable(tableName);
- try {
+ try (Connection connection = ConnectionFactory.createConnection(conf);
+ Table table = connection.getTable(tableName)) {
Scan 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/66af9410/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<Void> actiona = new PrivilegedExceptionAction<Void>() {
@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<Void> actiona = new PrivilegedExceptionAction<Void>() {
@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<Void>() {
@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<Void>() {
@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();
- }
}
}
}