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.util;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.assertNotNull;
022
023import java.io.PrintStream;
024import java.util.LinkedList;
025import java.util.List;
026import org.apache.hadoop.hbase.master.cleaner.TimeToLiveLogCleaner;
027import org.apache.hadoop.hbase.testclassification.MiscTests;
028import org.apache.hadoop.hbase.testclassification.SmallTests;
029import org.junit.jupiter.api.Tag;
030import org.junit.jupiter.api.Test;
031
032@Tag(MiscTests.TAG)
033@Tag(SmallTests.TAG)
034public class TestHBaseConfTool {
035
036  @Test
037  public void testHBaseConfTool() {
038    String[] args = { TimeToLiveLogCleaner.TTL_CONF_KEY };
039    PrintStream stdout = System.out;
040
041    try {
042      DummyPrintStream printStream = new DummyPrintStream(System.out);
043      System.setOut(printStream);
044
045      HBaseConfTool.main(args);
046
047      List<String> printedLines = printStream.getPrintedLines();
048      assertNotNull(printedLines);
049      assertEquals(1, printedLines.size());
050      assertEquals(String.valueOf(TimeToLiveLogCleaner.DEFAULT_TTL), printedLines.get(0));
051    } finally {
052      // reset to standard output
053      System.setOut(stdout);
054    }
055  }
056
057  static class DummyPrintStream extends PrintStream {
058
059    private List<String> printedLines = new LinkedList<>();
060
061    public DummyPrintStream(PrintStream printStream) {
062      super(printStream);
063    }
064
065    @Override
066    public void println(String line) {
067      printedLines.add(line);
068      super.println(line);
069    }
070
071    public List<String> getPrintedLines() {
072      return printedLines;
073    }
074  }
075}