1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }