View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.hbtop.mode;
19  
20  import static org.hamcrest.CoreMatchers.is;
21  import static org.junit.Assert.assertThat;
22  import static org.junit.Assert.fail;
23  
24  import java.util.List;
25  import org.apache.hadoop.hbase.hbtop.Record;
26  import org.apache.hadoop.hbase.hbtop.TestUtils;
27  import org.apache.hadoop.hbase.hbtop.field.Field;
28  import org.apache.hadoop.hbase.testclassification.SmallTests;
29  import org.junit.experimental.categories.Category;
30  
31  @Category(SmallTests.class)
32  public class TestTableMode extends TestModeBase {
33  
34    @Override
35    protected Mode getMode() {
36      return Mode.TABLE;
37    }
38  
39    @Override
40    protected void assertRecords(List<Record> records) {
41      TestUtils.assertRecordsInTableMode(records);
42    }
43  
44    @Override
45    protected void assertDrillDown(Record currentRecord, DrillDownInfo drillDownInfo) {
46      assertThat(drillDownInfo.getNextMode(), is(Mode.REGION));
47      assertThat(drillDownInfo.getInitialFilters().size(), is(2));
48  
49      String tableName = String.format("%s:%s", currentRecord.get(Field.NAMESPACE).asString(),
50        currentRecord.get(Field.TABLE).asString());
51  
52      switch (tableName) {
53        case "default:table1":
54          assertThat(drillDownInfo.getInitialFilters().get(0).toString(), is("NAMESPACE==default"));
55          assertThat(drillDownInfo.getInitialFilters().get(1).toString(), is("TABLE==table1"));
56          break;
57  
58        case "default:table2":
59          assertThat(drillDownInfo.getInitialFilters().get(0).toString(), is("NAMESPACE==default"));
60          assertThat(drillDownInfo.getInitialFilters().get(1).toString(), is("TABLE==table2"));
61          break;
62  
63        case "namespace:table3":
64          assertThat(drillDownInfo.getInitialFilters().get(0).toString(),
65            is("NAMESPACE==namespace"));
66          assertThat(drillDownInfo.getInitialFilters().get(1).toString(), is("TABLE==table3"));
67          break;
68  
69        default:
70          fail();
71      }
72    }
73  }