From 2e1ec3d3d8dc4ef771463decb814e7c118523bf9 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Sun, 4 Feb 2018 08:38:46 +0800 Subject: [PATCH] HBASE-19914 Refactor TestVisibilityLabelsOnNewVersionBehaviorTable --- .../client/ColumnFamilyDescriptorBuilder.java | 5 + ...bilityLabelsOnNewVersionBehaviorTable.java | 25 +- ...ilityLabelsWithDefaultVisLabelService.java | 4 +- .../TestVisibilityLabelsWithDeletes.java | 1476 ++++++----------- .../VisibilityLabelsWithDeletesTestBase.java | 313 ++++ 5 files changed, 886 insertions(+), 937 deletions(-) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelsWithDeletesTestBase.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ColumnFamilyDescriptorBuilder.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ColumnFamilyDescriptorBuilder.java index aaa460bfb92..d7feea62d21 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ColumnFamilyDescriptorBuilder.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ColumnFamilyDescriptorBuilder.java @@ -552,6 +552,11 @@ public class ColumnFamilyDescriptorBuilder { return this; } + public ColumnFamilyDescriptorBuilder setNewVersionBehavior(final boolean value) { + desc.setNewVersionBehavior(value); + return this; + } + public ColumnFamilyDescriptorBuilder setValue(final Bytes key, final Bytes value) { desc.setValue(key, value); return this; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsOnNewVersionBehaviorTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsOnNewVersionBehaviorTable.java index d3177f92c37..4093ace36fa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsOnNewVersionBehaviorTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsOnNewVersionBehaviorTable.java @@ -18,30 +18,33 @@ package org.apache.hadoop.hbase.security.visibility; import java.io.IOException; - import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.SecurityTests; import org.junit.ClassRule; import org.junit.experimental.categories.Category; -@Category({SecurityTests.class, MediumTests.class}) -public class TestVisibilityLabelsOnNewVersionBehaviorTable extends TestVisibilityLabelsWithDeletes { + +@Category({ SecurityTests.class, MediumTests.class }) +public class TestVisibilityLabelsOnNewVersionBehaviorTable + extends VisibilityLabelsWithDeletesTestBase { + @ClassRule public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestVisibilityLabelsOnNewVersionBehaviorTable.class); @Override - protected Table createTable(HColumnDescriptor fam) throws IOException { - fam.setNewVersionBehavior(true); - TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - HTableDescriptor table = new HTableDescriptor(tableName); - table.addFamily(fam); - TEST_UTIL.getHBaseAdmin().createTable(table); + protected Table createTable(byte[] fam) throws IOException { + TableName tableName = TableName.valueOf(testName.getMethodName()); + TEST_UTIL.getAdmin() + .createTable(TableDescriptorBuilder.newBuilder(tableName) + .addColumnFamily( + ColumnFamilyDescriptorBuilder.newBuilder(fam).setNewVersionBehavior(true).build()) + .build()); return TEST_UTIL.getConnection().getTable(tableName); } } 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 632665fd184..0d7ff683144 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 @@ -114,7 +114,7 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili SUPERUSER.runAs(action); } - @Test(timeout = 60 * 1000) + @Test public void testAddVisibilityLabelsOnRSRestart() throws Exception { List regionServerThreads = TEST_UTIL.getHBaseCluster() .getRegionServerThreads(); @@ -227,7 +227,7 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili SUPERUSER.runAs(action); } - @Test(timeout = 60 * 1000) + @Test public void testVisibilityLabelsOnWALReplay() throws Exception { final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, 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 2e3d625c7f1..7a5232a7106 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 @@ -17,7 +17,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.assertEquals; import static org.junit.Assert.assertTrue; @@ -27,17 +26,13 @@ import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HBaseClassTestRule; -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.client.Admin; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Delete; @@ -48,251 +43,64 @@ import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse; -import org.apache.hadoop.hbase.security.User; -import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.SecurityTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * Tests visibility labels with deletes - */ -@Category({SecurityTests.class, MediumTests.class}) -public class TestVisibilityLabelsWithDeletes { +@Category({ SecurityTests.class, LargeTests.class }) +public class TestVisibilityLabelsWithDeletes extends VisibilityLabelsWithDeletesTestBase { @ClassRule public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestVisibilityLabelsWithDeletes.class); + HBaseClassTestRule.forClass(TestVisibilityLabelsWithDeletes.class); - private static final Logger LOG = LoggerFactory.getLogger(TestVisibilityLabelsWithDeletes.class); - private static final String TOPSECRET = "TOPSECRET"; - private static final String PUBLIC = "PUBLIC"; - private static final String PRIVATE = "PRIVATE"; - private static final String CONFIDENTIAL = "CONFIDENTIAL"; - private static final String SECRET = "SECRET"; - public static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - private static final byte[] row1 = Bytes.toBytes("row1"); - private static final byte[] row2 = Bytes.toBytes("row2"); - protected final static byte[] fam = Bytes.toBytes("info"); - protected final static byte[] qual = Bytes.toBytes("qual"); - private final static byte[] qual1 = Bytes.toBytes("qual1"); - private final static byte[] qual2 = Bytes.toBytes("qual2"); - protected final static byte[] value = Bytes.toBytes("value"); - private final static byte[] value1 = Bytes.toBytes("value1"); - public static Configuration conf; - - @Rule - public final TestName TEST_NAME = new TestName(); - public static User SUPERUSER; - - @BeforeClass - public static void setupBeforeClass() throws Exception { - // setup configuration - conf = TEST_UTIL.getConfiguration(); - VisibilityTestUtil.enableVisiblityLabels(conf); - conf.setClass(VisibilityUtils.VISIBILITY_LABEL_GENERATOR_CLASS, SimpleScanLabelGenerator.class, - ScanLabelGenerator.class); - conf.set("hbase.superuser", "admin"); - TEST_UTIL.startMiniCluster(2); - SUPERUSER = User.createUserForTesting(conf, "admin", new String[] { "supergroup" }); - - // Wait for the labels table to become available - TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000); - addLabels(); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - TEST_UTIL.shutdownMiniCluster(); - } - - @After - public void tearDown() throws Exception { - } - - protected Table createTable(HColumnDescriptor fam) throws IOException { - TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - HTableDescriptor table = new HTableDescriptor(tableName); - table.addFamily(fam); - TEST_UTIL.getHBaseAdmin().createTable(table); + @Override + protected Table createTable(byte[] fam) throws IOException { + TableName tableName = TableName.valueOf(testName.getMethodName()); + TEST_UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(tableName) + .addColumnFamily(ColumnFamilyDescriptorBuilder.of(fam)).build()); return TEST_UTIL.getConnection().getTable(tableName); } - @Test - public void testVisibilityLabelsWithDeleteColumns() throws Throwable { - setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - - try (Table table = createTableAndWriteDataWithLabels(SECRET + "&" + TOPSECRET, SECRET)) { - PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { - @Override - public Void run() throws Exception { - 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); - table.delete(d); - } catch (Throwable t) { - throw new IOException(t); - } - return null; - } - }; - SUPERUSER.runAs(actiona); - - TEST_UTIL.getAdmin().flush(tableName); - Scan s = new Scan(); - s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); - ResultScanner scanner = table.getScanner(s); - Result[] next = scanner.next(3); - assertTrue(next.length == 1); - CellScanner cellScanner = next[0].cellScanner(); - cellScanner.advance(); - Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); - - } + private TableName createTable() throws IOException { + return createTable(-1); } - @Test - public void testVisibilityLabelsWithDeleteFamily() throws Exception { - setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - try (Table table = createTableAndWriteDataWithLabels(SECRET, CONFIDENTIAL + "|" + TOPSECRET)) { - PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { - @Override - public Void run() throws Exception { - 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); - table.delete(d); - } catch (Throwable t) { - throw new IOException(t); - } - return null; - } - }; - SUPERUSER.runAs(actiona); - - TEST_UTIL.getAdmin().flush(tableName); - Scan s = new Scan(); - s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); - ResultScanner scanner = table.getScanner(s); - Result[] next = scanner.next(3); - assertTrue(next.length == 1); - CellScanner cellScanner = next[0].cellScanner(); - cellScanner.advance(); - Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); - } + private TableName createTable(int maxVersions) throws IOException { + TableName tableName = TableName.valueOf(testName.getMethodName()); + createTable(tableName, maxVersions); + return tableName; } - @Test - public void testVisibilityLabelsWithDeleteFamilyVersion() throws Exception { - setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - long[] ts = new long[] { 123L, 125L }; - try (Table table = createTableAndWriteDataWithLabels(ts, - CONFIDENTIAL + "|" + TOPSECRET, SECRET)) { - PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { - @Override - public Void run() throws Exception { - try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { - Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL)); - d.addFamilyVersion(fam, 123L); - table.delete(d); - } catch (Throwable t) { - throw new IOException(t); - } - return null; - } - }; - SUPERUSER.runAs(actiona); - - TEST_UTIL.getAdmin().flush(tableName); - Scan s = new Scan(); - s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); - ResultScanner scanner = table.getScanner(s); - Result[] next = scanner.next(3); - assertTrue(next.length == 1); - CellScanner cellScanner = next[0].cellScanner(); - cellScanner.advance(); - Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); - } - } - - @Test - public void testVisibilityLabelsWithDeleteColumnExactVersion() throws Exception { - setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - long[] ts = new long[] { 123L, 125L }; - try (Table table = createTableAndWriteDataWithLabels(ts, - CONFIDENTIAL + "|" + TOPSECRET, SECRET)) { - PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { - @Override - public Void run() throws Exception { - 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); - table.delete(d); - } catch (Throwable t) { - throw new IOException(t); - } - return null; - } - }; - SUPERUSER.runAs(actiona); - - TEST_UTIL.getAdmin().flush(tableName); - Scan s = new Scan(); - s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); - ResultScanner scanner = table.getScanner(s); - Result[] next = scanner.next(3); - assertTrue(next.length == 1); - CellScanner cellScanner = next[0].cellScanner(); - cellScanner.advance(); - Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + private void createTable(TableName tableName, int maxVersions) throws IOException { + ColumnFamilyDescriptorBuilder builder = ColumnFamilyDescriptorBuilder.newBuilder(fam); + if (maxVersions > 0) { + builder.setMaxVersions(maxVersions); } + TEST_UTIL.getAdmin().createTable( + TableDescriptorBuilder.newBuilder(tableName).addColumnFamily(builder.build()).build()); } @Test public void testVisibilityLabelsWithDeleteColumnsWithMultipleVersions() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + - SECRET + "&" + TOPSECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d.addColumns(fam, qual, 125L); table.delete(d); } catch (Throwable t) { @@ -305,7 +113,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -313,24 +121,24 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @@ -338,14 +146,14 @@ public class TestVisibilityLabelsWithDeletes { public void testVisibilityLabelsWithDeleteColumnsWithMultipleVersionsNoTimestamp() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d1 = new Delete(row1); d1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d1.addColumns(fam, qual); @@ -358,8 +166,8 @@ public class TestVisibilityLabelsWithDeletes { table.delete(d2); Delete d3 = new Delete(row1); - d3.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + SECRET + "&" + TOPSECRET + ")")); + d3.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d3.addColumns(fam, qual); table.delete(d3); } catch (Throwable t) { @@ -370,7 +178,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -378,24 +186,23 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test - public void - testVisibilityLabelsWithDeleteColumnsWithNoMatchVisExpWithMultipleVersionsNoTimestamp() + public void testVisibilityLabelsWithDeleteColumnsNoMatchVisExpWithMultipleVersionsNoTimestamp() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addColumns(fam, qual); @@ -407,8 +214,8 @@ public class TestVisibilityLabelsWithDeletes { table.delete(d); d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + SECRET + "&" + TOPSECRET + ")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d.addColumns(fam, qual); table.delete(d); } catch (Throwable t) { @@ -419,7 +226,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -427,13 +234,13 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @@ -441,14 +248,14 @@ public class TestVisibilityLabelsWithDeletes { public void testVisibilityLabelsWithDeleteFamilyWithMultipleVersionsNoTimestamp() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d1 = new Delete(row1); d1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d1.addFamily(fam); @@ -460,8 +267,8 @@ public class TestVisibilityLabelsWithDeletes { table.delete(d2); Delete d3 = new Delete(row1); - d3.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + SECRET + "&" + TOPSECRET + ")")); + d3.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d3.addFamily(fam); table.delete(d3); } catch (Throwable t) { @@ -472,7 +279,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -480,19 +287,14 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testDeleteColumnsWithoutAndWithVisibilityLabels() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(row1); put.addColumn(fam, qual, value); @@ -506,7 +308,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -527,7 +329,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -544,12 +346,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeleteColumnsWithAndWithoutVisibilityLabels() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(row1); put.addColumn(fam, qual, value); @@ -564,7 +361,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -584,7 +381,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -601,12 +398,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeleteFamiliesWithoutAndWithVisibilityLabels() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(row1); put.addColumn(fam, qual, value); @@ -620,7 +412,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -641,7 +433,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -658,12 +450,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeleteFamiliesWithAndWithoutVisibilityLabels() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(row1); put.addColumn(fam, qual, value); @@ -678,7 +465,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -698,7 +485,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -715,12 +502,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeletesWithoutAndWithVisibilityLabels() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(row1); put.addColumn(fam, qual, value); @@ -734,7 +516,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); // The delete would not be able to apply it because of visibility mismatch @@ -756,7 +538,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Scan s = new Scan(); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -774,13 +556,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testVisibilityLabelsWithDeleteFamilyWithPutsReAppearing() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(5); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, value); @@ -795,7 +571,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addFamily(fam); @@ -808,7 +584,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -821,7 +597,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET)); d.addFamily(fam); @@ -834,13 +610,13 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(CONFIDENTIAL)); scanner = table.getScanner(s); next = scanner.next(3); assertEquals(1, next.length); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET)); scanner = table.getScanner(s); Result[] next1 = scanner.next(3); @@ -850,13 +626,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testVisibilityLabelsWithDeleteColumnsWithPutsReAppearing() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(5); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, value); @@ -871,7 +641,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addColumns(fam, qual); @@ -884,7 +654,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -897,7 +667,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET)); d.addColumns(fam, qual); @@ -910,13 +680,13 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(CONFIDENTIAL)); scanner = table.getScanner(s); next = scanner.next(3); assertEquals(1, next.length); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET)); scanner = table.getScanner(s); Result[] next1 = scanner.next(3); @@ -926,13 +696,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testVisibilityCombinations() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(5); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 123L, value); @@ -946,7 +710,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET)); d.addColumns(fam, qual, 126L); @@ -956,7 +720,7 @@ public class TestVisibilityLabelsWithDeletes { } try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addColumn(fam, qual, 123L); @@ -969,24 +733,18 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(CONFIDENTIAL, SECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertEquals(0, next.length); } } + @Test public void testVisibilityLabelsWithDeleteColumnWithSpecificVersionWithPutsReAppearing() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); - + TableName tableName = createTable(5); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put1 = new Put(Bytes.toBytes("row1")); put1.addColumn(fam, qual, 123L, value); @@ -998,7 +756,7 @@ public class TestVisibilityLabelsWithDeletes { table.put(createList(put1, put2)); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(CONFIDENTIAL, SECRET)); ResultScanner scanner = table.getScanner(s); @@ -1009,7 +767,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addColumn(fam, qual, 123L); @@ -1017,7 +775,7 @@ public class TestVisibilityLabelsWithDeletes { } try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET)); d.addColumn(fam, qual, 123L); @@ -1030,7 +788,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(CONFIDENTIAL)); scanner = table.getScanner(s); assertEquals(0, scanner.next(3).length); @@ -1039,11 +797,10 @@ public class TestVisibilityLabelsWithDeletes { } @Test - public void - testVisibilityLabelsWithDeleteFamilyWithNoMatchingVisExpWithMultipleVersionsNoTimestamp() + public void testVisibilityLabelsWithDeleteFamilyNoMatchingVisExpWithMultipleVersionsNoTimestamp() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @@ -1058,12 +815,12 @@ public class TestVisibilityLabelsWithDeletes { d2.addFamily(fam); Delete d3 = new Delete(row1); - d3.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + SECRET + "&" + TOPSECRET + ")")); + d3.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d3.addFamily(fam); try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { table.delete(createList(d1, d2, d3)); } catch (Throwable t) { throw new IOException(t); @@ -1073,7 +830,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1081,13 +838,13 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); scanner.close(); } } @@ -1095,7 +852,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeleteFamilyAndDeleteColumnsWithAndWithoutVisibilityExp() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @@ -1108,7 +865,7 @@ public class TestVisibilityLabelsWithDeletes { d2.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d2.addColumns(fam, qual); try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { table.delete(createList(d1, d2)); } catch (Throwable t) { throw new IOException(t); @@ -1118,7 +875,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1126,41 +883,36 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); scanner.close(); } } private Table doPuts(TableName tableName) throws IOException, InterruptedIOException, RetriesExhaustedWithDetailsException, InterruptedException { - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + createTable(tableName, 5); List puts = new ArrayList<>(5); Put put = new Put(Bytes.toBytes("row1")); @@ -1170,8 +922,8 @@ public class TestVisibilityLabelsWithDeletes { put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 124L, value); - put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + put.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); puts.add(put); put = new Put(Bytes.toBytes("row1")); @@ -1181,21 +933,21 @@ public class TestVisibilityLabelsWithDeletes { put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 126L, value); - put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + put.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); puts.add(put); put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 127L, value); - put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + put.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); puts.add(put); TEST_UTIL.getAdmin().flush(tableName); put = new Put(Bytes.toBytes("row2")); put.addColumn(fam, qual, 127L, value); - put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET - + "&" + SECRET + ")")); + put.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); puts.add(put); Table table = TEST_UTIL.getConnection().getTable(tableName); @@ -1203,14 +955,9 @@ public class TestVisibilityLabelsWithDeletes { return table; } - private Table doPutsWithDiffCols(TableName tableName) throws IOException, - InterruptedIOException, RetriesExhaustedWithDetailsException, InterruptedException { - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + private Table doPutsWithDiffCols(TableName tableName) throws IOException, InterruptedIOException, + RetriesExhaustedWithDetailsException, InterruptedException { + createTable(tableName, 5); List puts = new ArrayList<>(5); Put put = new Put(Bytes.toBytes("row1")); @@ -1220,8 +967,8 @@ public class TestVisibilityLabelsWithDeletes { put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 124L, value); - put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + put.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); puts.add(put); put = new Put(Bytes.toBytes("row1")); @@ -1236,8 +983,8 @@ public class TestVisibilityLabelsWithDeletes { put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual2, 127L, value); - put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + put.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); puts.add(put); Table table = TEST_UTIL.getConnection().getTable(tableName); @@ -1247,12 +994,7 @@ public class TestVisibilityLabelsWithDeletes { private Table doPutsWithoutVisibility(TableName tableName) throws IOException, InterruptedIOException, RetriesExhaustedWithDetailsException, InterruptedException { - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + createTable(tableName, 5); List puts = new ArrayList<>(5); Put put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 123L, value); @@ -1286,22 +1028,21 @@ public class TestVisibilityLabelsWithDeletes { return table; } - @Test public void testDeleteColumnWithSpecificTimeStampUsingMultipleVersionsUnMatchingVisExpression() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + - SECRET + "&" + TOPSECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d.addColumn(fam, qual, 125L); table.delete(d); } catch (Throwable t) { @@ -1314,7 +1055,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1322,48 +1063,48 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testDeleteColumnWithLatestTimeStampUsingMultipleVersions() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumn(fam, qual); @@ -1378,7 +1119,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1386,36 +1127,36 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } - @Test (timeout=180000) + @Test(timeout = 180000) public void testDeleteColumnWithLatestTimeStampWhenNoVersionMatches() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); Put put = new Put(Bytes.toBytes("row1")); @@ -1426,9 +1167,9 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility(SECRET )); + d.setCellVisibility(new CellVisibility(SECRET)); d.addColumn(fam, qual); table.delete(d); } catch (Throwable t) { @@ -1441,7 +1182,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1449,34 +1190,34 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(128L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 129L, value); @@ -1485,7 +1226,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -1493,23 +1234,24 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(129L, current.getTimestamp()); } } + @Test public void testDeleteColumnWithLatestTimeStampUsingMultipleVersionsAfterCompaction() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumn(fam, qual); @@ -1531,7 +1273,7 @@ public class TestVisibilityLabelsWithDeletes { // Sleep to ensure compaction happens. Need to do it in a better way Thread.sleep(5000); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1539,43 +1281,43 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testDeleteFamilyLatestTimeStampWithMulipleVersions() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addFamily(fam); @@ -1590,7 +1332,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1598,26 +1340,26 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testDeleteColumnswithMultipleColumnsWithMultipleVersions() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPutsWithDiffCols(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @@ -1627,7 +1369,7 @@ public class TestVisibilityLabelsWithDeletes { d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumns(fam, qual, 125L); try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { table.delete(d); } catch (Throwable t) { throw new IOException(t); @@ -1639,7 +1381,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1647,40 +1389,34 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), - current.getQualifierLength(), qual1, 0, qual1.length)); + current.getQualifierLength(), qual1, 0, qual1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), - current.getQualifierLength(), qual2, 0, qual2.length)); + current.getQualifierLength(), qual2, 0, qual2.length)); } } @Test public void testDeleteColumnsWithDiffColsAndTags() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(5); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual1, 125L, value); @@ -1703,7 +1439,7 @@ public class TestVisibilityLabelsWithDeletes { d2.addColumns(fam, qual1, 125L); try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { table.delete(createList(d1, d2)); } catch (Throwable t) { throw new IOException(t); @@ -1713,22 +1449,17 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertEquals(1, next.length); } } + @Test public void testDeleteColumnsWithDiffColsAndTags1() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(5); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual1, 125L, value); @@ -1751,7 +1482,7 @@ public class TestVisibilityLabelsWithDeletes { d2.addColumns(fam, qual1, 126L); try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { table.delete(createList(d1, d2)); } catch (Throwable t) { throw new IOException(t); @@ -1761,24 +1492,25 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertEquals(1, next.length); } } + @Test public void testDeleteFamilyWithoutCellVisibilityWithMulipleVersions() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPutsWithoutVisibility(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addFamily(fam); table.delete(d); @@ -1792,7 +1524,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1801,8 +1533,8 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @@ -1810,13 +1542,13 @@ public class TestVisibilityLabelsWithDeletes { public void testDeleteFamilyLatestTimeStampWithMulipleVersionsWithoutCellVisibilityInPuts() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPutsWithoutVisibility(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addFamily(fam); @@ -1830,7 +1562,7 @@ public class TestVisibilityLabelsWithDeletes { SUPERUSER.runAs(actiona); TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1838,51 +1570,51 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testDeleteFamilySpecificTimeStampWithMulipleVersions() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + SECRET + "&" + TOPSECRET + ")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d.addFamily(fam, 126L); table.delete(d); } catch (Throwable t) { @@ -1895,7 +1627,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(6); @@ -1903,41 +1635,41 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testScanAfterCompaction() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + - SECRET + "&" + TOPSECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")")); d.addFamily(fam, 126L); table.delete(d); } catch (Throwable t) { @@ -1958,7 +1690,7 @@ public class TestVisibilityLabelsWithDeletes { Thread.sleep(5000); // Sleep to ensure compaction happens. Need to do it in a better way Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -1966,31 +1698,31 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testDeleteFamilySpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); // Do not flush here. try (Table table = doPuts(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addFamily(fam, 125L); table.delete(d); } catch (Throwable t) { @@ -2002,7 +1734,7 @@ public class TestVisibilityLabelsWithDeletes { SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -2010,39 +1742,39 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addFamily(fam, 127L); table.delete(d); } catch (Throwable t) { @@ -2053,7 +1785,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2061,19 +1793,19 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); assertEquals(127L, current.getTimestamp()); } } @@ -2081,25 +1813,25 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testMultipleDeleteFamilyVersionWithDiffLabels() throws Exception { PrivilegedExceptionAction action = - new PrivilegedExceptionAction() { - @Override - public VisibilityLabelsResponse run() throws Exception { - try (Connection conn = ConnectionFactory.createConnection(conf)) { - return VisibilityClient.setAuths(conn, new String[] { CONFIDENTIAL, PRIVATE, SECRET }, + new PrivilegedExceptionAction() { + @Override + public VisibilityLabelsResponse run() throws Exception { + try (Connection conn = ConnectionFactory.createConnection(conf)) { + return VisibilityClient.setAuths(conn, new String[] { CONFIDENTIAL, PRIVATE, SECRET }, SUPERUSER.getShortName()); - } catch (Throwable e) { + } catch (Throwable e) { + } + return null; } - return null; - } - }; - VisibilityLabelsResponse response = SUPERUSER.runAs(action); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + }; + SUPERUSER.runAs(action); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addFamilyVersion(fam, 123L); @@ -2118,7 +1850,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(5); @@ -2126,35 +1858,35 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); } } - @Test (timeout=180000) + @Test(timeout = 180000) public void testSpecificDeletesFollowedByDeleteFamily() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - try (Table table = doPuts(tableName)){ + final TableName tableName = TableName.valueOf(testName.getMethodName()); + try (Table table = doPuts(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET + ")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumn(fam, qual, 126L); table.delete(d); d = new Delete(row1); @@ -2171,7 +1903,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(5); @@ -2179,25 +1911,25 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addFamily(fam); @@ -2210,7 +1942,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(5); @@ -2218,13 +1950,13 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); } } @@ -2232,29 +1964,28 @@ public class TestVisibilityLabelsWithDeletes { @Test(timeout = 180000) public void testSpecificDeletesFollowedByDeleteFamily1() throws Exception { PrivilegedExceptionAction action = - new PrivilegedExceptionAction() { - @Override - public VisibilityLabelsResponse run() throws Exception { - try (Connection conn = ConnectionFactory.createConnection(conf)) { - return VisibilityClient.setAuths(conn, new String[] { CONFIDENTIAL, - PRIVATE, SECRET }, + new PrivilegedExceptionAction() { + @Override + public VisibilityLabelsResponse run() throws Exception { + try (Connection conn = ConnectionFactory.createConnection(conf)) { + return VisibilityClient.setAuths(conn, new String[] { CONFIDENTIAL, PRIVATE, SECRET }, SUPERUSER.getShortName()); - } catch (Throwable e) { + } catch (Throwable e) { + } + return null; } - return null; - } - }; - VisibilityLabelsResponse response = SUPERUSER.runAs(action); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + }; + SUPERUSER.runAs(action); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET + ")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumn(fam, qual); table.delete(d); @@ -2272,7 +2003,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(5); @@ -2280,25 +2011,25 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.addFamily(fam); @@ -2311,7 +2042,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(5); @@ -2319,13 +2050,13 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); } } @@ -2333,13 +2064,13 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); try (Table table = doPuts(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumn(fam, qual, 125L); @@ -2353,7 +2084,7 @@ public class TestVisibilityLabelsWithDeletes { SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -2361,39 +2092,39 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumn(fam, qual, 127L); table.delete(d); } catch (Throwable t) { @@ -2404,7 +2135,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2412,24 +2143,24 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); assertEquals(127L, current.getTimestamp()); } } @@ -2437,17 +2168,17 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice1() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); // Do not flush here. try (Table table = doPuts(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")" + - "|(" + TOPSECRET + "&" + SECRET + ")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")" + "|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumn(fam, qual, 127L); table.delete(d); } catch (Throwable t) { @@ -2459,7 +2190,7 @@ public class TestVisibilityLabelsWithDeletes { SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -2467,36 +2198,36 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumn(fam, qual, 127L); @@ -2509,7 +2240,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2517,36 +2248,37 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); assertEquals(127L, current.getTimestamp()); } } + @Test public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice2() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); // Do not flush here. try (Table table = doPuts(tableName)) { @@ -2554,10 +2286,10 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumn(fam, qual, 125L); table.delete(d); } catch (Throwable t) { @@ -2569,7 +2301,7 @@ public class TestVisibilityLabelsWithDeletes { SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -2577,44 +2309,44 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumn(fam, qual, 127L); table.delete(d); } catch (Throwable t) { @@ -2625,7 +2357,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2633,44 +2365,45 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); assertEquals(127L, current.getTimestamp()); } } + @Test public void testDeleteColumnAndDeleteFamilylSpecificTimeStampWithMulipleVersion() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); + final TableName tableName = TableName.valueOf(testName.getMethodName()); // Do not flush here. try (Table table = doPuts(tableName)) { PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.addColumn(fam, qual, 125L); @@ -2684,7 +2417,7 @@ public class TestVisibilityLabelsWithDeletes { SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -2692,39 +2425,39 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addFamily(fam, 124L); table.delete(d); } catch (Throwable t) { @@ -2735,7 +2468,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2743,54 +2476,37 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); assertEquals(127L, current.getTimestamp()); } } - private void setAuths() throws IOException, InterruptedException { - PrivilegedExceptionAction action = - new PrivilegedExceptionAction() { - @Override - public VisibilityLabelsResponse run() throws Exception { - try (Connection conn = ConnectionFactory.createConnection(conf)) { - return VisibilityClient.setAuths(conn, new String[] { CONFIDENTIAL, - PRIVATE, SECRET, - TOPSECRET }, SUPERUSER.getShortName()); - } catch (Throwable e) { - } - return null; - } - }; - SUPERUSER.runAs(action); - } - @Test public void testDiffDeleteTypesForTheSameCellUsingMultipleVersions() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - try (Table table = doPuts(tableName)){ + final TableName tableName = TableName.valueOf(testName.getMethodName()); + try (Table table = doPuts(tableName)) { // Do not flush here. PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumns(fam, qual, 125L); table.delete(d); } catch (Throwable t) { @@ -2802,7 +2518,7 @@ public class TestVisibilityLabelsWithDeletes { SUPERUSER.runAs(actiona); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -2810,39 +2526,39 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); // Issue 2nd delete actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); - d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" - + TOPSECRET + "&" + SECRET+")")); + d.setCellVisibility(new CellVisibility( + "(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")")); d.addColumn(fam, qual, 127L); table.delete(d); } catch (Throwable t) { @@ -2853,7 +2569,7 @@ public class TestVisibilityLabelsWithDeletes { }; SUPERUSER.runAs(actiona); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2861,38 +2577,38 @@ public class TestVisibilityLabelsWithDeletes { cellScanner = next[0].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row2, 0, row2.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); } } @Test public void testDeleteColumnLatestWithNoCellVisibility() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - try (Table table = doPuts(tableName)){ + final TableName tableName = TableName.valueOf(testName.getMethodName()); + try (Table table = doPuts(tableName)) { TEST_UTIL.getAdmin().flush(tableName); PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addColumn(fam, qual, 125L); table.delete(d); @@ -2906,7 +2622,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -2916,7 +2632,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addColumns(fam, qual, 125L); table.delete(d); @@ -2930,7 +2646,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2941,7 +2657,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addFamily(fam, 125L); table.delete(d); @@ -2955,7 +2671,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2966,7 +2682,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addFamily(fam); table.delete(d); @@ -2980,7 +2696,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -2991,7 +2707,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addColumns(fam, qual); table.delete(d); @@ -3005,7 +2721,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -3016,7 +2732,7 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addFamilyVersion(fam, 126L); table.delete(d); @@ -3030,7 +2746,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); scanner = table.getScanner(s); next = scanner.next(3); @@ -3044,45 +2760,39 @@ public class TestVisibilityLabelsWithDeletes { cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), - row1, 0, row1.length)); + row1, 0, row1.length)); assertEquals(127L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), - row1, 0, row1.length)); + row1, 0, row1.length)); assertEquals(126L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), - row1, 0, row1.length)); + row1, 0, row1.length)); assertEquals(125L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), - row1, 0, row1.length)); + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), - row1, 0, row1.length)); + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), - row2, 0, row2.length)); + row2, 0, row2.length)); } @Test public void testVisibilityExpressionWithNotEqualORCondition() throws Exception { setAuths(); - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(5); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { Put put = new Put(Bytes.toBytes("row1")); put.addColumn(fam, qual, 123L, value); @@ -3097,10 +2807,10 @@ public class TestVisibilityLabelsWithDeletes { @Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); - Table table = connection.getTable(tableName)) { + Table table = connection.getTable(tableName)) { Delete d = new Delete(row1); d.addColumn(fam, qual, 124L); - d.setCellVisibility(new CellVisibility(PRIVATE )); + d.setCellVisibility(new CellVisibility(PRIVATE)); table.delete(d); } catch (Throwable t) { throw new IOException(t); @@ -3112,7 +2822,7 @@ public class TestVisibilityLabelsWithDeletes { TEST_UTIL.getAdmin().flush(tableName); Scan s = new Scan(); - s.setMaxVersions(5); + s.readVersions(5); s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); @@ -3120,48 +2830,42 @@ public class TestVisibilityLabelsWithDeletes { CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(124L, current.getTimestamp()); cellScanner.advance(); current = cellScanner.current(); - assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), - current.getRowLength(), row1, 0, row1.length)); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); assertEquals(123L, current.getTimestamp()); } } @Test public void testDeleteWithNoVisibilitiesForPutsAndDeletes() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); - Put p = new Put (Bytes.toBytes("row1")); + TableName tableName = createTable(5); + Put p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual, value); Table table = TEST_UTIL.getConnection().getTable(tableName); table.put(p); - p = new Put (Bytes.toBytes("row1")); + p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual1, value); table.put(p); - p = new Put (Bytes.toBytes("row2")); + p = new Put(Bytes.toBytes("row2")); p.addColumn(fam, qual, value); table.put(p); - p = new Put (Bytes.toBytes("row2")); + p = new Put(Bytes.toBytes("row2")); p.addColumn(fam, qual1, value); table.put(p); Delete d = new Delete(Bytes.toBytes("row1")); table.delete(d); Get g = new Get(Bytes.toBytes("row1")); - g.setMaxVersions(); + g.readAllVersions(); g.setAuthorizations(new Authorizations(SECRET, PRIVATE)); Result result = table.get(g); assertEquals(0, result.rawCells().length); - p = new Put (Bytes.toBytes("row1")); + p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual, value); table.put(p); result = table.get(g); @@ -3170,13 +2874,7 @@ public class TestVisibilityLabelsWithDeletes { @Test public void testDeleteWithFamilyDeletesOfSameTsButDifferentVisibilities() throws Exception { - final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = createTable(5); Table table = TEST_UTIL.getConnection().getTable(tableName); long t1 = 1234L; CellVisibility cellVisibility1 = new CellVisibility(SECRET); @@ -3203,7 +2901,7 @@ public class TestVisibilityLabelsWithDeletes { table.delete(d); Get g = new Get(row1); - g.setMaxVersions(); + g.readAllVersions(); g.setAuthorizations(new Authorizations(SECRET, PRIVATE)); Result result = table.get(g); assertEquals(0, result.rawCells().length); @@ -3230,77 +2928,19 @@ public class TestVisibilityLabelsWithDeletes { table.delete(d); g = new Get(row2); - g.setMaxVersions(); + g.readAllVersions(); g.setAuthorizations(new Authorizations(SECRET, PRIVATE)); result = table.get(g); assertEquals(0, result.rawCells().length); } - public Table createTableAndWriteDataWithLabels(String... labelExps) - throws Exception { - HColumnDescriptor cf = new HColumnDescriptor(fam); - Table table = createTable(cf); - int i = 1; - List puts = new ArrayList<>(labelExps.length); - for (String labelExp : labelExps) { - Put put = new Put(Bytes.toBytes("row" + i)); - put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, value); - put.setCellVisibility(new CellVisibility(labelExp)); - puts.add(put); - table.put(put); - i++; - } - // table.put(puts); - return table; - } - - public Table createTableAndWriteDataWithLabels(long[] timestamp, - String... labelExps) throws Exception { - HColumnDescriptor cf = new HColumnDescriptor(fam); - Table table = createTable(cf); - int i = 1; - List puts = new ArrayList<>(labelExps.length); - for (String labelExp : labelExps) { - Put put = new Put(Bytes.toBytes("row" + i)); - put.addColumn(fam, qual, timestamp[i - 1], value); - put.setCellVisibility(new CellVisibility(labelExp)); - puts.add(put); - table.put(put); - TEST_UTIL.getAdmin().flush(table.getName()); - i++; - } - return table; - } - - public static void addLabels() throws Exception { - PrivilegedExceptionAction action = - new PrivilegedExceptionAction() { - @Override - public VisibilityLabelsResponse run() throws Exception { - String[] labels = { SECRET, TOPSECRET, CONFIDENTIAL, PUBLIC, PRIVATE }; - try (Connection conn = ConnectionFactory.createConnection(conf)) { - VisibilityClient.addLabels(conn, labels); - } catch (Throwable t) { - throw new IOException(t); - } - return null; - } - }; - SUPERUSER.runAs(action); - } - @SafeVarargs public static List createList(T... ts) { return new ArrayList<>(Arrays.asList(ts)); } - private enum DeleteMark { - ROW, - FAMILY, - FAMILY_VERSION, - COLUMN, - CELL + ROW, FAMILY, FAMILY_VERSION, COLUMN, CELL } private static Delete addDeleteMark(Delete d, DeleteMark mark, long now) { @@ -3332,15 +2972,11 @@ public class TestVisibilityLabelsWithDeletes { } } - private void testDeleteCellWithoutVisibility(DeleteMark mark) throws IOException, InterruptedException { + private void testDeleteCellWithoutVisibility(DeleteMark mark) + throws IOException, InterruptedException { setAuths(); - final TableName tableName = TableName.valueOf("testDeleteCellWithoutVisibility-" + mark.name()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = TableName.valueOf("testDeleteCellWithoutVisibility-" + mark.name()); + createTable(tableName, 5); long now = EnvironmentEdgeManager.currentTime(); List puts = new ArrayList<>(1); Put put = new Put(row1); @@ -3351,7 +2987,7 @@ public class TestVisibilityLabelsWithDeletes { } puts.add(put); - try (Table table = TEST_UTIL.getConnection().getTable(tableName)){ + try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { table.put(puts); Result r = table.get(new Get(row1)); assertEquals(1, r.size()); @@ -3372,15 +3008,11 @@ public class TestVisibilityLabelsWithDeletes { } } - private void testDeleteCellWithVisibility(DeleteMark mark) throws IOException, InterruptedException { + private void testDeleteCellWithVisibility(DeleteMark mark) + throws IOException, InterruptedException { setAuths(); - final TableName tableName = TableName.valueOf("testDeleteCellWithVisibility-" + mark.name()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = TableName.valueOf("testDeleteCellWithVisibility-" + mark.name()); + createTable(tableName, 5); long now = EnvironmentEdgeManager.currentTime(); List puts = new ArrayList<>(2); Put put = new Put(row1); @@ -3425,15 +3057,11 @@ public class TestVisibilityLabelsWithDeletes { } } - private void testDeleteCellWithVisibilityV2(DeleteMark mark) throws IOException, InterruptedException { + private void testDeleteCellWithVisibilityV2(DeleteMark mark) + throws IOException, InterruptedException { setAuths(); - final TableName tableName = TableName.valueOf("testDeleteCellWithVisibilityV2-" + mark.name()); - Admin hBaseAdmin = TEST_UTIL.getAdmin(); - HColumnDescriptor colDesc = new HColumnDescriptor(fam); - colDesc.setMaxVersions(5); - HTableDescriptor desc = new HTableDescriptor(tableName); - desc.addFamily(colDesc); - hBaseAdmin.createTable(desc); + TableName tableName = TableName.valueOf("testDeleteCellWithVisibilityV2-" + mark.name()); + createTable(tableName, 5); long now = EnvironmentEdgeManager.currentTime(); List puts = new ArrayList<>(2); Put put = new Put(row1); @@ -3451,7 +3079,7 @@ public class TestVisibilityLabelsWithDeletes { put.addColumn(fam, qual, value1); } puts.add(put); - try (Table table = TEST_UTIL.getConnection().getTable(tableName)){ + try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { table.put(puts); Result r = table.get(new Get(row1)); assertEquals(1, r.size()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelsWithDeletesTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelsWithDeletesTestBase.java new file mode 100644 index 00000000000..ee5d3cc10b1 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelsWithDeletesTestBase.java @@ -0,0 +1,313 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.security.visibility; + +import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.List; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CellScanner; +import org.apache.hadoop.hbase.HBaseTestingUtility; +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.Delete; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse; +import org.apache.hadoop.hbase.security.User; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +/** + * Tests visibility labels with deletes + */ +public abstract class VisibilityLabelsWithDeletesTestBase { + + protected static final String TOPSECRET = "TOPSECRET"; + protected static final String PUBLIC = "PUBLIC"; + protected static final String PRIVATE = "PRIVATE"; + protected static final String CONFIDENTIAL = "CONFIDENTIAL"; + protected static final String SECRET = "SECRET"; + protected static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + protected static final byte[] row1 = Bytes.toBytes("row1"); + protected static final byte[] row2 = Bytes.toBytes("row2"); + protected final static byte[] fam = Bytes.toBytes("info"); + protected final static byte[] qual = Bytes.toBytes("qual"); + protected final static byte[] qual1 = Bytes.toBytes("qual1"); + protected final static byte[] qual2 = Bytes.toBytes("qual2"); + protected final static byte[] value = Bytes.toBytes("value"); + protected final static byte[] value1 = Bytes.toBytes("value1"); + protected static Configuration conf; + + @Rule + public final TestName testName = new TestName(); + protected static User SUPERUSER; + + @BeforeClass + public static void setupBeforeClass() throws Exception { + // setup configuration + conf = TEST_UTIL.getConfiguration(); + VisibilityTestUtil.enableVisiblityLabels(conf); + conf.setClass(VisibilityUtils.VISIBILITY_LABEL_GENERATOR_CLASS, SimpleScanLabelGenerator.class, + ScanLabelGenerator.class); + conf.set("hbase.superuser", "admin"); + TEST_UTIL.startMiniCluster(2); + SUPERUSER = User.createUserForTesting(conf, "admin", new String[] { "supergroup" }); + + // Wait for the labels table to become available + TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000); + addLabels(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + public static void addLabels() throws Exception { + PrivilegedExceptionAction action = + new PrivilegedExceptionAction() { + @Override + public VisibilityLabelsResponse run() throws Exception { + String[] labels = { SECRET, TOPSECRET, CONFIDENTIAL, PUBLIC, PRIVATE }; + try (Connection conn = ConnectionFactory.createConnection(conf)) { + VisibilityClient.addLabels(conn, labels); + } catch (Throwable t) { + throw new IOException(t); + } + return null; + } + }; + SUPERUSER.runAs(action); + } + + protected abstract Table createTable(byte[] fam) throws IOException; + + protected final void setAuths() throws IOException, InterruptedException { + PrivilegedExceptionAction action = + new PrivilegedExceptionAction() { + @Override + public VisibilityLabelsResponse run() throws Exception { + try (Connection conn = ConnectionFactory.createConnection(conf)) { + return VisibilityClient.setAuths(conn, + new String[] { CONFIDENTIAL, PRIVATE, SECRET, TOPSECRET }, SUPERUSER.getShortName()); + } catch (Throwable e) { + } + return null; + } + }; + SUPERUSER.runAs(action); + } + + private Table createTableAndWriteDataWithLabels(String... labelExps) throws Exception { + Table table = createTable(fam); + int i = 1; + List puts = new ArrayList<>(labelExps.length); + for (String labelExp : labelExps) { + Put put = new Put(Bytes.toBytes("row" + i)); + put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, value); + put.setCellVisibility(new CellVisibility(labelExp)); + puts.add(put); + table.put(put); + i++; + } + // table.put(puts); + return table; + } + + private Table createTableAndWriteDataWithLabels(long[] timestamp, String... labelExps) + throws Exception { + Table table = createTable(fam); + int i = 1; + List puts = new ArrayList<>(labelExps.length); + for (String labelExp : labelExps) { + Put put = new Put(Bytes.toBytes("row" + i)); + put.addColumn(fam, qual, timestamp[i - 1], value); + put.setCellVisibility(new CellVisibility(labelExp)); + puts.add(put); + table.put(put); + TEST_UTIL.getAdmin().flush(table.getName()); + i++; + } + return table; + } + + @Test + public void testVisibilityLabelsWithDeleteColumns() throws Throwable { + setAuths(); + final TableName tableName = TableName.valueOf(testName.getMethodName()); + + try (Table table = createTableAndWriteDataWithLabels(SECRET + "&" + TOPSECRET, SECRET)) { + PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + 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); + table.delete(d); + } catch (Throwable t) { + throw new IOException(t); + } + return null; + } + }; + SUPERUSER.runAs(actiona); + + TEST_UTIL.getAdmin().flush(tableName); + Scan s = new Scan(); + s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); + ResultScanner scanner = table.getScanner(s); + Result[] next = scanner.next(3); + assertTrue(next.length == 1); + CellScanner cellScanner = next[0].cellScanner(); + cellScanner.advance(); + Cell current = cellScanner.current(); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); + + } + } + + @Test + public void testVisibilityLabelsWithDeleteFamily() throws Exception { + setAuths(); + final TableName tableName = TableName.valueOf(testName.getMethodName()); + try (Table table = createTableAndWriteDataWithLabels(SECRET, CONFIDENTIAL + "|" + TOPSECRET)) { + PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + 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); + table.delete(d); + } catch (Throwable t) { + throw new IOException(t); + } + return null; + } + }; + SUPERUSER.runAs(actiona); + + TEST_UTIL.getAdmin().flush(tableName); + Scan s = new Scan(); + s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); + ResultScanner scanner = table.getScanner(s); + Result[] next = scanner.next(3); + assertTrue(next.length == 1); + CellScanner cellScanner = next[0].cellScanner(); + cellScanner.advance(); + Cell current = cellScanner.current(); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row1, 0, row1.length)); + } + } + + @Test + public void testVisibilityLabelsWithDeleteFamilyVersion() throws Exception { + setAuths(); + final TableName tableName = TableName.valueOf(testName.getMethodName()); + long[] ts = new long[] { 123L, 125L }; + try ( + Table table = createTableAndWriteDataWithLabels(ts, CONFIDENTIAL + "|" + TOPSECRET, SECRET)) { + PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + try (Connection connection = ConnectionFactory.createConnection(conf); + Table table = connection.getTable(tableName)) { + Delete d = new Delete(row1); + d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL)); + d.addFamilyVersion(fam, 123L); + table.delete(d); + } catch (Throwable t) { + throw new IOException(t); + } + return null; + } + }; + SUPERUSER.runAs(actiona); + + TEST_UTIL.getAdmin().flush(tableName); + Scan s = new Scan(); + s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); + ResultScanner scanner = table.getScanner(s); + Result[] next = scanner.next(3); + assertTrue(next.length == 1); + CellScanner cellScanner = next[0].cellScanner(); + cellScanner.advance(); + Cell current = cellScanner.current(); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); + } + } + + @Test + public void testVisibilityLabelsWithDeleteColumnExactVersion() throws Exception { + setAuths(); + final TableName tableName = TableName.valueOf(testName.getMethodName()); + long[] ts = new long[] { 123L, 125L }; + try ( + Table table = createTableAndWriteDataWithLabels(ts, CONFIDENTIAL + "|" + TOPSECRET, SECRET)) { + PrivilegedExceptionAction actiona = new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + 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); + table.delete(d); + } catch (Throwable t) { + throw new IOException(t); + } + return null; + } + }; + SUPERUSER.runAs(actiona); + + TEST_UTIL.getAdmin().flush(tableName); + Scan s = new Scan(); + s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL)); + ResultScanner scanner = table.getScanner(s); + Result[] next = scanner.next(3); + assertTrue(next.length == 1); + CellScanner cellScanner = next[0].cellScanner(); + cellScanner.advance(); + Cell current = cellScanner.current(); + assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), + row2, 0, row2.length)); + } + } +}