HBASE-23165 [hbtop] Some modifications from HBASE-22988 (#987)

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Toshihiro Suzuki 2020-01-11 21:06:07 +09:00
parent c9fa98a4d6
commit 1ad28a6f40
30 changed files with 79 additions and 65 deletions

View File

@ -645,7 +645,10 @@ elif [ "$COMMAND" = "hbtop" ] ; then
done
fi
HBASE_OPTS="${HBASE_OPTS} -Dlog4j.configuration=file:${HBASE_HOME}/conf/log4j-hbtop.properties"
if [ -f "${HBASE_HOME}/conf/log4j-hbtop.properties" ] ; then
HBASE_HBTOP_OPTS="${HBASE_HBTOP_OPTS} -Dlog4j.configuration=file:${HBASE_HOME}/conf/log4j-hbtop.properties"
fi
HBASE_OPTS="${HBASE_OPTS} ${HBASE_HBTOP_OPTS}"
else
CLASS=$COMMAND
fi

View File

@ -55,6 +55,9 @@ public final class RecordFilter {
return parse(filterString, Arrays.asList(Field.values()), ignoreCase);
}
/*
* Parse a filter string and build a RecordFilter instance.
*/
public static RecordFilter parse(String filterString, List<Field> fields, boolean ignoreCase) {
int index = 0;

View File

@ -41,13 +41,14 @@ public class RequestCountPerSecond {
previousFilteredReadRequestCount = filteredReadRequestCount;
previousWriteRequestCount = writeRequestCount;
} else if (previousLastReportTimestamp != lastReportTimestamp) {
readRequestCountPerSecond = (readRequestCount - previousReadRequestCount) /
((lastReportTimestamp - previousLastReportTimestamp) / 1000);
long delta = (lastReportTimestamp - previousLastReportTimestamp) / 1000;
if (delta < 1) {
delta = 1;
}
readRequestCountPerSecond = (readRequestCount - previousReadRequestCount) / delta;
filteredReadRequestCountPerSecond =
(filteredReadRequestCount - previousFilteredReadRequestCount) /
((lastReportTimestamp - previousLastReportTimestamp) / 1000);
writeRequestCountPerSecond = (writeRequestCount - previousWriteRequestCount) /
((lastReportTimestamp - previousLastReportTimestamp) / 1000);
(filteredReadRequestCount - previousFilteredReadRequestCount) / delta;
writeRequestCountPerSecond = (writeRequestCount - previousWriteRequestCount) / delta;
previousLastReportTimestamp = lastReportTimestamp;
previousReadRequestCount = readRequestCount;

View File

@ -129,10 +129,10 @@ public class FieldScreenView extends AbstractScreenView {
}
}
public void showScreenDescription(String sortKeyHeader) {
public void showScreenDescription(String sortFieldHeader) {
TerminalPrinter printer = getTerminalPrinter(SCREEN_DESCRIPTION_START_ROW);
printer.startBold().print("Fields Management").stopBold().endOfLine();
printer.print("Current Sort Field: ").startBold().print(sortKeyHeader).stopBold().endOfLine();
printer.print("Current Sort Field: ").startBold().print(sortFieldHeader).stopBold().endOfLine();
printer.print("Navigate with up/down, Right selects for move then <Enter> or Left commits,")
.endOfLine();
printer.print("'d' or <Space> toggles display, 's' sets sort. Use 'q' or <Esc> to end!")

View File

@ -234,8 +234,8 @@ public class TopScreenPresenter {
return new FieldScreenView(screen, terminal,
topScreenModel.getCurrentSortField(), topScreenModel.getFields(),
fieldDisplayMap,
(sortKey, fields, fieldDisplayMap) -> {
topScreenModel.setSortFieldAndFields(sortKey, fields);
(sortField, fields, fieldDisplayMap) -> {
topScreenModel.setSortFieldAndFields(sortField, fields);
this.fieldDisplayMap.clear();
this.fieldDisplayMap.putAll(fieldDisplayMap);
}, topScreenView);

View File

@ -30,11 +30,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class RecordTest {
public class TestRecord {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(RecordTest.class);
HBaseClassTestRule.forClass(TestRecord.class);
@Test
public void testBuilder() {

View File

@ -38,11 +38,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class RecordFilterTest {
public class TestRecordFilter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(RecordFilterTest.class);
HBaseClassTestRule.forClass(TestRecordFilter.class);
@Test
public void testParseAndBuilder() {

View File

@ -232,7 +232,7 @@ public final class TestUtils {
long requestCountPerSecond, long readRequestCountPerSecond,
long filteredReadRequestCountPerSecond, long writeCountRequestPerSecond,
Size storeFileSize, Size uncompressedStoreFileSize, int numStoreFiles,
Size memStoreSize, float Locality, String startKey, long compactingCellCount,
Size memStoreSize, float locality, String startKey, long compactingCellCount,
long compactedCellCount, float compactionProgress, String lastMajorCompactionTime) {
assertThat(record.size(), is(22));
assertThat(record.get(Field.NAMESPACE).asString(), is(namespace));
@ -255,7 +255,7 @@ public final class TestUtils {
is(uncompressedStoreFileSize));
assertThat(record.get(Field.NUM_STORE_FILES).asInt(), is(numStoreFiles));
assertThat(record.get(Field.MEM_STORE_SIZE).asSize(), is(memStoreSize));
assertThat(record.get(Field.LOCALITY).asFloat(), is(Locality));
assertThat(record.get(Field.LOCALITY).asFloat(), is(locality));
assertThat(record.get(Field.START_KEY).asString(), is(startKey));
assertThat(record.get(Field.COMPACTING_CELL_COUNT).asLong(), is(compactingCellCount));
assertThat(record.get(Field.COMPACTED_CELL_COUNT).asLong(), is(compactedCellCount));

View File

@ -30,11 +30,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class FieldValueTest {
public class TestFieldValue {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(FieldValueTest.class);
HBaseClassTestRule.forClass(TestFieldValue.class);
@Test
public void testParseAndAsSomethingMethod() {

View File

@ -32,10 +32,10 @@ import org.junit.ClassRule;
import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class ClientModeTest extends ModeTestBase {
public class TestClientMode extends TestModeBase {
@ClassRule public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(ClientModeTest.class);
HBaseClassTestRule.forClass(TestClientMode.class);
@Override protected Mode getMode() {
return Mode.CLIENT;

View File

@ -23,7 +23,7 @@ import org.apache.hadoop.hbase.hbtop.TestUtils;
import org.junit.Test;
public abstract class ModeTestBase {
public abstract class TestModeBase {
@Test
public void testGetRecords() {

View File

@ -32,11 +32,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class NamespaceModeTest extends ModeTestBase {
public class TestNamespaceMode extends TestModeBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(NamespaceModeTest.class);
HBaseClassTestRule.forClass(TestNamespaceMode.class);
@Override
protected Mode getMode() {

View File

@ -31,11 +31,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class RegionModeTest extends ModeTestBase {
public class TestRegionMode extends TestModeBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(RegionModeTest.class);
HBaseClassTestRule.forClass(TestRegionMode.class);
@Override
protected Mode getMode() {

View File

@ -32,11 +32,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class RegionServerModeTest extends ModeTestBase {
public class TestRegionServerMode extends TestModeBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(RegionServerModeTest.class);
HBaseClassTestRule.forClass(TestRegionServerMode.class);
@Override
protected Mode getMode() {

View File

@ -28,11 +28,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class RequestCountPerSecondTest {
public class TestRequestCountPerSecond {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(RequestCountPerSecondTest.class);
HBaseClassTestRule.forClass(TestRequestCountPerSecond.class);
@Test
public void test() {

View File

@ -32,11 +32,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class TableModeTest extends ModeTestBase {
public class TestTableMode extends TestModeBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TableModeTest.class);
HBaseClassTestRule.forClass(TestTableMode.class);
@Override
protected Mode getMode() {

View File

@ -32,11 +32,11 @@ import org.junit.ClassRule;
import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class UserModeTest extends ModeTestBase {
public class TestUserMode extends TestModeBase {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(UserModeTest.class);
HBaseClassTestRule.forClass(TestUserMode.class);
@Override
protected Mode getMode() {

View File

@ -47,11 +47,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class FieldScreenPresenterTest {
public class TestFieldScreenPresenter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(FieldScreenPresenterTest.class);
HBaseClassTestRule.forClass(TestFieldScreenPresenter.class);
@Mock
private FieldScreenView fieldScreenView;

View File

@ -37,11 +37,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class HelpScreenPresenterTest {
public class TestHelpScreenPresenter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(HelpScreenPresenterTest.class);
HBaseClassTestRule.forClass(TestHelpScreenPresenter.class);
private static final long TEST_REFRESH_DELAY = 5;

View File

@ -40,11 +40,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class ModeScreenPresenterTest {
public class TestModeScreenPresenter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(ModeScreenPresenterTest.class);
HBaseClassTestRule.forClass(TestModeScreenPresenter.class);
@Mock
private ModeScreenView modeScreenView;

View File

@ -42,11 +42,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class FilterDisplayModeScreenPresenterTest {
public class TestFilterDisplayModeScreenPresenter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(FilterDisplayModeScreenPresenterTest.class);
HBaseClassTestRule.forClass(TestFilterDisplayModeScreenPresenter.class);
@Mock
private FilterDisplayModeScreenView filterDisplayModeScreenView;

View File

@ -43,11 +43,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class InputModeScreenPresenterTest {
public class TestInputModeScreenPresenter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(InputModeScreenPresenterTest.class);
HBaseClassTestRule.forClass(TestInputModeScreenPresenter.class);
private static final String TEST_INPUT_MESSAGE = "test input message";

View File

@ -35,11 +35,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class MessageModeScreenPresenterTest {
public class TestMessageModeScreenPresenter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(MessageModeScreenPresenterTest.class);
HBaseClassTestRule.forClass(TestMessageModeScreenPresenter.class);
private static final String TEST_MESSAGE = "test message";

View File

@ -28,11 +28,11 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class PagingTest {
public class TestPaging {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(PagingTest.class);
HBaseClassTestRule.forClass(TestPaging.class);
@Test
public void testArrowUpAndArrowDown() {

View File

@ -47,11 +47,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class TopScreenModelTest {
public class TestTopScreenModel {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TopScreenModelTest.class);
HBaseClassTestRule.forClass(TestTopScreenModel.class);
@Mock
private Admin admin;

View File

@ -45,11 +45,11 @@ import org.mockito.runners.MockitoJUnitRunner;
@Category(SmallTests.class)
@RunWith(MockitoJUnitRunner.class)
public class TopScreenPresenterTest {
public class TestTopScreenPresenter {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TopScreenPresenterTest.class);
HBaseClassTestRule.forClass(TestTopScreenPresenter.class);
private static final List<FieldInfo> TEST_FIELD_INFOS = Arrays.asList(
new FieldInfo(Field.REGION, 10, true),

View File

@ -15,15 +15,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.hbtop.terminal;
package org.apache.hadoop.hbase.hbtop.terminal.impl;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.hbtop.terminal.impl.TerminalImpl;
import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
public final class CursorTest {
public final class TestCursor {
private CursorTest() {
private TestCursor() {
}
public static void main(String[] args) throws Exception {

View File

@ -15,15 +15,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.hbtop.terminal;
package org.apache.hadoop.hbase.hbtop.terminal.impl;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.hbtop.terminal.impl.TerminalImpl;
import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
public final class KeyPressTest {
public final class TestKeyPress {
private KeyPressTest() {
private TestKeyPress() {
}
public static void main(String[] args) throws Exception {

View File

@ -15,15 +15,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.hbtop.terminal;
package org.apache.hadoop.hbase.hbtop.terminal.impl;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.hbtop.terminal.impl.TerminalImpl;
import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
import org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter;
public final class TerminalPrinterTest {
public final class TestTerminalPrinter {
private TerminalPrinterTest() {
private TestTerminalPrinter() {
}
public static void main(String[] args) throws Exception {