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.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@Category(SmallTests.class) 032public class TestRecord { 033 034 @ClassRule 035 public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestRecord.class); 036 037 @Test 038 public void testBuilder() { 039 Record actual1 = 040 Record.builder().put(Field.TABLE, "tableName").put(entry(Field.REGION_COUNT, 3)) 041 .put(Field.REQUEST_COUNT_PER_SECOND, Field.REQUEST_COUNT_PER_SECOND.newValue(100L)).build(); 042 043 assertThat(actual1.size(), is(3)); 044 assertThat(actual1.get(Field.TABLE).asString(), is("tableName")); 045 assertThat(actual1.get(Field.REGION_COUNT).asInt(), is(3)); 046 assertThat(actual1.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L)); 047 048 Record actual2 = Record.builder().putAll(actual1).build(); 049 050 assertThat(actual2.size(), is(3)); 051 assertThat(actual2.get(Field.TABLE).asString(), is("tableName")); 052 assertThat(actual2.get(Field.REGION_COUNT).asInt(), is(3)); 053 assertThat(actual2.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L)); 054 } 055 056 @Test 057 public void testOfEntries() { 058 Record actual = Record.ofEntries(entry(Field.TABLE, "tableName"), entry(Field.REGION_COUNT, 3), 059 entry(Field.REQUEST_COUNT_PER_SECOND, 100L)); 060 061 assertThat(actual.size(), is(3)); 062 assertThat(actual.get(Field.TABLE).asString(), is("tableName")); 063 assertThat(actual.get(Field.REGION_COUNT).asInt(), is(3)); 064 assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(100L)); 065 } 066 067 @Test 068 public void testCombine() { 069 Record record1 = Record.ofEntries(entry(Field.TABLE, "tableName"), entry(Field.REGION_COUNT, 3), 070 entry(Field.REQUEST_COUNT_PER_SECOND, 100L)); 071 072 Record record2 = Record.ofEntries(entry(Field.TABLE, "tableName"), entry(Field.REGION_COUNT, 5), 073 entry(Field.REQUEST_COUNT_PER_SECOND, 500L)); 074 075 Record actual = record1.combine(record2); 076 077 assertThat(actual.size(), is(3)); 078 assertThat(actual.get(Field.TABLE).asString(), is("tableName")); 079 assertThat(actual.get(Field.REGION_COUNT).asInt(), is(8)); 080 assertThat(actual.get(Field.REQUEST_COUNT_PER_SECOND).asLong(), is(600L)); 081 } 082}