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