1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.client;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.*;
26 import org.apache.hadoop.hbase.util.Bytes;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32 import static org.mockito.Mockito.*;
33
34 @Category(MediumTests.class)
35 public class TestMetaScanner {
36 final Log LOG = LogFactory.getLog(getClass());
37 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
38
39 @BeforeClass
40 public static void setUpBeforeClass() throws Exception {
41 TEST_UTIL.startMiniCluster(1);
42 }
43
44
45
46
47 @AfterClass
48 public static void tearDownAfterClass() throws Exception {
49 TEST_UTIL.shutdownMiniCluster();
50 }
51
52 @Test
53 public void testMetaScanner() throws Exception {
54 LOG.info("Starting testMetaScanner");
55 final byte[] TABLENAME = Bytes.toBytes("testMetaScanner");
56 final byte[] FAMILY = Bytes.toBytes("family");
57 TEST_UTIL.createTable(TABLENAME, FAMILY);
58 Configuration conf = TEST_UTIL.getConfiguration();
59 HTable table = new HTable(conf, TABLENAME);
60 TEST_UTIL.createMultiRegions(conf, table, FAMILY,
61 new byte[][]{
62 HConstants.EMPTY_START_ROW,
63 Bytes.toBytes("region_a"),
64 Bytes.toBytes("region_b")});
65
66 TEST_UTIL.countRows(table);
67
68 MetaScanner.MetaScannerVisitor visitor =
69 mock(MetaScanner.MetaScannerVisitor.class);
70 doReturn(true).when(visitor).processRow((Result)anyObject());
71
72
73 MetaScanner.metaScan(conf, visitor, TABLENAME);
74 verify(visitor, times(3)).processRow((Result)anyObject());
75
76
77
78 reset(visitor);
79 doReturn(true).when(visitor).processRow((Result)anyObject());
80 MetaScanner.metaScan(conf, visitor, TABLENAME, HConstants.EMPTY_BYTE_ARRAY, 1000);
81 verify(visitor, times(3)).processRow((Result)anyObject());
82
83
84
85 reset(visitor);
86 doReturn(true).when(visitor).processRow((Result)anyObject());
87 MetaScanner.metaScan(conf, visitor, TABLENAME, Bytes.toBytes("region_ac"), 1000);
88 verify(visitor, times(2)).processRow((Result)anyObject());
89
90
91 reset(visitor);
92 doReturn(true).when(visitor).processRow((Result)anyObject());
93 MetaScanner.metaScan(conf, visitor, TABLENAME, Bytes.toBytes("region_ac"), 1);
94 verify(visitor, times(1)).processRow((Result)anyObject());
95 table.close();
96 }
97
98 @org.junit.Rule
99 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
100 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
101 }
102