Skip to content

Commit f3bd1b8

Browse files
authored
Fixes shell pagination (apache#5251)
* Remove -np from all tests * Check conditions for pagination Adds a boolean to track if the shell is able to paginate and adds specific conditions that invalidate pagination * Removes unneeded check and mockshell terminal size Removes the terminal size from MockShell so pagination does not occur.
1 parent b140460 commit f3bd1b8

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

shell/src/main/java/org/apache/accumulo/shell/Shell.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public class Shell extends ShellOptions implements KeywordExecutable {
229229
protected String execCommand = null;
230230
protected boolean verbose = true;
231231

232+
private boolean canPaginate = false;
232233
private boolean tabCompletion;
233234
private boolean disableAuthTimeout;
234235
private long authTimeout;
@@ -383,6 +384,8 @@ public boolean config(String... args) throws IOException {
383384
}
384385
}
385386

387+
canPaginate = terminal.getSize().getRows() > 0;
388+
386389
// decide whether to execute commands from a file and quit
387390
if (options.getExecFile() != null) {
388391
execFile = options.getExecFile();
@@ -1066,7 +1069,7 @@ public final void printLines(Iterator<String> lines, boolean paginate, PrintLine
10661069
if (out == null) {
10671070
if (peek != null) {
10681071
writer.println(peek);
1069-
if (paginate) {
1072+
if (canPaginate && paginate) {
10701073
linesPrinted += peek.isEmpty() ? 0 : Math.ceil(peek.length() * 1.0 / termWidth);
10711074

10721075
// check if displaying the next line would result in

test/src/main/java/org/apache/accumulo/test/shell/MockShell.java

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.accumulo.shell.Shell;
3131
import org.jline.reader.LineReader;
3232
import org.jline.reader.LineReaderBuilder;
33-
import org.jline.terminal.Size;
3433
import org.jline.terminal.Terminal;
3534
import org.jline.terminal.impl.DumbTerminal;
3635
import org.slf4j.Logger;
@@ -53,7 +52,6 @@ public class MockShell {
5352
output = new TestOutputStream();
5453
input = new StringInputStream();
5554
terminal = new DumbTerminal(input, output);
56-
terminal.setSize(new Size(80, 24));
5755
reader = LineReaderBuilder.builder().terminal(terminal).build();
5856
shell = new Shell(reader);
5957
shell.setLogErrorsToConsole();

test/src/main/java/org/apache/accumulo/test/shell/ShellServerIT.java

+32-33
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public void exporttableImporttable() throws Exception {
223223
}
224224
Thread.sleep(20);
225225
ts.exec("importtable " + table2 + " " + import_, true);
226-
ts.exec("config -t " + table2 + " -np", true, "345M", true);
226+
ts.exec("config -t " + table2, true, "345M", true);
227227
ts.exec("getsplits -t " + table2, true, "row5", true);
228228
ts.exec("constraint --list -t " + table2, true, "VisibilityConstraint=2", true);
229229
ts.exec("online " + table, true);
@@ -249,14 +249,14 @@ public void propStressTest() throws Exception {
249249
for (int i = 0; i < 50; i++) {
250250
String expected = (100 + i) + "M";
251251
ts.exec("config -t " + table + " -s table.split.threshold=" + expected, true);
252-
ts.exec("config -t " + table + " -np -f table.split.threshold", true, expected, true);
252+
ts.exec("config -t " + table + " -f table.split.threshold", true, expected, true);
253253

254254
ts.exec("config -t " + table + " -s table.scan.max.memory=" + expected, true);
255-
ts.exec("config -t " + table + " -np -f table.scan.max.memory", true, expected, true);
255+
ts.exec("config -t " + table + " -f table.scan.max.memory", true, expected, true);
256256

257257
String bExpected = ((i % 2) == 0) ? "true" : "false";
258258
ts.exec("config -t " + table + " -s table.bloom.enabled=" + bExpected, true);
259-
ts.exec("config -t " + table + " -np -f table.bloom.enabled", true, bExpected, true);
259+
ts.exec("config -t " + table + " -f table.bloom.enabled", true, bExpected, true);
260260
}
261261
}
262262
}
@@ -688,7 +688,7 @@ public void clonetable() throws Exception {
688688
ts.exec("table " + clone);
689689
ts.exec("scan", true, "value", true);
690690
ts.exec("constraint --list -t " + clone, true, "VisibilityConstraint=2", true);
691-
ts.exec("config -t " + clone + " -np", true, "123M", true);
691+
ts.exec("config -t " + clone, true, "123M", true);
692692
ts.exec("getsplits -t " + clone, true, "a\nb\nc\n");
693693
ts.exec("deletetable -f " + table);
694694
ts.exec("deletetable -f " + clone);
@@ -717,7 +717,7 @@ public void clonetableOffline() throws Exception {
717717
ts.exec("table " + clone);
718718
ts.exec("scan", false, "TableOfflineException", true);
719719
ts.exec("constraint --list -t " + clone, true, "VisibilityConstraint=2", true);
720-
ts.exec("config -t " + clone + " -np", true, "123M", true);
720+
ts.exec("config -t " + clone, true, "123M", true);
721721
ts.exec("getsplits -t " + clone, true, "a\nb\nc\n");
722722
ts.exec("deletetable -f " + table);
723723
ts.exec("deletetable -f " + clone);
@@ -1080,7 +1080,7 @@ public void deletemany() throws Exception {
10801080
assertEquals(10, countkeys(table));
10811081
ts.exec("deletemany -f -b row8");
10821082
assertEquals(8, countkeys(table));
1083-
ts.exec("scan -t " + table + " -np", true, "row8", false);
1083+
ts.exec("scan -t " + table, true, "row8", false);
10841084
make10();
10851085
ts.exec("deletemany -f -b row4 -e row5");
10861086
assertEquals(8, countkeys(table));
@@ -1165,7 +1165,7 @@ public void formatter() {
11651165
expectedDefault.add("row2 cf1:cq []\t2468ace");
11661166
ArrayList<String> actualDefault = new ArrayList<>(4);
11671167
boolean isFirst = true;
1168-
for (String s : ts.exec("scan -np", true).split("[\n\r]+")) {
1168+
for (String s : ts.exec("scan", true).split("[\n\r]+")) {
11691169
if (isFirst) {
11701170
isFirst = false;
11711171
} else {
@@ -1181,7 +1181,7 @@ public void formatter() {
11811181
ts.exec("formatter -t formatter_test -f " + HexFormatter.class.getName(), true);
11821182
ArrayList<String> actualFormatted = new ArrayList<>(4);
11831183
isFirst = true;
1184-
for (String s : ts.exec("scan -np", true).split("[\n\r]+")) {
1184+
for (String s : ts.exec("scan", true).split("[\n\r]+")) {
11851185
if (isFirst) {
11861186
isFirst = false;
11871187
} else {
@@ -1292,7 +1292,7 @@ public void grep() throws Exception {
12921292

12931293
@Test
12941294
public void help() throws Exception {
1295-
ts.exec("help -np", true, "Help Commands", true);
1295+
ts.exec("help", true, "Help Commands", true);
12961296
ts.exec("?", true, "Help Commands", true);
12971297
for (String c : ("bye exit quit about help info ? "
12981298
+ "deleteiter deletescaniter listiter setiter setscaniter "
@@ -1376,7 +1376,7 @@ public void importDirectoryWithOptions() throws Exception {
13761376
ts.exec("createtable " + table, true);
13771377
ts.exec("notable", true);
13781378
ts.exec("importdirectory -t " + table + " -i " + importDir + " true", true);
1379-
ts.exec("scan -t " + table + " -np -b 0 -e 2", true, "0-->" + nonce, true);
1379+
ts.exec("scan -t " + table + " -b 0 -e 2", true, "0-->" + nonce, true);
13801380
ts.exec("scan -t " + table + " -b 00000098 -e 00000100", true, "99-->" + nonce, true);
13811381
// Attempt to re-import without -i option, error should occur
13821382
ts.exec("importdirectory -t " + table + " " + importDir + " true", false);
@@ -1661,7 +1661,7 @@ public void verifyPerTableClasspath(final String table, final File fooConstraint
16611661

16621662
sleepUninterruptibly(250, TimeUnit.MILLISECONDS);
16631663

1664-
ts.exec("scan -np", true, "foo", false);
1664+
ts.exec("scan ", true, "foo", false);
16651665

16661666
ts.exec("constraint -a FooConstraint", true);
16671667

@@ -1771,25 +1771,25 @@ public void namespaces() throws Exception {
17711771
}
17721772

17731773
private int countkeys(String table) {
1774-
ts.exec("scan -np -t " + table);
1774+
ts.exec("scan -t " + table);
17751775
return ts.output.get().split("\n").length - 1;
17761776
}
17771777

17781778
@Test
17791779
public void scans() throws Exception {
17801780
ts.exec("createtable t");
17811781
make10();
1782-
String result = ts.exec("scan -np -b row1 -e row1");
1782+
String result = ts.exec("scan -b row1 -e row1");
17831783
assertEquals(2, result.split("\n").length);
1784-
result = ts.exec("scan -np -b row3 -e row5");
1784+
result = ts.exec("scan -b row3 -e row5");
17851785
assertEquals(4, result.split("\n").length);
1786-
result = ts.exec("scan -np -r row3");
1786+
result = ts.exec("scan -r row3");
17871787
assertEquals(2, result.split("\n").length);
1788-
result = ts.exec("scan -np -b row:");
1788+
result = ts.exec("scan -b row:");
17891789
assertEquals(1, result.split("\n").length);
1790-
result = ts.exec("scan -np -b row");
1790+
result = ts.exec("scan -b row");
17911791
assertEquals(11, result.split("\n").length);
1792-
result = ts.exec("scan -np -e row:");
1792+
result = ts.exec("scan -e row:");
17931793
assertEquals(11, result.split("\n").length);
17941794
ts.exec("deletetable -f t");
17951795
}
@@ -1836,21 +1836,21 @@ public void scansWithClassLoaderContext() throws IOException {
18361836

18371837
// The implementation of ValueReversingIterator in the FAKE context does nothing, the value is
18381838
// not reversed.
1839-
result = ts.exec("scan -pn baz -np -b row1 -e row1");
1839+
result = ts.exec("scan -pn baz -b row1 -e row1");
18401840
assertEquals(2, result.split("\n").length);
18411841
assertTrue(result.contains("value"));
1842-
result = ts.exec("scan -pn baz -np -b row3 -e row5");
1842+
result = ts.exec("scan -pn baz -b row3 -e row5");
18431843
assertEquals(4, result.split("\n").length);
18441844
assertTrue(result.contains("value"));
1845-
result = ts.exec("scan -pn baz -np -r row3");
1845+
result = ts.exec("scan -pn baz -r row3");
18461846
assertEquals(2, result.split("\n").length);
18471847
assertTrue(result.contains("value"));
1848-
result = ts.exec("scan -pn baz -np -b row:");
1848+
result = ts.exec("scan -pn baz -b row:");
18491849
assertEquals(1, result.split("\n").length);
1850-
result = ts.exec("scan -pn baz -np -b row");
1850+
result = ts.exec("scan -pn baz -b row");
18511851
assertEquals(11, result.split("\n").length);
18521852
assertTrue(result.contains("value"));
1853-
result = ts.exec("scan -pn baz -np -e row:");
1853+
result = ts.exec("scan -pn baz -e row:");
18541854
assertEquals(11, result.split("\n").length);
18551855
assertTrue(result.contains("value"));
18561856

@@ -1862,25 +1862,25 @@ public void scansWithClassLoaderContext() throws IOException {
18621862
+ REAL_CONTEXT + "=" + REAL_CONTEXT_CLASSPATH + "\n", result);
18631863
// Override the table classloader context with the REAL implementation of
18641864
// ValueReversingIterator, which does reverse the value.
1865-
result = ts.exec("scan -pn baz -np -b row1 -e row1 -cc " + REAL_CONTEXT);
1865+
result = ts.exec("scan -pn baz -b row1 -e row1 -cc " + REAL_CONTEXT);
18661866
assertEquals(2, result.split("\n").length);
18671867
assertTrue(result.contains("eulav"));
18681868
assertFalse(result.contains("value"));
1869-
result = ts.exec("scan -pn baz -np -b row3 -e row5 -cc " + REAL_CONTEXT);
1869+
result = ts.exec("scan -pn baz -b row3 -e row5 -cc " + REAL_CONTEXT);
18701870
assertEquals(4, result.split("\n").length);
18711871
assertTrue(result.contains("eulav"));
18721872
assertFalse(result.contains("value"));
1873-
result = ts.exec("scan -pn baz -np -r row3 -cc " + REAL_CONTEXT);
1873+
result = ts.exec("scan -pn baz -r row3 -cc " + REAL_CONTEXT);
18741874
assertEquals(2, result.split("\n").length);
18751875
assertTrue(result.contains("eulav"));
18761876
assertFalse(result.contains("value"));
1877-
result = ts.exec("scan -pn baz -np -b row: -cc " + REAL_CONTEXT);
1877+
result = ts.exec("scan -pn baz -b row: -cc " + REAL_CONTEXT);
18781878
assertEquals(1, result.split("\n").length);
1879-
result = ts.exec("scan -pn baz -np -b row -cc " + REAL_CONTEXT);
1879+
result = ts.exec("scan -pn baz -b row -cc " + REAL_CONTEXT);
18801880
assertEquals(11, result.split("\n").length);
18811881
assertTrue(result.contains("eulav"));
18821882
assertFalse(result.contains("value"));
1883-
result = ts.exec("scan -pn baz -np -e row: -cc " + REAL_CONTEXT);
1883+
result = ts.exec("scan -pn baz -e row: -cc " + REAL_CONTEXT);
18841884
assertEquals(11, result.split("\n").length);
18851885
assertTrue(result.contains("eulav"));
18861886
assertFalse(result.contains("value"));
@@ -2046,8 +2046,7 @@ private void make10() {
20462046
private List<String> getFiles(String tableId) {
20472047
ts.output.clear();
20482048

2049-
ts.exec(
2050-
"scan -t " + MetadataTable.NAME + " -np -c file -b " + tableId + " -e " + tableId + "~");
2049+
ts.exec("scan -t " + MetadataTable.NAME + " -c file -b " + tableId + " -e " + tableId + "~");
20512050

20522051
log.debug("countFiles(): {}", ts.output.get());
20532052

0 commit comments

Comments
 (0)