1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.hadoop.hbase.quotas;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.apache.hadoop.hbase.HRegionInfo;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.client.Connection;
29 import org.apache.hadoop.hbase.testclassification.SmallTests;
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
34
35 import com.google.common.collect.Iterables;
36
37
38
39
40 @Category(SmallTests.class)
41 public class TestQuotaObserverChore {
42 private Connection conn;
43 private QuotaObserverChore chore;
44
45 @Before
46 public void setup() throws Exception {
47 conn = mock(Connection.class);
48 chore = mock(QuotaObserverChore.class);
49 }
50
51 @Test
52 public void testNumRegionsForTable() {
53 TableName tn1 = TableName.valueOf("t1");
54 TableName tn2 = TableName.valueOf("t2");
55 TableName tn3 = TableName.valueOf("t3");
56
57 final int numTable1Regions = 10;
58 final int numTable2Regions = 15;
59 final int numTable3Regions = 8;
60 Map<HRegionInfo,Long> regionReports = new HashMap<>();
61 for (int i = 0; i < numTable1Regions; i++) {
62 regionReports.put(new HRegionInfo(tn1, Bytes.toBytes(i), Bytes.toBytes(i + 1)), 0L);
63 }
64
65 for (int i = 0; i < numTable2Regions; i++) {
66 regionReports.put(new HRegionInfo(tn2, Bytes.toBytes(i), Bytes.toBytes(i + 1)), 0L);
67 }
68
69 for (int i = 0; i < numTable3Regions; i++) {
70 regionReports.put(new HRegionInfo(tn3, Bytes.toBytes(i), Bytes.toBytes(i + 1)), 0L);
71 }
72
73 TableQuotaSnapshotStore store = new TableQuotaSnapshotStore(conn, chore, regionReports);
74 when(chore.getTableSnapshotStore()).thenReturn(store);
75
76 assertEquals(numTable1Regions, Iterables.size(store.filterBySubject(tn1)));
77 assertEquals(numTable2Regions, Iterables.size(store.filterBySubject(tn2)));
78 assertEquals(numTable3Regions, Iterables.size(store.filterBySubject(tn3)));
79 }
80 }