001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.hbtop;
019
020import static org.apache.hadoop.hbase.hbtop.Record.entry;
021import static org.hamcrest.CoreMatchers.is;
022import static org.junit.Assert.assertThat;
023
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.hbtop.field.Field;
026import org.apache.hadoop.hbase.testclassification.SmallTests;
027import org.junit.ClassRule;
028import org.junit.Test;
029import org.junit.experimental.categories.Category;
030
031
032@Category(SmallTests.class)
033public class RecordTest {
034
035  @ClassRule
036  public static final HBaseClassTestRule CLASS_RULE =
037    HBaseClassTestRule.forClass(RecordTest.class);
038
039  @Test
040  public void testBuilder() {
041    Record actual1 = Record.builder().put(Field.TABLE, "tableName")
042      .put(entry(Field.REGION_COUNT, 3))
043      .put(Field.REQUEST_COUNT_PER_SECOND, Field.REQUEST_COUNT_PER_SECOND.newValue(100L))
044      .build();
045
046    assertThat(actual1.size(), is(3));
047    assertThat(actual1.get(Field.TABLE).asString(), is("tableName"));
048    assertThat(actual1.get(Field.REGION_COUNT).asInt(), is(3));
049    assertThat(actual1.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
050
051    Record actual2 = Record.builder().putAll(actual1).build();
052
053    assertThat(actual2.size(), is(3));
054    assertThat(actual2.get(Field.TABLE).asString(), is("tableName"));
055    assertThat(actual2.get(Field.REGION_COUNT).asInt(), is(3));
056    assertThat(actual2.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
057  }
058
059  @Test
060  public void testOfEntries() {
061    Record actual = Record.ofEntries(
062      entry(Field.TABLE, "tableName"),
063      entry(Field.REGION_COUNT, 3),
064      entry(Field.REQUEST_COUNT_PER_SECOND, 100L)
065    );
066
067    assertThat(actual.size(), is(3));
068    assertThat(actual.get(Field.TABLE).asString(), is("tableName"));
069    assertThat(actual.get(Field.REGION_COUNT).asInt(), is(3));
070    assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
071  }
072
073  @Test
074  public void testCombine() {
075    Record record1 = Record.ofEntries(
076      entry(Field.TABLE, "tableName"),
077      entry(Field.REGION_COUNT, 3),
078      entry(Field.REQUEST_COUNT_PER_SECOND, 100L)
079    );
080
081    Record record2 = Record.ofEntries(
082      entry(Field.TABLE, "tableName"),
083      entry(Field.REGION_COUNT, 5),
084      entry(Field.REQUEST_COUNT_PER_SECOND, 500L)
085    );
086
087    Record actual = record1.combine(record2);
088
089    assertThat(actual.size(), is(3));
090    assertThat(actual.get(Field.TABLE).asString(), is("tableName"));
091    assertThat(actual.get(Field.REGION_COUNT).asInt(), is(8));
092    assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(600L));
093  }
094}