1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.security.visibility;
19
20 import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
23
24 import java.io.IOException;
25 import java.io.InterruptedIOException;
26 import java.security.PrivilegedExceptionAction;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.apache.hadoop.conf.Configuration;
31 import org.apache.hadoop.hbase.Cell;
32 import org.apache.hadoop.hbase.CellScanner;
33 import org.apache.hadoop.hbase.HBaseTestingUtility;
34 import org.apache.hadoop.hbase.HColumnDescriptor;
35 import org.apache.hadoop.hbase.HConstants;
36 import org.apache.hadoop.hbase.HTableDescriptor;
37 import org.apache.hadoop.hbase.testclassification.MediumTests;
38 import org.apache.hadoop.hbase.TableName;
39 import org.apache.hadoop.hbase.client.Delete;
40 import org.apache.hadoop.hbase.client.Get;
41 import org.apache.hadoop.hbase.client.HBaseAdmin;
42 import org.apache.hadoop.hbase.client.HTable;
43 import org.apache.hadoop.hbase.client.Put;
44 import org.apache.hadoop.hbase.client.Result;
45 import org.apache.hadoop.hbase.client.ResultScanner;
46 import org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException;
47 import org.apache.hadoop.hbase.client.Scan;
48 import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse;
49 import org.apache.hadoop.hbase.security.User;
50 import org.apache.hadoop.hbase.util.Bytes;
51 import org.junit.After;
52 import org.junit.AfterClass;
53 import org.junit.BeforeClass;
54 import org.junit.Rule;
55 import org.junit.Test;
56 import org.junit.experimental.categories.Category;
57 import org.junit.rules.TestName;
58
59
60
61
62 @Category(MediumTests.class)
63 public class TestVisibilityLabelsWithDeletes {
64 private static final String TOPSECRET = "TOPSECRET";
65 private static final String PUBLIC = "PUBLIC";
66 private static final String PRIVATE = "PRIVATE";
67 private static final String CONFIDENTIAL = "CONFIDENTIAL";
68 private static final String SECRET = "SECRET";
69 public static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
70 private static final byte[] row1 = Bytes.toBytes("row1");
71 private static final byte[] row2 = Bytes.toBytes("row2");
72 private final static byte[] fam = Bytes.toBytes("info");
73 private final static byte[] qual = Bytes.toBytes("qual");
74 private final static byte[] qual1 = Bytes.toBytes("qual1");
75 private final static byte[] qual2 = Bytes.toBytes("qual2");
76 private final static byte[] value = Bytes.toBytes("value");
77 private final static byte[] value1 = Bytes.toBytes("value1");
78 public static Configuration conf;
79
80 @Rule
81 public final TestName TEST_NAME = new TestName();
82 public static User SUPERUSER;
83
84 @BeforeClass
85 public static void setupBeforeClass() throws Exception {
86
87 conf = TEST_UTIL.getConfiguration();
88 conf.setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, false);
89 VisibilityTestUtil.enableVisiblityLabels(conf);
90 conf.setClass(VisibilityUtils.VISIBILITY_LABEL_GENERATOR_CLASS, SimpleScanLabelGenerator.class,
91 ScanLabelGenerator.class);
92 conf.set("hbase.superuser", "admin");
93 TEST_UTIL.startMiniCluster(2);
94 SUPERUSER = User.createUserForTesting(conf, "admin", new String[] { "supergroup" });
95
96
97 TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
98 addLabels();
99 }
100
101 @AfterClass
102 public static void tearDownAfterClass() throws Exception {
103 TEST_UTIL.shutdownMiniCluster();
104 }
105
106 @After
107 public void tearDown() throws Exception {
108 }
109
110 @Test
111 public void testVisibilityLabelsWithDeleteColumns() throws Throwable {
112 setAuths();
113 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
114 final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + TOPSECRET,
115 SECRET);
116 try {
117 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
118 public Void run() throws Exception {
119 HTable table = null;
120 try {
121 table = new HTable(conf, TEST_NAME.getMethodName());
122 Delete d = new Delete(row1);
123 d.setCellVisibility(new CellVisibility(TOPSECRET + "&" + SECRET));
124 d.deleteColumns(fam, qual);
125 table.delete(d);
126 } catch (Throwable t) {
127 throw new IOException(t);
128 } finally {
129 table.close();
130 }
131 return null;
132 }
133 };
134 SUPERUSER.runAs(actiona);
135
136 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
137 Scan s = new Scan();
138 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL));
139 ResultScanner scanner = table.getScanner(s);
140 Result[] next = scanner.next(3);
141 assertTrue(next.length == 1);
142 CellScanner cellScanner = next[0].cellScanner();
143 cellScanner.advance();
144 Cell current = cellScanner.current();
145 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
146 current.getRowLength(), row2, 0, row2.length));
147
148 } finally {
149 if (table != null) {
150 table.close();
151 }
152 }
153 }
154
155 @Test
156 public void testVisibilityLabelsWithDeleteFamily() throws Exception {
157 setAuths();
158 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
159 final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET, CONFIDENTIAL + "|"
160 + TOPSECRET);
161 try {
162 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
163 public Void run() throws Exception {
164 try {
165 HTable table = new HTable(conf, TEST_NAME.getMethodName());
166 Delete d = new Delete(row2);
167 d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
168 d.deleteFamily(fam);
169 table.delete(d);
170 } catch (Throwable t) {
171 throw new IOException(t);
172 }
173 return null;
174 }
175 };
176 SUPERUSER.runAs(actiona);
177
178 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
179 Scan s = new Scan();
180 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL));
181 ResultScanner scanner = table.getScanner(s);
182 Result[] next = scanner.next(3);
183 assertTrue(next.length == 1);
184 CellScanner cellScanner = next[0].cellScanner();
185 cellScanner.advance();
186 Cell current = cellScanner.current();
187 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
188 current.getRowLength(), row1, 0, row1.length));
189 } finally {
190 if (table != null) {
191 table.close();
192 }
193 }
194 }
195
196 @Test
197 public void testVisibilityLabelsWithDeleteFamilyVersion() throws Exception {
198 setAuths();
199 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
200 long[] ts = new long[] { 123l, 125l };
201 final HTable table = createTableAndWriteDataWithLabels(tableName, ts, CONFIDENTIAL + "|"
202 + TOPSECRET, SECRET);
203 try {
204 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
205 public Void run() throws Exception {
206 HTable table = null;
207 try {
208 table = new HTable(conf, TEST_NAME.getMethodName());
209 Delete d = new Delete(row1);
210 d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
211 d.deleteFamilyVersion(fam, 123l);
212 table.delete(d);
213 } catch (Throwable t) {
214 throw new IOException(t);
215 } finally {
216 table.close();
217 }
218 return null;
219 }
220 };
221 SUPERUSER.runAs(actiona);
222
223 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
224 Scan s = new Scan();
225 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL));
226 ResultScanner scanner = table.getScanner(s);
227 Result[] next = scanner.next(3);
228 assertTrue(next.length == 1);
229 CellScanner cellScanner = next[0].cellScanner();
230 cellScanner.advance();
231 Cell current = cellScanner.current();
232 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
233 current.getRowLength(), row2, 0, row2.length));
234 } finally {
235 if (table != null) {
236 table.close();
237 }
238 }
239 }
240
241 @Test
242 public void testVisibilityLabelsWithDeleteColumnExactVersion() throws Exception {
243 setAuths();
244 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
245 long[] ts = new long[] { 123l, 125l };
246 final HTable table = createTableAndWriteDataWithLabels(tableName, ts, CONFIDENTIAL + "|"
247 + TOPSECRET, SECRET);
248 try {
249 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
250 public Void run() throws Exception {
251 HTable table = null;
252 try {
253 table = new HTable(conf, TEST_NAME.getMethodName());
254 Delete d = new Delete(row1);
255 d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
256 d.deleteColumn(fam, qual, 123l);
257 table.delete(d);
258 } catch (Throwable t) {
259 throw new IOException(t);
260 } finally {
261 table.close();
262 }
263 return null;
264 }
265 };
266 SUPERUSER.runAs(actiona);
267
268 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
269 Scan s = new Scan();
270 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL));
271 ResultScanner scanner = table.getScanner(s);
272 Result[] next = scanner.next(3);
273 assertTrue(next.length == 1);
274 CellScanner cellScanner = next[0].cellScanner();
275 cellScanner.advance();
276 Cell current = cellScanner.current();
277 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
278 current.getRowLength(), row2, 0, row2.length));
279 } finally {
280 if (table != null) {
281 table.close();
282 }
283 }
284 }
285
286 @Test
287 public void testVisibilityLabelsWithDeleteColumnsWithMultipleVersions() throws Exception {
288 setAuths();
289 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
290 HTable table = null;
291 try {
292 table = doPuts(tableName);
293 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
294 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
295 public Void run() throws Exception {
296 try {
297 HTable table = new HTable(conf, TEST_NAME.getMethodName());
298 Delete d = new Delete(row1);
299 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
300 SECRET + "&" + TOPSECRET+")"));
301 d.deleteColumns(fam, qual, 125l);
302 table.delete(d);
303 } catch (Throwable t) {
304 throw new IOException(t);
305 }
306 return null;
307 }
308 };
309 SUPERUSER.runAs(actiona);
310
311 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
312 Scan s = new Scan();
313 s.setMaxVersions(5);
314 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
315 ResultScanner scanner = table.getScanner(s);
316 Result[] next = scanner.next(3);
317 assertTrue(next.length == 2);
318 CellScanner cellScanner = next[0].cellScanner();
319 cellScanner.advance();
320 Cell current = cellScanner.current();
321 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
322 current.getRowLength(), row1, 0, row1.length));
323 assertEquals(current.getTimestamp(), 127l);
324 cellScanner.advance();
325 current = cellScanner.current();
326 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
327 current.getRowLength(), row1, 0, row1.length));
328 assertEquals(current.getTimestamp(), 126l);
329 cellScanner.advance();
330 current = cellScanner.current();
331 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
332 current.getRowLength(), row1, 0, row1.length));
333 assertEquals(current.getTimestamp(), 125l);
334 cellScanner = next[1].cellScanner();
335 cellScanner.advance();
336 current = cellScanner.current();
337 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
338 current.getRowLength(), row2, 0, row2.length));
339 } finally {
340 if (table != null) {
341 table.close();
342 }
343 }
344 }
345
346 @Test
347 public void testVisibilityLabelsWithDeleteColumnsWithMultipleVersionsNoTimestamp()
348 throws Exception {
349 setAuths();
350 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
351 HTable table = null;
352 try {
353 table = doPuts(tableName);
354 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
355 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
356 public Void run() throws Exception {
357 try {
358 HTable table = new HTable(conf, TEST_NAME.getMethodName());
359 Delete d = new Delete(row1);
360 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
361 d.deleteColumns(fam, qual);
362 table.delete(d);
363
364 d = new Delete(row1);
365 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
366 d.deleteColumns(fam, qual);
367 table.delete(d);
368 table.flushCommits();
369
370 d = new Delete(row1);
371 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
372 + SECRET + "&" + TOPSECRET + ")"));
373 d.deleteColumns(fam, qual);
374 table.delete(d);
375 table.flushCommits();
376 } catch (Throwable t) {
377 throw new IOException(t);
378 }
379 return null;
380 }
381 };
382 SUPERUSER.runAs(actiona);
383 Scan s = new Scan();
384 s.setMaxVersions(5);
385 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
386 ResultScanner scanner = table.getScanner(s);
387 Result[] next = scanner.next(3);
388 assertTrue(next.length == 1);
389 CellScanner cellScanner = next[0].cellScanner();
390 cellScanner.advance();
391 Cell current = cellScanner.current();
392 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
393 current.getRowLength(), row2, 0, row2.length));
394 } finally {
395 if (table != null) {
396 table.close();
397 }
398 }
399 }
400
401 @Test
402 public void
403 testVisibilityLabelsWithDeleteColumnsWithNoMatchVisExpWithMultipleVersionsNoTimestamp()
404 throws Exception {
405 setAuths();
406 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
407 HTable table = null;
408 try {
409 table = doPuts(tableName);
410 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
411 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
412 public Void run() throws Exception {
413 try {
414 HTable table = new HTable(conf, TEST_NAME.getMethodName());
415 Delete d = new Delete(row1);
416 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
417 d.deleteColumns(fam, qual);
418 table.delete(d);
419
420 d = new Delete(row1);
421 d.setCellVisibility(new CellVisibility(SECRET));
422 d.deleteColumns(fam, qual);
423 table.delete(d);
424 table.flushCommits();
425
426 d = new Delete(row1);
427 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
428 + SECRET + "&" + TOPSECRET + ")"));
429 d.deleteColumns(fam, qual);
430 table.delete(d);
431 table.flushCommits();
432 } catch (Throwable t) {
433 throw new IOException(t);
434 }
435 return null;
436 }
437 };
438 SUPERUSER.runAs(actiona);
439 Scan s = new Scan();
440 s.setMaxVersions(5);
441 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
442 ResultScanner scanner = table.getScanner(s);
443 Result[] next = scanner.next(3);
444 assertTrue(next.length == 2);
445 CellScanner cellScanner = next[0].cellScanner();
446 cellScanner.advance();
447 Cell current = cellScanner.current();
448 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
449 current.getRowLength(), row1, 0, row1.length));
450 cellScanner = next[1].cellScanner();
451 cellScanner.advance();
452 current = cellScanner.current();
453 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
454 current.getRowLength(), row2, 0, row2.length));
455 } finally {
456 if (table != null) {
457 table.close();
458 }
459 }
460 }
461
462 @Test
463 public void testVisibilityLabelsWithDeleteFamilyWithMultipleVersionsNoTimestamp()
464 throws Exception {
465 setAuths();
466 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
467 HTable table = null;
468 try {
469 table = doPuts(tableName);
470 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
471 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
472 public Void run() throws Exception {
473 try {
474 HTable table = new HTable(conf, TEST_NAME.getMethodName());
475 Delete d = new Delete(row1);
476 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
477 d.deleteFamily(fam);
478 table.delete(d);
479
480 d = new Delete(row1);
481 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
482 d.deleteFamily(fam);
483 table.delete(d);
484 table.flushCommits();
485
486 d = new Delete(row1);
487 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
488 + SECRET + "&" + TOPSECRET + ")"));
489 d.deleteFamily(fam);
490 table.delete(d);
491 table.flushCommits();
492 } catch (Throwable t) {
493 throw new IOException(t);
494 }
495 return null;
496 }
497 };
498 SUPERUSER.runAs(actiona);
499 Scan s = new Scan();
500 s.setMaxVersions(5);
501 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
502 ResultScanner scanner = table.getScanner(s);
503 Result[] next = scanner.next(3);
504 assertTrue(next.length == 1);
505 CellScanner cellScanner = next[0].cellScanner();
506 cellScanner.advance();
507 Cell current = cellScanner.current();
508 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
509 current.getRowLength(), row2, 0, row2.length));
510 } finally {
511 if (table != null) {
512 table.close();
513 }
514 }
515 }
516
517 @Test
518 public void testVisibilityLabelsWithDeleteFamilyWithPutsReAppearing() throws Exception {
519 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
520 HTable table = null;
521 try {
522 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
523 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
524 colDesc.setMaxVersions(5);
525 HTableDescriptor desc = new HTableDescriptor(tableName);
526 desc.addFamily(colDesc);
527 hBaseAdmin.createTable(desc);
528 table = new HTable(conf, tableName);
529 Put put = new Put(Bytes.toBytes("row1"));
530 put.add(fam, qual, value);
531 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
532 table.put(put);
533 put = new Put(Bytes.toBytes("row1"));
534 put.add(fam, qual, value);
535 put.setCellVisibility(new CellVisibility(SECRET));
536 table.put(put);
537 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
538 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
539 public Void run() throws Exception {
540 try {
541 HTable table = new HTable(conf, TEST_NAME.getMethodName());
542 Delete d = new Delete(row1);
543 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
544 d.deleteFamily(fam);
545 table.delete(d);
546 table.flushCommits();
547 } catch (Throwable t) {
548 throw new IOException(t);
549 }
550 return null;
551 }
552 };
553 SUPERUSER.runAs(actiona);
554 Scan s = new Scan();
555 s.setMaxVersions(5);
556 s.setAuthorizations(new Authorizations(SECRET));
557 ResultScanner scanner = table.getScanner(s);
558 Result[] next = scanner.next(3);
559 assertEquals(next.length, 1);
560 put = new Put(Bytes.toBytes("row1"));
561 put.add(fam, qual, value1);
562 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
563 table.put(put);
564 actiona = new PrivilegedExceptionAction<Void>() {
565 public Void run() throws Exception {
566 try {
567 HTable table = new HTable(conf, TEST_NAME.getMethodName());
568 Delete d = new Delete(row1);
569 d.setCellVisibility(new CellVisibility(SECRET));
570 d.deleteFamily(fam);
571 table.delete(d);
572 table.flushCommits();
573 } catch (Throwable t) {
574 throw new IOException(t);
575 }
576 return null;
577 }
578 };
579 SUPERUSER.runAs(actiona);
580 s = new Scan();
581 s.setMaxVersions(5);
582 s.setAuthorizations(new Authorizations(CONFIDENTIAL));
583 scanner = table.getScanner(s);
584 next = scanner.next(3);
585 assertEquals(next.length, 1);
586 s = new Scan();
587 s.setMaxVersions(5);
588 s.setAuthorizations(new Authorizations(SECRET));
589 scanner = table.getScanner(s);
590 Result[] next1 = scanner.next(3);
591 assertEquals(next1.length, 0);
592 } finally {
593 if (table != null) {
594 table.close();
595 }
596 }
597 }
598
599 @Test
600 public void testVisibilityLabelsWithDeleteColumnsWithPutsReAppearing() throws Exception {
601 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
602 HTable table = null;
603 try {
604 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
605 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
606 colDesc.setMaxVersions(5);
607 HTableDescriptor desc = new HTableDescriptor(tableName);
608 desc.addFamily(colDesc);
609 hBaseAdmin.createTable(desc);
610 table = new HTable(conf, tableName);
611 Put put = new Put(Bytes.toBytes("row1"));
612 put.add(fam, qual, value);
613 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
614 table.put(put);
615 put = new Put(Bytes.toBytes("row1"));
616 put.add(fam, qual, value);
617 put.setCellVisibility(new CellVisibility(SECRET));
618 table.put(put);
619 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
620 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
621 public Void run() throws Exception {
622 try {
623 HTable table = new HTable(conf, TEST_NAME.getMethodName());
624 Delete d = new Delete(row1);
625 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
626 d.deleteColumns(fam, qual);
627 table.delete(d);
628 table.flushCommits();
629 } catch (Throwable t) {
630 throw new IOException(t);
631 }
632 return null;
633 }
634 };
635 SUPERUSER.runAs(actiona);
636 Scan s = new Scan();
637 s.setMaxVersions(5);
638 s.setAuthorizations(new Authorizations(SECRET));
639 ResultScanner scanner = table.getScanner(s);
640 Result[] next = scanner.next(3);
641 assertEquals(next.length, 1);
642 put = new Put(Bytes.toBytes("row1"));
643 put.add(fam, qual, value1);
644 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
645 table.put(put);
646 actiona = new PrivilegedExceptionAction<Void>() {
647 public Void run() throws Exception {
648 try {
649 HTable table = new HTable(conf, TEST_NAME.getMethodName());
650 Delete d = new Delete(row1);
651 d.setCellVisibility(new CellVisibility(SECRET));
652 d.deleteColumns(fam, qual);
653 table.delete(d);
654 table.flushCommits();
655 } catch (Throwable t) {
656 throw new IOException(t);
657 }
658 return null;
659 }
660 };
661 SUPERUSER.runAs(actiona);
662 s = new Scan();
663 s.setMaxVersions(5);
664 s.setAuthorizations(new Authorizations(CONFIDENTIAL));
665 scanner = table.getScanner(s);
666 next = scanner.next(3);
667 assertEquals(next.length, 1);
668 s = new Scan();
669 s.setMaxVersions(5);
670 s.setAuthorizations(new Authorizations(SECRET));
671 scanner = table.getScanner(s);
672 Result[] next1 = scanner.next(3);
673 assertEquals(next1.length, 0);
674 } finally {
675 if (table != null) {
676 table.close();
677 }
678 }
679 }
680
681 @Test
682 public void testVisibilityCombinations() throws Exception {
683 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
684 HTable table = null;
685 try {
686 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
687 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
688 colDesc.setMaxVersions(5);
689 HTableDescriptor desc = new HTableDescriptor(tableName);
690 desc.addFamily(colDesc);
691 hBaseAdmin.createTable(desc);
692 table = new HTable(conf, tableName);
693 Put put = new Put(Bytes.toBytes("row1"));
694 put.add(fam, qual, 123l, value);
695 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
696 table.put(put);
697 put = new Put(Bytes.toBytes("row1"));
698 put.add(fam, qual, 124l, value1);
699 put.setCellVisibility(new CellVisibility(SECRET));
700 table.put(put);
701 table.flushCommits();
702 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
703 public Void run() throws Exception {
704 try {
705 HTable table = new HTable(conf, TEST_NAME.getMethodName());
706 Delete d = new Delete(row1);
707 d.setCellVisibility(new CellVisibility(SECRET));
708 d.deleteColumns(fam, qual, 126l);
709 table.delete(d);
710
711 table = new HTable(conf, TEST_NAME.getMethodName());
712 d = new Delete(row1);
713 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
714 d.deleteColumn(fam, qual, 123l);
715 table.delete(d);
716 table.flushCommits();
717 } catch (Throwable t) {
718 throw new IOException(t);
719 }
720 return null;
721 }
722 };
723 SUPERUSER.runAs(actiona);
724 Scan s = new Scan();
725 s.setMaxVersions(5);
726 s.setAuthorizations(new Authorizations(CONFIDENTIAL, SECRET));
727 ResultScanner scanner = table.getScanner(s);
728 Result[] next = scanner.next(3);
729 assertEquals(next.length, 0);
730 } finally {
731 if (table != null) {
732 table.close();
733 }
734 }
735 }
736 @Test
737 public void testVisibilityLabelsWithDeleteColumnWithSpecificVersionWithPutsReAppearing()
738 throws Exception {
739 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
740 HTable table = null;
741 try {
742 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
743 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
744 colDesc.setMaxVersions(5);
745 HTableDescriptor desc = new HTableDescriptor(tableName);
746 desc.addFamily(colDesc);
747 hBaseAdmin.createTable(desc);
748 table = new HTable(conf, tableName);
749 Put put = new Put(Bytes.toBytes("row1"));
750 put.add(fam, qual, 123l, value);
751 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
752 table.put(put);
753 put = new Put(Bytes.toBytes("row1"));
754 put.add(fam, qual, 123l, value1);
755 put.setCellVisibility(new CellVisibility(SECRET));
756 table.put(put);
757 table.flushCommits();
758
759 Scan s = new Scan();
760 s.setMaxVersions(5);
761 s.setAuthorizations(new Authorizations(CONFIDENTIAL, SECRET));
762 ResultScanner scanner = table.getScanner(s);
763 Result[] next = scanner.next(3);
764 assertEquals(next.length, 1);
765 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
766 public Void run() throws Exception {
767 try {
768 HTable table = new HTable(conf, TEST_NAME.getMethodName());
769 Delete d = new Delete(row1);
770 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
771 d.deleteColumn(fam, qual, 123l);
772 table.delete(d);
773
774 table = new HTable(conf, TEST_NAME.getMethodName());
775 d = new Delete(row1);
776 d.setCellVisibility(new CellVisibility(SECRET));
777 d.deleteColumn(fam, qual, 123l);
778 table.delete(d);
779 table.flushCommits();
780 } catch (Throwable t) {
781 throw new IOException(t);
782 }
783 return null;
784 }
785 };
786 SUPERUSER.runAs(actiona);
787 s = new Scan();
788 s.setMaxVersions(5);
789 s.setAuthorizations(new Authorizations(CONFIDENTIAL));
790 scanner = table.getScanner(s);
791 next = scanner.next(3);
792 assertEquals(next.length, 0);
793 } finally {
794 if (table != null) {
795 table.close();
796 }
797 }
798 }
799
800 @Test
801 public void
802 testVisibilityLabelsWithDeleteFamilyWithNoMatchingVisExpWithMultipleVersionsNoTimestamp()
803 throws Exception {
804 setAuths();
805 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
806 HTable table = null;
807 try {
808 table = doPuts(tableName);
809 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
810 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
811 public Void run() throws Exception {
812 try {
813 HTable table = new HTable(conf, TEST_NAME.getMethodName());
814 Delete d = new Delete(row1);
815 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
816 d.deleteFamily(fam);
817 table.delete(d);
818
819 d = new Delete(row1);
820 d.setCellVisibility(new CellVisibility(SECRET));
821 d.deleteFamily(fam);
822 table.delete(d);
823 table.flushCommits();
824
825 d = new Delete(row1);
826 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
827 + SECRET + "&" + TOPSECRET + ")"));
828 d.deleteFamily(fam);
829 table.delete(d);
830 table.flushCommits();
831 } catch (Throwable t) {
832 throw new IOException(t);
833 }
834 return null;
835 }
836 };
837 SUPERUSER.runAs(actiona);
838 Scan s = new Scan();
839 s.setMaxVersions(5);
840 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
841 ResultScanner scanner = table.getScanner(s);
842 Result[] next = scanner.next(3);
843 assertTrue(next.length == 2);
844 CellScanner cellScanner = next[0].cellScanner();
845 cellScanner.advance();
846 Cell current = cellScanner.current();
847 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
848 current.getRowLength(), row1, 0, row1.length));
849 cellScanner = next[1].cellScanner();
850 cellScanner.advance();
851 current = cellScanner.current();
852 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
853 current.getRowLength(), row2, 0, row2.length));
854 } finally {
855 if (table != null) {
856 table.close();
857 }
858 }
859 }
860
861 @Test
862 public void testDeleteFamilyAndDeleteColumnsWithAndWithoutVisibilityExp() throws Exception {
863 setAuths();
864 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
865 HTable table = null;
866 try {
867 table = doPuts(tableName);
868 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
869 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
870 public Void run() throws Exception {
871 try {
872 HTable table = new HTable(conf, TEST_NAME.getMethodName());
873 Delete d = new Delete(row1);
874 d.deleteFamily(fam);
875 table.delete(d);
876
877 d = new Delete(row1);
878 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
879 d.deleteColumns(fam, qual);
880 table.delete(d);
881 table.flushCommits();
882 } catch (Throwable t) {
883 throw new IOException(t);
884 }
885 return null;
886 }
887 };
888 SUPERUSER.runAs(actiona);
889 Scan s = new Scan();
890 s.setMaxVersions(5);
891 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
892 ResultScanner scanner = table.getScanner(s);
893 Result[] next = scanner.next(3);
894 assertTrue(next.length == 2);
895 CellScanner cellScanner = next[0].cellScanner();
896 cellScanner.advance();
897 Cell current = cellScanner.current();
898 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
899 current.getRowLength(), row1, 0, row1.length));
900 assertEquals(current.getTimestamp(), 127l);
901 cellScanner.advance();
902 current = cellScanner.current();
903 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
904 current.getRowLength(), row1, 0, row1.length));
905 assertEquals(current.getTimestamp(), 126l);
906 cellScanner.advance();
907 current = cellScanner.current();
908 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
909 current.getRowLength(), row1, 0, row1.length));
910 assertEquals(current.getTimestamp(), 124l);
911 cellScanner.advance();
912 current = cellScanner.current();
913 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
914 current.getRowLength(), row1, 0, row1.length));
915 assertEquals(current.getTimestamp(), 123l);
916 cellScanner = next[1].cellScanner();
917 cellScanner.advance();
918 current = cellScanner.current();
919 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
920 current.getRowLength(), row2, 0, row2.length));
921 } finally {
922 if (table != null) {
923 table.close();
924 }
925 }
926 }
927
928 private HTable doPuts(TableName tableName) throws IOException, InterruptedIOException,
929 RetriesExhaustedWithDetailsException, InterruptedException {
930 HTable table;
931 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
932 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
933 colDesc.setMaxVersions(5);
934 HTableDescriptor desc = new HTableDescriptor(tableName);
935 desc.addFamily(colDesc);
936 hBaseAdmin.createTable(desc);
937 table = new HTable(conf, tableName);
938 Put put = new Put(Bytes.toBytes("row1"));
939 put.add(fam, qual, 123l, value);
940 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
941 table.put(put);
942 put = new Put(Bytes.toBytes("row1"));
943 put.add(fam, qual, 124l, value);
944 put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
945 + TOPSECRET + "&" + SECRET+")"));
946 table.put(put);
947 put = new Put(Bytes.toBytes("row1"));
948 put.add(fam, qual, 125l, value);
949 put.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
950 table.put(put);
951 put = new Put(Bytes.toBytes("row1"));
952 put.add(fam, qual, 126l, value);
953 put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
954 + TOPSECRET + "&" + SECRET+")"));
955 table.put(put);
956 put = new Put(Bytes.toBytes("row1"));
957 put.add(fam, qual, 127l, value);
958 put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
959 + TOPSECRET + "&" + SECRET+")"));
960 table.put(put);
961 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
962 put = new Put(Bytes.toBytes("row2"));
963 put.add(fam, qual, 127l, value);
964 put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET
965 + "&" + SECRET + ")"));
966 table.put(put);
967 return table;
968 }
969
970 private HTable doPutsWithDiffCols(TableName tableName) throws IOException,
971 InterruptedIOException, RetriesExhaustedWithDetailsException, InterruptedException {
972 HTable table;
973 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
974 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
975 colDesc.setMaxVersions(5);
976 HTableDescriptor desc = new HTableDescriptor(tableName);
977 desc.addFamily(colDesc);
978 hBaseAdmin.createTable(desc);
979 table = new HTable(conf, tableName);
980 Put put = new Put(Bytes.toBytes("row1"));
981 put.add(fam, qual, 123l, value);
982 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
983 table.put(put);
984 put = new Put(Bytes.toBytes("row1"));
985 put.add(fam, qual, 124l, value);
986 put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
987 + TOPSECRET + "&" + SECRET+")"));
988 table.put(put);
989 put = new Put(Bytes.toBytes("row1"));
990 put.add(fam, qual, 125l, value);
991 put.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
992 table.put(put);
993 put = new Put(Bytes.toBytes("row1"));
994 put.add(fam, qual1, 126l, value);
995 put.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
996 table.put(put);
997 put = new Put(Bytes.toBytes("row1"));
998 put.add(fam, qual2, 127l, value);
999 put.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
1000 + TOPSECRET + "&" + SECRET+")"));
1001 table.put(put);
1002 return table;
1003 }
1004
1005 private HTable doPutsWithoutVisibility(TableName tableName) throws IOException,
1006 InterruptedIOException, RetriesExhaustedWithDetailsException, InterruptedException {
1007 HTable table;
1008 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
1009 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
1010 colDesc.setMaxVersions(5);
1011 HTableDescriptor desc = new HTableDescriptor(tableName);
1012 desc.addFamily(colDesc);
1013 hBaseAdmin.createTable(desc);
1014 table = new HTable(conf, tableName);
1015 Put put = new Put(Bytes.toBytes("row1"));
1016 put.add(fam, qual, 123l, value);
1017 table.put(put);
1018 put = new Put(Bytes.toBytes("row1"));
1019 put.add(fam, qual, 124l, value);
1020 table.put(put);
1021 put = new Put(Bytes.toBytes("row1"));
1022 put.add(fam, qual, 125l, value);
1023 table.put(put);
1024 put = new Put(Bytes.toBytes("row1"));
1025 put.add(fam, qual, 126l, value);
1026 table.put(put);
1027 put = new Put(Bytes.toBytes("row1"));
1028 put.add(fam, qual, 127l, value);
1029 table.put(put);
1030 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1031 put = new Put(Bytes.toBytes("row2"));
1032 put.add(fam, qual, 127l, value);
1033 table.put(put);
1034 return table;
1035 }
1036
1037
1038 @Test
1039 public void testDeleteColumnWithSpecificTimeStampUsingMultipleVersionsUnMatchingVisExpression()
1040 throws Exception {
1041 setAuths();
1042 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1043 HTable table = null;
1044 try {
1045 table = doPuts(tableName);
1046 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1047 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1048 public Void run() throws Exception {
1049 try {
1050 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1051 Delete d = new Delete(row1);
1052 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
1053 SECRET + "&" + TOPSECRET+")"));
1054 d.deleteColumn(fam, qual, 125l);
1055 table.delete(d);
1056 } catch (Throwable t) {
1057 throw new IOException(t);
1058 }
1059 return null;
1060 }
1061 };
1062 SUPERUSER.runAs(actiona);
1063
1064 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1065 Scan s = new Scan();
1066 s.setMaxVersions(5);
1067 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1068 ResultScanner scanner = table.getScanner(s);
1069 Result[] next = scanner.next(3);
1070 assertTrue(next.length == 2);
1071 CellScanner cellScanner = next[0].cellScanner();
1072 cellScanner.advance();
1073 Cell current = cellScanner.current();
1074 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1075 current.getRowLength(), row1, 0, row1.length));
1076 assertEquals(current.getTimestamp(), 127l);
1077 cellScanner.advance();
1078 current = cellScanner.current();
1079 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1080 current.getRowLength(), row1, 0, row1.length));
1081 assertEquals(current.getTimestamp(), 126l);
1082 cellScanner.advance();
1083 current = cellScanner.current();
1084 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1085 current.getRowLength(), row1, 0, row1.length));
1086 assertEquals(current.getTimestamp(), 125l);
1087 cellScanner.advance();
1088 current = cellScanner.current();
1089 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1090 current.getRowLength(), row1, 0, row1.length));
1091 assertEquals(current.getTimestamp(), 124l);
1092 cellScanner.advance();
1093 current = cellScanner.current();
1094 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1095 current.getRowLength(), row1, 0, row1.length));
1096 assertEquals(current.getTimestamp(), 123l);
1097 cellScanner = next[1].cellScanner();
1098 cellScanner.advance();
1099 current = cellScanner.current();
1100 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1101 current.getRowLength(), row2, 0, row2.length));
1102 } finally {
1103 if (table != null) {
1104 table.close();
1105 }
1106 }
1107 }
1108
1109 @Test
1110 public void testDeleteColumnWithLatestTimeStampUsingMultipleVersions() throws Exception {
1111 setAuths();
1112 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1113 HTable table = null;
1114 try {
1115 table = doPuts(tableName);
1116 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1117 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1118 public Void run() throws Exception {
1119 try {
1120 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1121 Delete d = new Delete(row1);
1122 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
1123 d.deleteColumn(fam, qual);
1124 table.delete(d);
1125 } catch (Throwable t) {
1126 throw new IOException(t);
1127 }
1128 return null;
1129 }
1130 };
1131 SUPERUSER.runAs(actiona);
1132
1133 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1134 Scan s = new Scan();
1135 s.setMaxVersions(5);
1136 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1137 ResultScanner scanner = table.getScanner(s);
1138 Result[] next = scanner.next(3);
1139 assertTrue(next.length == 2);
1140 CellScanner cellScanner = next[0].cellScanner();
1141 cellScanner.advance();
1142 Cell current = cellScanner.current();
1143 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1144 current.getRowLength(), row1, 0, row1.length));
1145 assertEquals(current.getTimestamp(), 127l);
1146 cellScanner.advance();
1147 current = cellScanner.current();
1148 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1149 current.getRowLength(), row1, 0, row1.length));
1150 assertEquals(current.getTimestamp(), 126l);
1151 cellScanner.advance();
1152 current = cellScanner.current();
1153 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1154 current.getRowLength(), row1, 0, row1.length));
1155 assertEquals(current.getTimestamp(), 124l);
1156 cellScanner.advance();
1157 current = cellScanner.current();
1158 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1159 current.getRowLength(), row1, 0, row1.length));
1160 assertEquals(current.getTimestamp(), 123l);
1161 cellScanner = next[1].cellScanner();
1162 cellScanner.advance();
1163 current = cellScanner.current();
1164 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1165 current.getRowLength(), row2, 0, row2.length));
1166 } finally {
1167 if (table != null) {
1168 table.close();
1169 }
1170 }
1171 }
1172
1173 @Test (timeout=180000)
1174 public void testDeleteColumnWithLatestTimeStampWhenNoVersionMatches() throws Exception {
1175 setAuths();
1176 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1177 HTable table = null;
1178 try {
1179 table = doPuts(tableName);
1180 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1181 Put put = new Put(Bytes.toBytes("row1"));
1182 put.add(fam, qual, 128l, value);
1183 put.setCellVisibility(new CellVisibility(TOPSECRET));
1184 table.put(put);
1185 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1186 public Void run() throws Exception {
1187 try {
1188 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1189 Delete d = new Delete(row1);
1190 d.setCellVisibility(new CellVisibility(SECRET ));
1191 d.deleteColumn(fam, qual);
1192 table.delete(d);
1193 } catch (Throwable t) {
1194 throw new IOException(t);
1195 }
1196 return null;
1197 }
1198 };
1199 SUPERUSER.runAs(actiona);
1200
1201 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1202 Scan s = new Scan();
1203 s.setMaxVersions(5);
1204 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1205 ResultScanner scanner = table.getScanner(s);
1206 Result[] next = scanner.next(3);
1207 assertTrue(next.length == 2);
1208 CellScanner cellScanner = next[0].cellScanner();
1209 cellScanner.advance();
1210 Cell current = cellScanner.current();
1211 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1212 current.getRowLength(), row1, 0, row1.length));
1213 assertEquals(current.getTimestamp(), 128l);
1214 cellScanner.advance();
1215 current = cellScanner.current();
1216 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1217 current.getRowLength(), row1, 0, row1.length));
1218 assertEquals(current.getTimestamp(), 127l);
1219 cellScanner.advance();
1220 current = cellScanner.current();
1221 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1222 current.getRowLength(), row1, 0, row1.length));
1223 assertEquals(current.getTimestamp(), 126l);
1224 cellScanner.advance();
1225 current = cellScanner.current();
1226 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1227 current.getRowLength(), row1, 0, row1.length));
1228 assertEquals(current.getTimestamp(), 125l);
1229 cellScanner.advance();
1230 current = cellScanner.current();
1231 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1232 current.getRowLength(), row1, 0, row1.length));
1233 assertEquals(current.getTimestamp(), 124l);
1234 cellScanner = next[1].cellScanner();
1235 cellScanner.advance();
1236 current = cellScanner.current();
1237 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1238 current.getRowLength(), row2, 0, row2.length));
1239
1240 put = new Put(Bytes.toBytes("row1"));
1241 put.add(fam, qual, 129l, value);
1242 put.setCellVisibility(new CellVisibility(SECRET));
1243 table.put(put);
1244 table.flushCommits();
1245 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1246 s = new Scan();
1247 s.setMaxVersions(5);
1248 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1249 scanner = table.getScanner(s);
1250 next = scanner.next(3);
1251 assertTrue(next.length == 2);
1252 cellScanner = next[0].cellScanner();
1253 cellScanner.advance();
1254 current = cellScanner.current();
1255 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1256 current.getRowLength(), row1, 0, row1.length));
1257 assertEquals(current.getTimestamp(), 129l);
1258 } finally {
1259 if (table != null) {
1260 table.close();
1261 }
1262 }
1263 }
1264 @Test
1265 public void testDeleteColumnWithLatestTimeStampUsingMultipleVersionsAfterCompaction()
1266 throws Exception {
1267 setAuths();
1268 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1269 HTable table = null;
1270 try {
1271 table = doPuts(tableName);
1272 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1273 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1274 public Void run() throws Exception {
1275 try {
1276 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1277 Delete d = new Delete(row1);
1278 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
1279 d.deleteColumn(fam, qual);
1280 table.delete(d);
1281 } catch (Throwable t) {
1282 throw new IOException(t);
1283 }
1284 return null;
1285 }
1286 };
1287 SUPERUSER.runAs(actiona);
1288 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1289 Put put = new Put(Bytes.toBytes("row3"));
1290 put.add(fam, qual, 127l, value);
1291 put.setCellVisibility(new CellVisibility(CONFIDENTIAL + "&" + PRIVATE));
1292 table.put(put);
1293 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1294 TEST_UTIL.getHBaseAdmin().majorCompact(tableName.getNameAsString());
1295
1296 Thread.sleep(5000);
1297 Scan s = new Scan();
1298 s.setMaxVersions(5);
1299 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1300 ResultScanner scanner = table.getScanner(s);
1301 Result[] next = scanner.next(3);
1302 assertTrue(next.length == 3);
1303 CellScanner cellScanner = next[0].cellScanner();
1304 cellScanner.advance();
1305 Cell current = cellScanner.current();
1306 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1307 current.getRowLength(), row1, 0, row1.length));
1308 assertEquals(current.getTimestamp(), 127l);
1309 cellScanner.advance();
1310 current = cellScanner.current();
1311 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1312 current.getRowLength(), row1, 0, row1.length));
1313 assertEquals(current.getTimestamp(), 126l);
1314 cellScanner.advance();
1315 current = cellScanner.current();
1316 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1317 current.getRowLength(), row1, 0, row1.length));
1318 assertEquals(current.getTimestamp(), 124l);
1319 cellScanner.advance();
1320 current = cellScanner.current();
1321 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1322 current.getRowLength(), row1, 0, row1.length));
1323 assertEquals(current.getTimestamp(), 123l);
1324 cellScanner = next[1].cellScanner();
1325 cellScanner.advance();
1326 current = cellScanner.current();
1327 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1328 current.getRowLength(), row2, 0, row2.length));
1329 } finally {
1330 if (table != null) {
1331 table.close();
1332 }
1333 }
1334 }
1335
1336 @Test
1337 public void testDeleteFamilyLatestTimeStampWithMulipleVersions() throws Exception {
1338 setAuths();
1339 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1340 HTable table = null;
1341 try {
1342 table = doPuts(tableName);
1343 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1344 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1345 public Void run() throws Exception {
1346 try {
1347 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1348 Delete d = new Delete(row1);
1349 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
1350 d.deleteFamily(fam);
1351 table.delete(d);
1352 } catch (Throwable t) {
1353 throw new IOException(t);
1354 }
1355 return null;
1356 }
1357 };
1358 SUPERUSER.runAs(actiona);
1359
1360 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1361 Scan s = new Scan();
1362 s.setMaxVersions(5);
1363 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1364 ResultScanner scanner = table.getScanner(s);
1365 Result[] next = scanner.next(3);
1366 assertTrue(next.length == 2);
1367 CellScanner cellScanner = next[0].cellScanner();
1368 cellScanner.advance();
1369 Cell current = cellScanner.current();
1370 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1371 current.getRowLength(), row1, 0, row1.length));
1372 assertEquals(current.getTimestamp(), 127l);
1373 cellScanner.advance();
1374 current = cellScanner.current();
1375 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1376 current.getRowLength(), row1, 0, row1.length));
1377 assertEquals(current.getTimestamp(), 126l);
1378 cellScanner = next[1].cellScanner();
1379 cellScanner.advance();
1380 current = cellScanner.current();
1381 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1382 current.getRowLength(), row2, 0, row2.length));
1383 } finally {
1384 if (table != null) {
1385 table.close();
1386 }
1387 }
1388 }
1389
1390 @Test
1391 public void testDeleteColumnswithMultipleColumnsWithMultipleVersions() throws Exception {
1392 setAuths();
1393 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1394 HTable table = null;
1395 try {
1396 table = doPutsWithDiffCols(tableName);
1397 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1398 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1399 public Void run() throws Exception {
1400 try {
1401 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1402 Delete d = new Delete(row1);
1403 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
1404 d.deleteColumns(fam, qual, 125l);
1405 table.delete(d);
1406 } catch (Throwable t) {
1407 throw new IOException(t);
1408 }
1409 return null;
1410 }
1411 };
1412 SUPERUSER.runAs(actiona);
1413
1414 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1415 Scan s = new Scan();
1416 s.setMaxVersions(5);
1417 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1418 ResultScanner scanner = table.getScanner(s);
1419 Result[] next = scanner.next(3);
1420 assertTrue(next.length == 1);
1421 CellScanner cellScanner = next[0].cellScanner();
1422 cellScanner.advance();
1423 Cell current = cellScanner.current();
1424 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1425 current.getRowLength(), row1, 0, row1.length));
1426 assertEquals(current.getTimestamp(), 124l);
1427 cellScanner.advance();
1428 current = cellScanner.current();
1429 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1430 current.getRowLength(), row1, 0, row1.length));
1431 assertEquals(current.getTimestamp(), 123l);
1432 cellScanner.advance();
1433 current = cellScanner.current();
1434 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1435 current.getRowLength(), row1, 0, row1.length));
1436 assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(),
1437 current.getQualifierLength(), qual1, 0, qual1.length));
1438 assertEquals(current.getTimestamp(), 126l);
1439 cellScanner.advance();
1440 current = cellScanner.current();
1441 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1442 current.getRowLength(), row1, 0, row1.length));
1443 assertEquals(current.getTimestamp(), 127l);
1444 assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(),
1445 current.getQualifierLength(), qual2, 0, qual2.length));
1446 } finally {
1447 if (table != null) {
1448 table.close();
1449 }
1450 }
1451 }
1452
1453 @Test
1454 public void testDeleteColumnsWithDiffColsAndTags() throws Exception {
1455 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1456 HTable table = null;
1457 try {
1458 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
1459 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
1460 colDesc.setMaxVersions(5);
1461 HTableDescriptor desc = new HTableDescriptor(tableName);
1462 desc.addFamily(colDesc);
1463 hBaseAdmin.createTable(desc);
1464 table = new HTable(conf, tableName);
1465 Put put = new Put(Bytes.toBytes("row1"));
1466 put.add(fam, qual1, 125l, value);
1467 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
1468 table.put(put);
1469 put = new Put(Bytes.toBytes("row1"));
1470 put.add(fam, qual1, 126l, value);
1471 put.setCellVisibility(new CellVisibility(SECRET));
1472 table.put(put);
1473 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1474 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1475 public Void run() throws Exception {
1476 try {
1477 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1478 Delete d = new Delete(row1);
1479 d.setCellVisibility(new CellVisibility(SECRET));
1480 d.deleteColumns(fam, qual, 126l);
1481 table.delete(d);
1482 d = new Delete(row1);
1483 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
1484 d.deleteColumns(fam, qual1, 125l);
1485 table.delete(d);
1486 table.flushCommits();
1487 } catch (Throwable t) {
1488 throw new IOException(t);
1489 }
1490 return null;
1491 }
1492 };
1493 SUPERUSER.runAs(actiona);
1494 Scan s = new Scan();
1495 s.setMaxVersions(5);
1496 s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
1497 ResultScanner scanner = table.getScanner(s);
1498 Result[] next = scanner.next(3);
1499 assertEquals(next.length, 1);
1500 } finally {
1501 if (table != null) {
1502 table.close();
1503 }
1504 }
1505 }
1506 @Test
1507 public void testDeleteColumnsWithDiffColsAndTags1() throws Exception {
1508 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1509 HTable table = null;
1510 try {
1511 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
1512 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
1513 colDesc.setMaxVersions(5);
1514 HTableDescriptor desc = new HTableDescriptor(tableName);
1515 desc.addFamily(colDesc);
1516 hBaseAdmin.createTable(desc);
1517 table = new HTable(conf, tableName);
1518 Put put = new Put(Bytes.toBytes("row1"));
1519 put.add(fam, qual1, 125l, value);
1520 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
1521 table.put(put);
1522 put = new Put(Bytes.toBytes("row1"));
1523 put.add(fam, qual1, 126l, value);
1524 put.setCellVisibility(new CellVisibility(SECRET));
1525 table.put(put);
1526 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1527 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1528 public Void run() throws Exception {
1529 try {
1530 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1531 Delete d = new Delete(row1);
1532 d.setCellVisibility(new CellVisibility(SECRET));
1533 d.deleteColumns(fam, qual, 126l);
1534 table.delete(d);
1535 d = new Delete(row1);
1536 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
1537 d.deleteColumns(fam, qual1, 126l);
1538 table.delete(d);
1539 table.flushCommits();
1540 } catch (Throwable t) {
1541 throw new IOException(t);
1542 }
1543 return null;
1544 }
1545 };
1546 SUPERUSER.runAs(actiona);
1547 Scan s = new Scan();
1548 s.setMaxVersions(5);
1549 s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
1550 ResultScanner scanner = table.getScanner(s);
1551 Result[] next = scanner.next(3);
1552 assertEquals(next.length, 1);
1553 } finally {
1554 if (table != null) {
1555 table.close();
1556 }
1557 }
1558 }
1559 @Test
1560 public void testDeleteFamilyWithoutCellVisibilityWithMulipleVersions() throws Exception {
1561 setAuths();
1562 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1563 HTable table = null;
1564 try {
1565 table = doPutsWithoutVisibility(tableName);
1566 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1567 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1568 public Void run() throws Exception {
1569 try {
1570 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1571 Delete d = new Delete(row1);
1572 d.deleteFamily(fam);
1573 table.delete(d);
1574 } catch (Throwable t) {
1575 throw new IOException(t);
1576 }
1577 return null;
1578 }
1579 };
1580 SUPERUSER.runAs(actiona);
1581
1582 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1583 Scan s = new Scan();
1584 s.setMaxVersions(5);
1585 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1586 ResultScanner scanner = table.getScanner(s);
1587 Result[] next = scanner.next(3);
1588 assertTrue(next.length == 1);
1589
1590 CellScanner cellScanner = next[0].cellScanner();
1591 cellScanner.advance();
1592 Cell current = cellScanner.current();
1593 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1594 current.getRowLength(), row2, 0, row2.length));
1595 } finally {
1596 if (table != null) {
1597 table.close();
1598 }
1599 }
1600 }
1601
1602 @Test
1603 public void testDeleteFamilyLatestTimeStampWithMulipleVersionsWithoutCellVisibilityInPuts()
1604 throws Exception {
1605 setAuths();
1606 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1607 HTable table = null;
1608 try {
1609 table = doPutsWithoutVisibility(tableName);
1610 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1611 public Void run() throws Exception {
1612 try {
1613 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1614 Delete d = new Delete(row1);
1615 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
1616 d.deleteFamily(fam);
1617 table.delete(d);
1618 } catch (Throwable t) {
1619 throw new IOException(t);
1620 }
1621 return null;
1622 }
1623 };
1624 SUPERUSER.runAs(actiona);
1625 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1626 Scan s = new Scan();
1627 s.setMaxVersions(5);
1628 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1629 ResultScanner scanner = table.getScanner(s);
1630 Result[] next = scanner.next(3);
1631 assertTrue(next.length == 2);
1632 CellScanner cellScanner = next[0].cellScanner();
1633 cellScanner.advance();
1634 Cell current = cellScanner.current();
1635 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1636 current.getRowLength(), row1, 0, row1.length));
1637 assertEquals(current.getTimestamp(), 127l);
1638 cellScanner.advance();
1639 current = cellScanner.current();
1640 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1641 current.getRowLength(), row1, 0, row1.length));
1642 assertEquals(current.getTimestamp(), 126l);
1643 cellScanner.advance();
1644 current = cellScanner.current();
1645 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1646 current.getRowLength(), row1, 0, row1.length));
1647 assertEquals(current.getTimestamp(), 125l);
1648 cellScanner.advance();
1649 current = cellScanner.current();
1650 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1651 current.getRowLength(), row1, 0, row1.length));
1652 assertEquals(current.getTimestamp(), 124l);
1653 cellScanner.advance();
1654 current = cellScanner.current();
1655 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1656 current.getRowLength(), row1, 0, row1.length));
1657 assertEquals(current.getTimestamp(), 123l);
1658 cellScanner = next[1].cellScanner();
1659 cellScanner.advance();
1660 current = cellScanner.current();
1661 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1662 current.getRowLength(), row2, 0, row2.length));
1663 } finally {
1664 if (table != null) {
1665 table.close();
1666 }
1667 }
1668 }
1669
1670 @Test
1671 public void testDeleteFamilySpecificTimeStampWithMulipleVersions() throws Exception {
1672 setAuths();
1673 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1674 HTable table = null;
1675 try {
1676 table = doPuts(tableName);
1677 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1678 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1679 public Void run() throws Exception {
1680 try {
1681 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1682 Delete d = new Delete(row1);
1683 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
1684 + SECRET + "&" + TOPSECRET + ")"));
1685 d.deleteFamily(fam, 126l);
1686 table.delete(d);
1687 } catch (Throwable t) {
1688 throw new IOException(t);
1689 }
1690 return null;
1691 }
1692 };
1693 SUPERUSER.runAs(actiona);
1694
1695 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1696 Scan s = new Scan();
1697 s.setMaxVersions(5);
1698 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1699 ResultScanner scanner = table.getScanner(s);
1700 Result[] next = scanner.next(6);
1701 assertTrue(next.length == 2);
1702 CellScanner cellScanner = next[0].cellScanner();
1703 cellScanner.advance();
1704 Cell current = cellScanner.current();
1705 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1706 current.getRowLength(), row1, 0, row1.length));
1707 assertEquals(current.getTimestamp(), 127l);
1708 cellScanner.advance();
1709 current = cellScanner.current();
1710 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1711 current.getRowLength(), row1, 0, row1.length));
1712 assertEquals(current.getTimestamp(), 125l);
1713 cellScanner.advance();
1714 current = cellScanner.current();
1715 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1716 current.getRowLength(), row1, 0, row1.length));
1717 assertEquals(current.getTimestamp(), 123l);
1718 cellScanner = next[1].cellScanner();
1719 cellScanner.advance();
1720 current = cellScanner.current();
1721 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1722 current.getRowLength(), row2, 0, row2.length));
1723 } finally {
1724 if (table != null) {
1725 table.close();
1726 }
1727 }
1728 }
1729
1730 @Test
1731 public void testScanAfterCompaction() throws Exception {
1732 setAuths();
1733 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1734 HTable table = null;
1735 try {
1736 table = doPuts(tableName);
1737 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1738 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1739 public Void run() throws Exception {
1740 try {
1741 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1742 Delete d = new Delete(row1);
1743 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
1744 SECRET + "&" + TOPSECRET+")"));
1745 d.deleteFamily(fam, 126l);
1746 table.delete(d);
1747 } catch (Throwable t) {
1748 throw new IOException(t);
1749 }
1750 return null;
1751 }
1752 };
1753 SUPERUSER.runAs(actiona);
1754
1755 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1756 Put put = new Put(Bytes.toBytes("row3"));
1757 put.add(fam, qual, 127l, value);
1758 put.setCellVisibility(new CellVisibility(CONFIDENTIAL + "&" + PRIVATE));
1759 table.put(put);
1760 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1761 TEST_UTIL.getHBaseAdmin().compact(tableName.getNameAsString());
1762 Thread.sleep(5000);
1763
1764 Scan s = new Scan();
1765 s.setMaxVersions(5);
1766 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1767 ResultScanner scanner = table.getScanner(s);
1768 Result[] next = scanner.next(3);
1769 assertTrue(next.length == 3);
1770 CellScanner cellScanner = next[0].cellScanner();
1771 cellScanner.advance();
1772 Cell current = cellScanner.current();
1773 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1774 current.getRowLength(), row1, 0, row1.length));
1775 assertEquals(current.getTimestamp(), 127l);
1776 cellScanner = next[1].cellScanner();
1777 cellScanner.advance();
1778 current = cellScanner.current();
1779 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1780 current.getRowLength(), row2, 0, row2.length));
1781 } finally {
1782 if (table != null) {
1783 table.close();
1784 }
1785 }
1786 }
1787
1788 @Test
1789 public void testDeleteFamilySpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception {
1790 setAuths();
1791 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1792 HTable table = null;
1793 try {
1794
1795 table = doPuts(tableName);
1796 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1797 public Void run() throws Exception {
1798 try {
1799 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1800 Delete d = new Delete(row1);
1801 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
1802 + TOPSECRET + "&" + SECRET+")"));
1803 d.deleteFamily(fam, 125l);
1804 table.delete(d);
1805 } catch (Throwable t) {
1806 throw new IOException(t);
1807 }
1808 return null;
1809 }
1810 };
1811 SUPERUSER.runAs(actiona);
1812
1813 Scan s = new Scan();
1814 s.setMaxVersions(5);
1815 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1816 ResultScanner scanner = table.getScanner(s);
1817 Result[] next = scanner.next(3);
1818 assertTrue(next.length == 2);
1819 CellScanner cellScanner = next[0].cellScanner();
1820 cellScanner.advance();
1821 Cell current = cellScanner.current();
1822 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1823 current.getRowLength(), row1, 0, row1.length));
1824 assertEquals(current.getTimestamp(), 127l);
1825 cellScanner.advance();
1826 current = cellScanner.current();
1827 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1828 current.getRowLength(), row1, 0, row1.length));
1829 assertEquals(current.getTimestamp(), 126l);
1830 cellScanner.advance();
1831 current = cellScanner.current();
1832 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1833 current.getRowLength(), row1, 0, row1.length));
1834 assertEquals(current.getTimestamp(), 125l);
1835 cellScanner.advance();
1836 current = cellScanner.current();
1837 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1838 current.getRowLength(), row1, 0, row1.length));
1839 assertEquals(current.getTimestamp(), 123l);
1840 cellScanner = next[1].cellScanner();
1841 cellScanner.advance();
1842 current = cellScanner.current();
1843 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1844 current.getRowLength(), row2, 0, row2.length));
1845
1846
1847 actiona = new PrivilegedExceptionAction<Void>() {
1848 public Void run() throws Exception {
1849 try {
1850 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1851 Delete d = new Delete(row1);
1852 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
1853 + TOPSECRET + "&" + SECRET+")"));
1854 d.deleteFamily(fam, 127l);
1855 table.delete(d);
1856 } catch (Throwable t) {
1857 throw new IOException(t);
1858 }
1859 return null;
1860 }
1861 };
1862 SUPERUSER.runAs(actiona);
1863 s = new Scan();
1864 s.setMaxVersions(5);
1865 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1866 scanner = table.getScanner(s);
1867 next = scanner.next(3);
1868 assertTrue(next.length == 2);
1869 cellScanner = next[0].cellScanner();
1870 cellScanner.advance();
1871 current = cellScanner.current();
1872 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1873 current.getRowLength(), row1, 0, row1.length));
1874 assertEquals(current.getTimestamp(), 125l);
1875 cellScanner.advance();
1876 current = cellScanner.current();
1877 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1878 current.getRowLength(), row1, 0, row1.length));
1879 assertEquals(current.getTimestamp(), 123l);
1880 cellScanner = next[1].cellScanner();
1881 cellScanner.advance();
1882 current = cellScanner.current();
1883 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1884 current.getRowLength(), row2, 0, row2.length));
1885 assertEquals(current.getTimestamp(), 127l);
1886 } finally {
1887 if (table != null) {
1888 table.close();
1889 }
1890 }
1891 }
1892
1893 @Test
1894 public void testMultipleDeleteFamilyVersionWithDiffLabels() throws Exception {
1895 PrivilegedExceptionAction<VisibilityLabelsResponse> action =
1896 new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
1897 public VisibilityLabelsResponse run() throws Exception {
1898 try {
1899 return VisibilityClient.setAuths(conf, new String[] { CONFIDENTIAL, PRIVATE, SECRET },
1900 SUPERUSER.getShortName());
1901 } catch (Throwable e) {
1902 }
1903 return null;
1904 }
1905 };
1906 VisibilityLabelsResponse response = SUPERUSER.runAs(action);
1907 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1908 HTable table = doPuts(tableName);
1909 try {
1910 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1911 public Void run() throws Exception {
1912 try {
1913 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1914 Delete d = new Delete(row1);
1915 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
1916 d.deleteFamilyVersion(fam, 123l);
1917 table.delete(d);
1918 d = new Delete(row1);
1919 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
1920 d.deleteFamilyVersion(fam, 125l);
1921 table.delete(d);
1922 } catch (Throwable t) {
1923 throw new IOException(t);
1924 }
1925 return null;
1926 }
1927 };
1928 SUPERUSER.runAs(actiona);
1929
1930 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1931 Scan s = new Scan();
1932 s.setMaxVersions(5);
1933 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1934 ResultScanner scanner = table.getScanner(s);
1935 Result[] next = scanner.next(5);
1936 assertTrue(next.length == 2);
1937 CellScanner cellScanner = next[0].cellScanner();
1938 cellScanner.advance();
1939 Cell current = cellScanner.current();
1940 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1941 current.getRowLength(), row1, 0, row1.length));
1942 assertEquals(current.getTimestamp(), 127l);
1943 cellScanner.advance();
1944 current = cellScanner.current();
1945 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1946 current.getRowLength(), row1, 0, row1.length));
1947 assertEquals(current.getTimestamp(), 126l);
1948 cellScanner.advance();
1949 current = cellScanner.current();
1950 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1951 current.getRowLength(), row1, 0, row1.length));
1952 assertEquals(current.getTimestamp(), 124l);
1953 } finally {
1954 if (table != null) {
1955 table.close();
1956 }
1957 }
1958 }
1959
1960 @Test (timeout=180000)
1961 public void testSpecificDeletesFollowedByDeleteFamily() throws Exception {
1962 setAuths();
1963 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
1964 HTable table = doPuts(tableName);
1965 try {
1966 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
1967 public Void run() throws Exception {
1968 try {
1969 HTable table = new HTable(conf, TEST_NAME.getMethodName());
1970 Delete d = new Delete(row1);
1971 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
1972 + TOPSECRET + "&" + SECRET + ")"));
1973 d.deleteColumn(fam, qual, 126l);
1974 table.delete(d);
1975 d = new Delete(row1);
1976 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
1977 d.deleteFamilyVersion(fam, 125l);
1978 table.delete(d);
1979 } catch (Throwable t) {
1980 throw new IOException(t);
1981 }
1982 return null;
1983 }
1984 };
1985 SUPERUSER.runAs(actiona);
1986
1987 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
1988 Scan s = new Scan();
1989 s.setMaxVersions(5);
1990 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
1991 ResultScanner scanner = table.getScanner(s);
1992 Result[] next = scanner.next(5);
1993 assertTrue(next.length == 2);
1994 CellScanner cellScanner = next[0].cellScanner();
1995 cellScanner.advance();
1996 Cell current = cellScanner.current();
1997 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
1998 current.getRowLength(), row1, 0, row1.length));
1999 assertEquals(current.getTimestamp(), 127l);
2000 cellScanner.advance();
2001 current = cellScanner.current();
2002 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2003 current.getRowLength(), row1, 0, row1.length));
2004 assertEquals(current.getTimestamp(), 124l);
2005 cellScanner.advance();
2006 current = cellScanner.current();
2007 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2008 current.getRowLength(), row1, 0, row1.length));
2009 assertEquals(current.getTimestamp(), 123l);
2010
2011 actiona = new PrivilegedExceptionAction<Void>() {
2012 public Void run() throws Exception {
2013 try {
2014 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2015 Delete d = new Delete(row1);
2016 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
2017 d.deleteFamily(fam);
2018 table.delete(d);
2019 } catch (Throwable t) {
2020 throw new IOException(t);
2021 }
2022 return null;
2023 }
2024 };
2025 SUPERUSER.runAs(actiona);
2026 s = new Scan();
2027 s.setMaxVersions(5);
2028 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2029 scanner = table.getScanner(s);
2030 next = scanner.next(5);
2031 assertTrue(next.length == 2);
2032 cellScanner = next[0].cellScanner();
2033 cellScanner.advance();
2034 current = cellScanner.current();
2035 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2036 current.getRowLength(), row1, 0, row1.length));
2037 assertEquals(current.getTimestamp(), 127l);
2038 cellScanner.advance();
2039 current = cellScanner.current();
2040 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2041 current.getRowLength(), row1, 0, row1.length));
2042 assertEquals(current.getTimestamp(), 124l);
2043 } finally {
2044 if (table != null) {
2045 table.close();
2046 }
2047 }
2048 }
2049
2050 @Test(timeout = 180000)
2051 public void testSpecificDeletesFollowedByDeleteFamily1() throws Exception {
2052 PrivilegedExceptionAction<VisibilityLabelsResponse> action =
2053 new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
2054 public VisibilityLabelsResponse run() throws Exception {
2055 try {
2056 return VisibilityClient.setAuths(conf, new String[] { CONFIDENTIAL, PRIVATE, SECRET },
2057 SUPERUSER.getShortName());
2058 } catch (Throwable e) {
2059 }
2060 return null;
2061 }
2062 };
2063 VisibilityLabelsResponse response = SUPERUSER.runAs(action);
2064 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2065 HTable table = doPuts(tableName);
2066 try {
2067 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2068 public Void run() throws Exception {
2069 try {
2070 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2071 Delete d = new Delete(row1);
2072 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
2073 + TOPSECRET + "&" + SECRET + ")"));
2074 d.deleteColumn(fam, qual);
2075 table.delete(d);
2076
2077 d = new Delete(row1);
2078 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
2079 d.deleteFamilyVersion(fam, 125l);
2080 table.delete(d);
2081 } catch (Throwable t) {
2082 throw new IOException(t);
2083 }
2084 return null;
2085 }
2086 };
2087 SUPERUSER.runAs(actiona);
2088
2089 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2090 Scan s = new Scan();
2091 s.setMaxVersions(5);
2092 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2093 ResultScanner scanner = table.getScanner(s);
2094 Result[] next = scanner.next(5);
2095 assertTrue(next.length == 2);
2096 CellScanner cellScanner = next[0].cellScanner();
2097 cellScanner.advance();
2098 Cell current = cellScanner.current();
2099 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2100 current.getRowLength(), row1, 0, row1.length));
2101 assertEquals(current.getTimestamp(), 126l);
2102 cellScanner.advance();
2103 current = cellScanner.current();
2104 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2105 current.getRowLength(), row1, 0, row1.length));
2106 assertEquals(current.getTimestamp(), 124l);
2107 cellScanner.advance();
2108 current = cellScanner.current();
2109 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2110 current.getRowLength(), row1, 0, row1.length));
2111 assertEquals(current.getTimestamp(), 123l);
2112
2113 actiona = new PrivilegedExceptionAction<Void>() {
2114 public Void run() throws Exception {
2115 try {
2116 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2117 Delete d = new Delete(row1);
2118 d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
2119 d.deleteFamily(fam);
2120 table.delete(d);
2121 } catch (Throwable t) {
2122 throw new IOException(t);
2123 }
2124 return null;
2125 }
2126 };
2127 SUPERUSER.runAs(actiona);
2128 s = new Scan();
2129 s.setMaxVersions(5);
2130 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2131 scanner = table.getScanner(s);
2132 next = scanner.next(5);
2133 assertTrue(next.length == 2);
2134 cellScanner = next[0].cellScanner();
2135 cellScanner.advance();
2136 current = cellScanner.current();
2137 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2138 current.getRowLength(), row1, 0, row1.length));
2139 assertEquals(current.getTimestamp(), 126l);
2140 cellScanner.advance();
2141 current = cellScanner.current();
2142 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2143 current.getRowLength(), row1, 0, row1.length));
2144 assertEquals(current.getTimestamp(), 124l);
2145
2146 } finally {
2147 if (table != null) {
2148 table.close();
2149 }
2150 }
2151 }
2152
2153 @Test
2154 public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception {
2155 setAuths();
2156 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2157 HTable table = null;
2158 try {
2159
2160 table = doPuts(tableName);
2161 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2162 public Void run() throws Exception {
2163 try {
2164 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2165 Delete d = new Delete(row1);
2166 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
2167 d.deleteColumn(fam, qual, 125l);
2168 table.delete(d);
2169 } catch (Throwable t) {
2170 throw new IOException(t);
2171 }
2172 return null;
2173 }
2174 };
2175 SUPERUSER.runAs(actiona);
2176
2177 Scan s = new Scan();
2178 s.setMaxVersions(5);
2179 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2180 ResultScanner scanner = table.getScanner(s);
2181 Result[] next = scanner.next(3);
2182 assertTrue(next.length == 2);
2183 CellScanner cellScanner = next[0].cellScanner();
2184 cellScanner.advance();
2185 Cell current = cellScanner.current();
2186 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2187 current.getRowLength(), row1, 0, row1.length));
2188 assertEquals(current.getTimestamp(), 127l);
2189 cellScanner.advance();
2190 current = cellScanner.current();
2191 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2192 current.getRowLength(), row1, 0, row1.length));
2193 assertEquals(current.getTimestamp(), 126l);
2194 cellScanner.advance();
2195 current = cellScanner.current();
2196 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2197 current.getRowLength(), row1, 0, row1.length));
2198 assertEquals(current.getTimestamp(), 124l);
2199 cellScanner.advance();
2200 current = cellScanner.current();
2201 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2202 current.getRowLength(), row1, 0, row1.length));
2203 assertEquals(current.getTimestamp(), 123l);
2204 cellScanner = next[1].cellScanner();
2205 cellScanner.advance();
2206 current = cellScanner.current();
2207 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2208 current.getRowLength(), row2, 0, row2.length));
2209
2210
2211 actiona = new PrivilegedExceptionAction<Void>() {
2212 public Void run() throws Exception {
2213 try {
2214 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2215 Delete d = new Delete(row1);
2216 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
2217 + TOPSECRET + "&" + SECRET+")"));
2218 d.deleteColumn(fam, qual, 127l);
2219 table.delete(d);
2220 } catch (Throwable t) {
2221 throw new IOException(t);
2222 }
2223 return null;
2224 }
2225 };
2226 SUPERUSER.runAs(actiona);
2227 s = new Scan();
2228 s.setMaxVersions(5);
2229 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2230 scanner = table.getScanner(s);
2231 next = scanner.next(3);
2232 assertTrue(next.length == 2);
2233 cellScanner = next[0].cellScanner();
2234 cellScanner.advance();
2235 current = cellScanner.current();
2236 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2237 current.getRowLength(), row1, 0, row1.length));
2238 assertEquals(current.getTimestamp(), 126l);
2239 cellScanner.advance();
2240 current = cellScanner.current();
2241 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2242 current.getRowLength(), row1, 0, row1.length));
2243 assertEquals(current.getTimestamp(), 124l);
2244 cellScanner.advance();
2245 current = cellScanner.current();
2246 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2247 current.getRowLength(), row1, 0, row1.length));
2248 assertEquals(current.getTimestamp(), 123l);
2249 cellScanner = next[1].cellScanner();
2250 cellScanner.advance();
2251 current = cellScanner.current();
2252 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2253 current.getRowLength(), row2, 0, row2.length));
2254 assertEquals(current.getTimestamp(), 127l);
2255 } finally {
2256 if (table != null) {
2257 table.close();
2258 }
2259 }
2260 }
2261
2262 @Test
2263 public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice1() throws Exception {
2264 setAuths();
2265 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2266 HTable table = null;
2267 try {
2268
2269 table = doPuts(tableName);
2270 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2271 public Void run() throws Exception {
2272 try {
2273 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2274 Delete d = new Delete(row1);
2275 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")" +
2276 "|(" + TOPSECRET + "&" + SECRET + ")"));
2277 d.deleteColumn(fam, qual, 127l);
2278 table.delete(d);
2279 } catch (Throwable t) {
2280 throw new IOException(t);
2281 }
2282 return null;
2283 }
2284 };
2285 SUPERUSER.runAs(actiona);
2286
2287 Scan s = new Scan();
2288 s.setMaxVersions(5);
2289 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2290 ResultScanner scanner = table.getScanner(s);
2291 Result[] next = scanner.next(3);
2292 assertTrue(next.length == 2);
2293 CellScanner cellScanner = next[0].cellScanner();
2294 cellScanner.advance();
2295 Cell current = cellScanner.current();
2296 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2297 current.getRowLength(), row1, 0, row1.length));
2298 assertEquals(current.getTimestamp(), 126l);
2299 cellScanner.advance();
2300 current = cellScanner.current();
2301 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2302 current.getRowLength(), row1, 0, row1.length));
2303 assertEquals(current.getTimestamp(), 125l);
2304 cellScanner.advance();
2305 current = cellScanner.current();
2306 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2307 current.getRowLength(), row1, 0, row1.length));
2308 assertEquals(current.getTimestamp(), 124l);
2309 cellScanner.advance();
2310 current = cellScanner.current();
2311 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2312 current.getRowLength(), row1, 0, row1.length));
2313 assertEquals(current.getTimestamp(), 123l);
2314 cellScanner = next[1].cellScanner();
2315 cellScanner.advance();
2316 current = cellScanner.current();
2317 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2318 current.getRowLength(), row2, 0, row2.length));
2319
2320
2321 actiona = new PrivilegedExceptionAction<Void>() {
2322 public Void run() throws Exception {
2323 try {
2324 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2325 Delete d = new Delete(row1);
2326 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
2327 d.deleteColumn(fam, qual, 127l);
2328 table.delete(d);
2329 } catch (Throwable t) {
2330 throw new IOException(t);
2331 }
2332 return null;
2333 }
2334 };
2335 SUPERUSER.runAs(actiona);
2336 s = new Scan();
2337 s.setMaxVersions(5);
2338 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2339 scanner = table.getScanner(s);
2340 next = scanner.next(3);
2341 assertTrue(next.length == 2);
2342 cellScanner = next[0].cellScanner();
2343 cellScanner.advance();
2344 current = cellScanner.current();
2345 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2346 current.getRowLength(), row1, 0, row1.length));
2347 assertEquals(current.getTimestamp(), 126l);
2348 cellScanner.advance();
2349 current = cellScanner.current();
2350 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2351 current.getRowLength(), row1, 0, row1.length));
2352 assertEquals(current.getTimestamp(), 125l);
2353 cellScanner.advance();
2354 current = cellScanner.current();
2355 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2356 current.getRowLength(), row1, 0, row1.length));
2357 assertEquals(current.getTimestamp(), 124l);
2358 cellScanner.advance();
2359 current = cellScanner.current();
2360 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2361 current.getRowLength(), row1, 0, row1.length));
2362 assertEquals(current.getTimestamp(), 123l);
2363 cellScanner = next[1].cellScanner();
2364 cellScanner.advance();
2365 current = cellScanner.current();
2366 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2367 current.getRowLength(), row2, 0, row2.length));
2368 assertEquals(current.getTimestamp(), 127l);
2369 } finally {
2370 if (table != null) {
2371 table.close();
2372 }
2373 }
2374 }
2375 @Test
2376 public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice2() throws Exception {
2377 setAuths();
2378 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2379 HTable table = null;
2380 try {
2381
2382 table = doPuts(tableName);
2383 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2384 public Void run() throws Exception {
2385 try {
2386 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2387 Delete d = new Delete(row1);
2388 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
2389 + TOPSECRET + "&" + SECRET+")"));
2390 d.deleteColumn(fam, qual, 125l);
2391 table.delete(d);
2392 } catch (Throwable t) {
2393 throw new IOException(t);
2394 }
2395 return null;
2396 }
2397 };
2398 SUPERUSER.runAs(actiona);
2399
2400 Scan s = new Scan();
2401 s.setMaxVersions(5);
2402 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2403 ResultScanner scanner = table.getScanner(s);
2404 Result[] next = scanner.next(3);
2405 assertTrue(next.length == 2);
2406 CellScanner cellScanner = next[0].cellScanner();
2407 cellScanner.advance();
2408 Cell current = cellScanner.current();
2409 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2410 current.getRowLength(), row1, 0, row1.length));
2411 assertEquals(current.getTimestamp(), 127l);
2412 cellScanner.advance();
2413 current = cellScanner.current();
2414 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2415 current.getRowLength(), row1, 0, row1.length));
2416 assertEquals(current.getTimestamp(), 126l);
2417 cellScanner.advance();
2418 current = cellScanner.current();
2419 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2420 current.getRowLength(), row1, 0, row1.length));
2421 assertEquals(current.getTimestamp(), 125l);
2422 cellScanner.advance();
2423 current = cellScanner.current();
2424 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2425 current.getRowLength(), row1, 0, row1.length));
2426 assertEquals(current.getTimestamp(), 124l);
2427 cellScanner.advance();
2428 current = cellScanner.current();
2429 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2430 current.getRowLength(), row1, 0, row1.length));
2431 assertEquals(current.getTimestamp(), 123l);
2432 cellScanner = next[1].cellScanner();
2433 cellScanner.advance();
2434 current = cellScanner.current();
2435 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2436 current.getRowLength(), row2, 0, row2.length));
2437
2438
2439 actiona = new PrivilegedExceptionAction<Void>() {
2440 public Void run() throws Exception {
2441 try {
2442 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2443 Delete d = new Delete(row1);
2444 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
2445 + TOPSECRET + "&" + SECRET+")"));
2446 d.deleteColumn(fam, qual, 127l);
2447 table.delete(d);
2448 } catch (Throwable t) {
2449 throw new IOException(t);
2450 }
2451 return null;
2452 }
2453 };
2454 SUPERUSER.runAs(actiona);
2455 s = new Scan();
2456 s.setMaxVersions(5);
2457 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2458 scanner = table.getScanner(s);
2459 next = scanner.next(3);
2460 assertTrue(next.length == 2);
2461 cellScanner = next[0].cellScanner();
2462 cellScanner.advance();
2463 current = cellScanner.current();
2464 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2465 current.getRowLength(), row1, 0, row1.length));
2466 assertEquals(current.getTimestamp(), 126l);
2467 cellScanner.advance();
2468 current = cellScanner.current();
2469 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2470 current.getRowLength(), row1, 0, row1.length));
2471 assertEquals(current.getTimestamp(), 125l);
2472 cellScanner.advance();
2473 current = cellScanner.current();
2474 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2475 current.getRowLength(), row1, 0, row1.length));
2476 assertEquals(current.getTimestamp(), 124l);
2477 cellScanner.advance();
2478 current = cellScanner.current();
2479 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2480 current.getRowLength(), row1, 0, row1.length));
2481 assertEquals(current.getTimestamp(), 123l);
2482 cellScanner = next[1].cellScanner();
2483 cellScanner.advance();
2484 current = cellScanner.current();
2485 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2486 current.getRowLength(), row2, 0, row2.length));
2487 assertEquals(current.getTimestamp(), 127l);
2488 } finally {
2489 if (table != null) {
2490 table.close();
2491 }
2492 }
2493 }
2494 @Test
2495 public void testDeleteColumnAndDeleteFamilylSpecificTimeStampWithMulipleVersion()
2496 throws Exception {
2497 setAuths();
2498 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2499 HTable table = null;
2500 try {
2501
2502 table = doPuts(tableName);
2503 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2504 public Void run() throws Exception {
2505 try {
2506 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2507 Delete d = new Delete(row1);
2508 d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
2509 d.deleteColumn(fam, qual, 125l);
2510 table.delete(d);
2511 } catch (Throwable t) {
2512 throw new IOException(t);
2513 }
2514 return null;
2515 }
2516 };
2517 SUPERUSER.runAs(actiona);
2518
2519 Scan s = new Scan();
2520 s.setMaxVersions(5);
2521 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2522 ResultScanner scanner = table.getScanner(s);
2523 Result[] next = scanner.next(3);
2524 assertTrue(next.length == 2);
2525 CellScanner cellScanner = next[0].cellScanner();
2526 cellScanner.advance();
2527 Cell current = cellScanner.current();
2528 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2529 current.getRowLength(), row1, 0, row1.length));
2530 assertEquals(current.getTimestamp(), 127l);
2531 cellScanner.advance();
2532 current = cellScanner.current();
2533 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2534 current.getRowLength(), row1, 0, row1.length));
2535 assertEquals(current.getTimestamp(), 126l);
2536 cellScanner.advance();
2537 current = cellScanner.current();
2538 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2539 current.getRowLength(), row1, 0, row1.length));
2540 assertEquals(current.getTimestamp(), 124l);
2541 cellScanner.advance();
2542 current = cellScanner.current();
2543 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2544 current.getRowLength(), row1, 0, row1.length));
2545 assertEquals(current.getTimestamp(), 123l);
2546 cellScanner = next[1].cellScanner();
2547 cellScanner.advance();
2548 current = cellScanner.current();
2549 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2550 current.getRowLength(), row2, 0, row2.length));
2551
2552
2553 actiona = new PrivilegedExceptionAction<Void>() {
2554 public Void run() throws Exception {
2555 try {
2556 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2557 Delete d = new Delete(row1);
2558 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
2559 + TOPSECRET + "&" + SECRET+")"));
2560 d.deleteFamily(fam, 124l);
2561 table.delete(d);
2562 } catch (Throwable t) {
2563 throw new IOException(t);
2564 }
2565 return null;
2566 }
2567 };
2568 SUPERUSER.runAs(actiona);
2569 s = new Scan();
2570 s.setMaxVersions(5);
2571 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2572 scanner = table.getScanner(s);
2573 next = scanner.next(3);
2574 assertTrue(next.length == 2);
2575 cellScanner = next[0].cellScanner();
2576 cellScanner.advance();
2577 current = cellScanner.current();
2578 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2579 current.getRowLength(), row1, 0, row1.length));
2580 assertEquals(current.getTimestamp(), 127l);
2581 cellScanner.advance();
2582 current = cellScanner.current();
2583 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2584 current.getRowLength(), row1, 0, row1.length));
2585 assertEquals(current.getTimestamp(), 126l);
2586 cellScanner = next[1].cellScanner();
2587 cellScanner.advance();
2588 current = cellScanner.current();
2589 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2590 current.getRowLength(), row2, 0, row2.length));
2591 assertEquals(current.getTimestamp(), 127l);
2592 } finally {
2593 if (table != null) {
2594 table.close();
2595 }
2596 }
2597 }
2598
2599 private void setAuths() throws IOException, InterruptedException {
2600 PrivilegedExceptionAction<VisibilityLabelsResponse> action =
2601 new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
2602 public VisibilityLabelsResponse run() throws Exception {
2603 try {
2604 return VisibilityClient.setAuths(conf, new String[] { CONFIDENTIAL, PRIVATE, SECRET,
2605 TOPSECRET }, SUPERUSER.getShortName());
2606 } catch (Throwable e) {
2607 }
2608 return null;
2609 }
2610 };
2611 SUPERUSER.runAs(action);
2612 }
2613
2614 @Test
2615 public void testDiffDeleteTypesForTheSameCellUsingMultipleVersions() throws Exception {
2616 setAuths();
2617 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2618 HTable table = null;
2619 try {
2620
2621 table = doPuts(tableName);
2622 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2623 public Void run() throws Exception {
2624 try {
2625 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2626 Delete d = new Delete(row1);
2627 d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
2628 + TOPSECRET + "&" + SECRET+")"));
2629 d.deleteColumns(fam, qual, 125l);
2630 table.delete(d);
2631 } catch (Throwable t) {
2632 throw new IOException(t);
2633 }
2634 return null;
2635 }
2636 };
2637 SUPERUSER.runAs(actiona);
2638
2639 Scan s = new Scan();
2640 s.setMaxVersions(5);
2641 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2642 ResultScanner scanner = table.getScanner(s);
2643 Result[] next = scanner.next(3);
2644 assertTrue(next.length == 2);
2645 CellScanner cellScanner = next[0].cellScanner();
2646 cellScanner.advance();
2647 Cell current = cellScanner.current();
2648 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2649 current.getRowLength(), row1, 0, row1.length));
2650 assertEquals(current.getTimestamp(), 127l);
2651 cellScanner.advance();
2652 current = cellScanner.current();
2653 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2654 current.getRowLength(), row1, 0, row1.length));
2655 assertEquals(current.getTimestamp(), 126l);
2656 cellScanner.advance();
2657 current = cellScanner.current();
2658 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2659 current.getRowLength(), row1, 0, row1.length));
2660 assertEquals(current.getTimestamp(), 125l);
2661 cellScanner.advance();
2662 current = cellScanner.current();
2663 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2664 current.getRowLength(), row1, 0, row1.length));
2665 assertEquals(current.getTimestamp(), 123l);
2666 cellScanner = next[1].cellScanner();
2667 cellScanner.advance();
2668 current = cellScanner.current();
2669 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2670 current.getRowLength(), row2, 0, row2.length));
2671
2672
2673 actiona = new PrivilegedExceptionAction<Void>() {
2674 public Void run() throws Exception {
2675 try {
2676 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2677 Delete d = new Delete(row1);
2678 d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
2679 + TOPSECRET + "&" + SECRET+")"));
2680 d.deleteColumn(fam, qual, 127l);
2681 table.delete(d);
2682 } catch (Throwable t) {
2683 throw new IOException(t);
2684 }
2685 return null;
2686 }
2687 };
2688 SUPERUSER.runAs(actiona);
2689 s = new Scan();
2690 s.setMaxVersions(5);
2691 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2692 scanner = table.getScanner(s);
2693 next = scanner.next(3);
2694 assertTrue(next.length == 2);
2695 cellScanner = next[0].cellScanner();
2696 cellScanner.advance();
2697 current = cellScanner.current();
2698 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2699 current.getRowLength(), row1, 0, row1.length));
2700 assertEquals(current.getTimestamp(), 126l);
2701 cellScanner.advance();
2702 current = cellScanner.current();
2703 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2704 current.getRowLength(), row1, 0, row1.length));
2705 assertEquals(current.getTimestamp(), 125l);
2706 cellScanner.advance();
2707 current = cellScanner.current();
2708 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2709 current.getRowLength(), row1, 0, row1.length));
2710 assertEquals(current.getTimestamp(), 123l);
2711 cellScanner = next[1].cellScanner();
2712 cellScanner.advance();
2713 current = cellScanner.current();
2714 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2715 current.getRowLength(), row2, 0, row2.length));
2716 } finally {
2717 if (table != null) {
2718 table.close();
2719 }
2720 }
2721 }
2722
2723 @Test
2724 public void testDeleteColumnLatestWithNoCellVisibility() throws Exception {
2725 setAuths();
2726 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2727 HTable table = null;
2728 try {
2729 table = doPuts(tableName);
2730 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2731 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2732 public Void run() throws Exception {
2733 try {
2734 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2735 Delete d = new Delete(row1);
2736 d.deleteColumn(fam, qual, 125l);
2737 table.delete(d);
2738 } catch (Throwable t) {
2739 throw new IOException(t);
2740 }
2741 return null;
2742 }
2743 };
2744 SUPERUSER.runAs(actiona);
2745
2746 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2747 Scan s = new Scan();
2748 s.setMaxVersions(5);
2749 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2750 ResultScanner scanner = table.getScanner(s);
2751 Result[] next = scanner.next(3);
2752 assertTrue(next.length == 2);
2753 scanAll(next);
2754 actiona = new PrivilegedExceptionAction<Void>() {
2755 public Void run() throws Exception {
2756 try {
2757 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2758 Delete d = new Delete(row1);
2759 d.deleteColumns(fam, qual, 125l);
2760 table.delete(d);
2761 } catch (Throwable t) {
2762 throw new IOException(t);
2763 }
2764 return null;
2765 }
2766 };
2767 SUPERUSER.runAs(actiona);
2768
2769 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2770 s = new Scan();
2771 s.setMaxVersions(5);
2772 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2773 scanner = table.getScanner(s);
2774 next = scanner.next(3);
2775 assertTrue(next.length == 2);
2776 scanAll(next);
2777
2778 actiona = new PrivilegedExceptionAction<Void>() {
2779 public Void run() throws Exception {
2780 try {
2781 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2782 Delete d = new Delete(row1);
2783 d.deleteFamily(fam, 125l);
2784 table.delete(d);
2785 } catch (Throwable t) {
2786 throw new IOException(t);
2787 }
2788 return null;
2789 }
2790 };
2791 SUPERUSER.runAs(actiona);
2792
2793 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2794 s = new Scan();
2795 s.setMaxVersions(5);
2796 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2797 scanner = table.getScanner(s);
2798 next = scanner.next(3);
2799 assertTrue(next.length == 2);
2800 scanAll(next);
2801
2802 actiona = new PrivilegedExceptionAction<Void>() {
2803 public Void run() throws Exception {
2804 try {
2805 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2806 Delete d = new Delete(row1);
2807 d.deleteFamily(fam);
2808 table.delete(d);
2809 } catch (Throwable t) {
2810 throw new IOException(t);
2811 }
2812 return null;
2813 }
2814 };
2815 SUPERUSER.runAs(actiona);
2816
2817 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2818 s = new Scan();
2819 s.setMaxVersions(5);
2820 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2821 scanner = table.getScanner(s);
2822 next = scanner.next(3);
2823 assertTrue(next.length == 2);
2824 scanAll(next);
2825
2826 actiona = new PrivilegedExceptionAction<Void>() {
2827 public Void run() throws Exception {
2828 try {
2829 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2830 Delete d = new Delete(row1);
2831 d.deleteColumns(fam, qual);
2832 table.delete(d);
2833 } catch (Throwable t) {
2834 throw new IOException(t);
2835 }
2836 return null;
2837 }
2838 };
2839 SUPERUSER.runAs(actiona);
2840
2841 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2842 s = new Scan();
2843 s.setMaxVersions(5);
2844 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2845 scanner = table.getScanner(s);
2846 next = scanner.next(3);
2847 assertTrue(next.length == 2);
2848 scanAll(next);
2849
2850 actiona = new PrivilegedExceptionAction<Void>() {
2851 public Void run() throws Exception {
2852 try {
2853 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2854 Delete d = new Delete(row1);
2855 d.deleteFamilyVersion(fam, 126l);
2856 table.delete(d);
2857 } catch (Throwable t) {
2858 throw new IOException(t);
2859 }
2860 return null;
2861 }
2862 };
2863 SUPERUSER.runAs(actiona);
2864
2865 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2866 s = new Scan();
2867 s.setMaxVersions(5);
2868 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2869 scanner = table.getScanner(s);
2870 next = scanner.next(3);
2871 assertTrue(next.length == 2);
2872 scanAll(next);
2873 } finally {
2874 if (table != null) {
2875 table.close();
2876 }
2877 }
2878 }
2879
2880 private void scanAll(Result[] next) throws IOException {
2881 CellScanner cellScanner = next[0].cellScanner();
2882 cellScanner.advance();
2883 Cell current = cellScanner.current();
2884 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
2885 row1, 0, row1.length));
2886 assertEquals(current.getTimestamp(), 127l);
2887 cellScanner.advance();
2888 current = cellScanner.current();
2889 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
2890 row1, 0, row1.length));
2891 assertEquals(current.getTimestamp(), 126l);
2892 cellScanner.advance();
2893 current = cellScanner.current();
2894 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
2895 row1, 0, row1.length));
2896 assertEquals(current.getTimestamp(), 125l);
2897 cellScanner.advance();
2898 current = cellScanner.current();
2899 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
2900 row1, 0, row1.length));
2901 assertEquals(current.getTimestamp(), 124l);
2902 cellScanner.advance();
2903 current = cellScanner.current();
2904 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
2905 row1, 0, row1.length));
2906 assertEquals(current.getTimestamp(), 123l);
2907 cellScanner = next[1].cellScanner();
2908 cellScanner.advance();
2909 current = cellScanner.current();
2910 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
2911 row2, 0, row2.length));
2912 }
2913
2914 @Test
2915 public void testVisibilityExpressionWithNotEqualORCondition() throws Exception {
2916 setAuths();
2917 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2918 HTable table = null;
2919 try {
2920 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
2921 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
2922 colDesc.setMaxVersions(5);
2923 HTableDescriptor desc = new HTableDescriptor(tableName);
2924 desc.addFamily(colDesc);
2925 hBaseAdmin.createTable(desc);
2926 table = new HTable(conf, tableName);
2927 Put put = new Put(Bytes.toBytes("row1"));
2928 put.add(fam, qual, 123l, value);
2929 put.setCellVisibility(new CellVisibility(CONFIDENTIAL));
2930 table.put(put);
2931 put = new Put(Bytes.toBytes("row1"));
2932 put.add(fam, qual, 124l, value);
2933 put.setCellVisibility(new CellVisibility(CONFIDENTIAL + "|" + PRIVATE));
2934 table.put(put);
2935 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2936 PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
2937 public Void run() throws Exception {
2938 try {
2939 HTable table = new HTable(conf, TEST_NAME.getMethodName());
2940 Delete d = new Delete(row1);
2941 d.deleteColumn(fam, qual, 124l);
2942 d.setCellVisibility(new CellVisibility(PRIVATE ));
2943 table.delete(d);
2944 } catch (Throwable t) {
2945 throw new IOException(t);
2946 }
2947 return null;
2948 }
2949 };
2950 SUPERUSER.runAs(actiona);
2951
2952 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
2953 Scan s = new Scan();
2954 s.setMaxVersions(5);
2955 s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
2956 ResultScanner scanner = table.getScanner(s);
2957 Result[] next = scanner.next(3);
2958 assertTrue(next.length == 1);
2959 CellScanner cellScanner = next[0].cellScanner();
2960 cellScanner.advance();
2961 Cell current = cellScanner.current();
2962 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2963 current.getRowLength(), row1, 0, row1.length));
2964 assertEquals(current.getTimestamp(), 124l);
2965 cellScanner.advance();
2966 current = cellScanner.current();
2967 assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
2968 current.getRowLength(), row1, 0, row1.length));
2969 assertEquals(current.getTimestamp(), 123l);
2970 } finally {
2971 if (table != null) {
2972 table.close();
2973 }
2974 }
2975 }
2976
2977 @Test
2978 public void testDeleteWithNoVisibilitiesForPutsAndDeletes() throws Exception {
2979 final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
2980 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
2981 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
2982 colDesc.setMaxVersions(5);
2983 HTableDescriptor desc = new HTableDescriptor(tableName);
2984 desc.addFamily(colDesc);
2985 hBaseAdmin.createTable(desc);
2986 HTable table = new HTable(conf, tableName);
2987 try {
2988 Put p = new Put(Bytes.toBytes("row1"));
2989 p.add(fam, qual, value);
2990 table.put(p);
2991 p = new Put(Bytes.toBytes("row1"));
2992 p.add(fam, qual1, value);
2993 table.put(p);
2994 p = new Put(Bytes.toBytes("row2"));
2995 p.add(fam, qual, value);
2996 table.put(p);
2997 p = new Put(Bytes.toBytes("row2"));
2998 p.add(fam, qual1, value);
2999 table.put(p);
3000 Delete d = new Delete(Bytes.toBytes("row1"));
3001 table.delete(d);
3002 Get g = new Get(Bytes.toBytes("row1"));
3003 g.setMaxVersions();
3004 g.setAuthorizations(new Authorizations(SECRET, PRIVATE));
3005 Result result = table.get(g);
3006 assertEquals(0, result.rawCells().length);
3007
3008 p = new Put(Bytes.toBytes("row1"));
3009 p.add(fam, qual, value);
3010 table.put(p);
3011 result = table.get(g);
3012 assertEquals(1, result.rawCells().length);
3013 } finally {
3014 table.close();
3015 }
3016 }
3017
3018 @Test
3019 public void testDeleteWithFamilyDeletesOfSameTsButDifferentVisibilities() throws Exception {
3020 final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
3021 HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
3022 HColumnDescriptor colDesc = new HColumnDescriptor(fam);
3023 colDesc.setMaxVersions(5);
3024 HTableDescriptor desc = new HTableDescriptor(tableName);
3025 desc.addFamily(colDesc);
3026 hBaseAdmin.createTable(desc);
3027 HTable table = new HTable(conf, tableName);
3028 long t1 = 1234L;
3029 CellVisibility cellVisibility1 = new CellVisibility(SECRET);
3030 CellVisibility cellVisibility2 = new CellVisibility(PRIVATE);
3031 try {
3032
3033 Put p = new Put(row1);
3034 p.add(fam, qual, t1, value);
3035 p.setCellVisibility(cellVisibility1);
3036 table.put(p);
3037
3038
3039 p = new Put(row1);
3040 p.add(fam, qual1, t1, value);
3041 p.setCellVisibility(cellVisibility2);
3042 table.put(p);
3043
3044 Delete d = new Delete(row1);
3045 d.deleteFamily(fam, t1);
3046 d.setCellVisibility(cellVisibility2);
3047 table.delete(d);
3048 d = new Delete(row1);
3049 d.deleteFamily(fam, t1);
3050 d.setCellVisibility(cellVisibility1);
3051 table.delete(d);
3052
3053 Get g = new Get(row1);
3054 g.setMaxVersions();
3055 g.setAuthorizations(new Authorizations(SECRET, PRIVATE));
3056 Result result = table.get(g);
3057 assertEquals(0, result.rawCells().length);
3058
3059
3060 p = new Put(row2);
3061 p.add(fam, qual, t1, value);
3062 p.setCellVisibility(cellVisibility1);
3063 table.put(p);
3064
3065
3066 p = new Put(row2);
3067 p.add(fam, qual1, t1, value);
3068 p.setCellVisibility(cellVisibility2);
3069 table.put(p);
3070
3071 d = new Delete(row2);
3072 d.deleteFamilyVersion(fam, t1);
3073 d.setCellVisibility(cellVisibility2);
3074 table.delete(d);
3075 d = new Delete(row2);
3076 d.deleteFamilyVersion(fam, t1);
3077 d.setCellVisibility(cellVisibility1);
3078 table.delete(d);
3079
3080 g = new Get(row2);
3081 g.setMaxVersions();
3082 g.setAuthorizations(new Authorizations(SECRET, PRIVATE));
3083 result = table.get(g);
3084 assertEquals(0, result.rawCells().length);
3085 } finally {
3086 table.close();
3087 }
3088 }
3089
3090 public static HTable createTableAndWriteDataWithLabels(TableName tableName, String... labelExps)
3091 throws Exception {
3092 HTable table = null;
3093 table = TEST_UTIL.createTable(tableName, fam);
3094 int i = 1;
3095 List<Put> puts = new ArrayList<Put>();
3096 for (String labelExp : labelExps) {
3097 Put put = new Put(Bytes.toBytes("row" + i));
3098 put.add(fam, qual, HConstants.LATEST_TIMESTAMP, value);
3099 put.setCellVisibility(new CellVisibility(labelExp));
3100 puts.add(put);
3101 table.put(put);
3102 i++;
3103 }
3104
3105 return table;
3106 }
3107
3108 public static HTable createTableAndWriteDataWithLabels(TableName tableName, long[] timestamp,
3109 String... labelExps) throws Exception {
3110 HTable table = null;
3111 table = TEST_UTIL.createTable(tableName, fam);
3112 int i = 1;
3113 List<Put> puts = new ArrayList<Put>();
3114 for (String labelExp : labelExps) {
3115 Put put = new Put(Bytes.toBytes("row" + i));
3116 put.add(fam, qual, timestamp[i - 1], value);
3117 put.setCellVisibility(new CellVisibility(labelExp));
3118 puts.add(put);
3119 table.put(put);
3120 TEST_UTIL.getHBaseAdmin().flush(tableName.getNameAsString());
3121 i++;
3122 }
3123 return table;
3124 }
3125
3126 public static void addLabels() throws Exception {
3127 PrivilegedExceptionAction<VisibilityLabelsResponse> action =
3128 new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
3129 public VisibilityLabelsResponse run() throws Exception {
3130 String[] labels = { SECRET, TOPSECRET, CONFIDENTIAL, PUBLIC, PRIVATE };
3131 try {
3132 VisibilityClient.addLabels(conf, labels);
3133 } catch (Throwable t) {
3134 throw new IOException(t);
3135 }
3136 return null;
3137 }
3138 };
3139 SUPERUSER.runAs(action);
3140 }
3141 }