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;
19  
20  import static org.apache.hadoop.hbase.hbtop.Record.entry;
21  import static org.hamcrest.CoreMatchers.is;
22  import static org.junit.Assert.assertThat;
23  
24  import org.apache.hadoop.hbase.hbtop.field.Field;
25  import org.apache.hadoop.hbase.testclassification.SmallTests;
26  import org.junit.Test;
27  import org.junit.experimental.categories.Category;
28  
29  @Category(SmallTests.class)
30  public class TestRecord {
31  
32    @Test
33    public void testBuilder() {
34      Record actual1 = Record.builder().put(Field.TABLE, "tableName")
35        .put(entry(Field.REGION_COUNT, 3))
36        .put(Field.REQUEST_COUNT_PER_SECOND, Field.REQUEST_COUNT_PER_SECOND.newValue(100L))
37        .build();
38  
39      assertThat(actual1.size(), is(3));
40      assertThat(actual1.get(Field.TABLE).asString(), is("tableName"));
41      assertThat(actual1.get(Field.REGION_COUNT).asInt(), is(3));
42      assertThat(actual1.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
43  
44      Record actual2 = Record.builder().putAll(actual1).build();
45  
46      assertThat(actual2.size(), is(3));
47      assertThat(actual2.get(Field.TABLE).asString(), is("tableName"));
48      assertThat(actual2.get(Field.REGION_COUNT).asInt(), is(3));
49      assertThat(actual2.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
50    }
51  
52    @Test
53    public void testOfEntries() {
54      Record actual = Record.ofEntries(
55        entry(Field.TABLE, "tableName"),
56        entry(Field.REGION_COUNT, 3),
57        entry(Field.REQUEST_COUNT_PER_SECOND, 100L)
58      );
59  
60      assertThat(actual.size(), is(3));
61      assertThat(actual.get(Field.TABLE).asString(), is("tableName"));
62      assertThat(actual.get(Field.REGION_COUNT).asInt(), is(3));
63      assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
64    }
65  
66    @Test
67    public void testCombine() {
68      Record record1 = Record.ofEntries(
69        entry(Field.TABLE, "tableName"),
70        entry(Field.REGION_COUNT, 3),
71        entry(Field.REQUEST_COUNT_PER_SECOND, 100L)
72      );
73  
74      Record record2 = Record.ofEntries(
75        entry(Field.TABLE, "tableName"),
76        entry(Field.REGION_COUNT, 5),
77        entry(Field.REQUEST_COUNT_PER_SECOND, 500L)
78      );
79  
80      Record actual = record1.combine(record2);
81  
82      assertThat(actual.size(), is(3));
83      assertThat(actual.get(Field.TABLE).asString(), is("tableName"));
84      assertThat(actual.get(Field.REGION_COUNT).asInt(), is(8));
85      assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(600L));
86    }
87  }