Skip to content

Commit 14bee69

Browse files
NihalJainApache9
authored andcommitted
HBASE-20804 Document and add tests for HBaseConfTool (#5190)
Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit e86f930)
1 parent 0e224b1 commit 14bee69

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.util;
19+
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNotNull;
22+
23+
import java.io.PrintStream;
24+
import java.util.LinkedList;
25+
import java.util.List;
26+
import org.apache.hadoop.hbase.HBaseClassTestRule;
27+
import org.apache.hadoop.hbase.master.cleaner.TimeToLiveLogCleaner;
28+
import org.apache.hadoop.hbase.testclassification.MiscTests;
29+
import org.apache.hadoop.hbase.testclassification.SmallTests;
30+
import org.junit.ClassRule;
31+
import org.junit.Test;
32+
import org.junit.experimental.categories.Category;
33+
34+
@Category({ MiscTests.class, SmallTests.class })
35+
public class TestHBaseConfTool {
36+
37+
@ClassRule
38+
public static final HBaseClassTestRule CLASS_RULE =
39+
HBaseClassTestRule.forClass(TestHBaseConfTool.class);
40+
41+
@Test
42+
public void testHBaseConfTool() {
43+
String[] args = { TimeToLiveLogCleaner.TTL_CONF_KEY };
44+
PrintStream stdout = System.out;
45+
46+
try {
47+
DummyPrintStream printStream = new DummyPrintStream(System.out);
48+
System.setOut(printStream);
49+
50+
HBaseConfTool.main(args);
51+
52+
List<String> printedLines = printStream.getPrintedLines();
53+
assertNotNull(printedLines);
54+
assertEquals(1, printedLines.size());
55+
assertEquals(String.valueOf(TimeToLiveLogCleaner.DEFAULT_TTL), printedLines.get(0));
56+
} finally {
57+
// reset to standard output
58+
System.setOut(stdout);
59+
}
60+
}
61+
62+
static class DummyPrintStream extends PrintStream {
63+
64+
private List<String> printedLines = new LinkedList<>();
65+
66+
public DummyPrintStream(PrintStream printStream) {
67+
super(printStream);
68+
}
69+
70+
@Override
71+
public void println(String line) {
72+
printedLines.add(line);
73+
super.println(line);
74+
}
75+
76+
public List<String> getPrintedLines() {
77+
return printedLines;
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)