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.hamcrest.MatcherAssert.assertThat;
023
024import org.apache.hadoop.hbase.hbtop.field.Field;
025import org.apache.hadoop.hbase.testclassification.SmallTests;
026import org.junit.jupiter.api.Tag;
027import org.junit.jupiter.api.Test;
028
029@Tag(SmallTests.TAG)
030public class TestRecord {
031
032  @Test
033  public void testBuilder() {
034    Record actual1 =
035      Record.builder().put(Field.TABLE, "tableName").put(entry(Field.REGION_COUNT, 3))
036        .put(Field.REQUEST_COUNT_PER_SECOND, Field.REQUEST_COUNT_PER_SECOND.newValue(100L)).build();
037
038    assertThat(actual1.size(), is(3));
039    assertThat(actual1.get(Field.TABLE).asString(), is("tableName"));
040    assertThat(actual1.get(Field.REGION_COUNT).asInt(), is(3));
041    assertThat(actual1.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
042
043    Record actual2 = Record.builder().putAll(actual1).build();
044
045    assertThat(actual2.size(), is(3));
046    assertThat(actual2.get(Field.TABLE).asString(), is("tableName"));
047    assertThat(actual2.get(Field.REGION_COUNT).asInt(), is(3));
048    assertThat(actual2.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
049  }
050
051  @Test
052  public void testOfEntries() {
053    Record actual = Record.ofEntries(entry(Field.TABLE, "tableName"), entry(Field.REGION_COUNT, 3),
054      entry(Field.REQUEST_COUNT_PER_SECOND, 100L));
055
056    assertThat(actual.size(), is(3));
057    assertThat(actual.get(Field.TABLE).asString(), is("tableName"));
058    assertThat(actual.get(Field.REGION_COUNT).asInt(), is(3));
059    assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L));
060  }
061
062  @Test
063  public void testCombine() {
064    Record record1 = Record.ofEntries(entry(Field.TABLE, "tableName"), entry(Field.REGION_COUNT, 3),
065      entry(Field.REQUEST_COUNT_PER_SECOND, 100L));
066
067    Record record2 = Record.ofEntries(entry(Field.TABLE, "tableName"), entry(Field.REGION_COUNT, 5),
068      entry(Field.REQUEST_COUNT_PER_SECOND, 500L));
069
070    Record actual = record1.combine(record2);
071
072    assertThat(actual.size(), is(3));
073    assertThat(actual.get(Field.TABLE).asString(), is("tableName"));
074    assertThat(actual.get(Field.REGION_COUNT).asInt(), is(8));
075    assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(600L));
076  }
077}