You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by md...@apache.org on 2014/04/29 05:21:36 UTC
[1/3] git commit: ACCUMULO-2742 offset history command by one
Repository: accumulo
Updated Branches:
refs/heads/1.6.0-SNAPSHOT 0aa475895 -> 1f7dd2d53
refs/heads/master a723216a7 -> b48b13acb
ACCUMULO-2742 offset history command by one
The history entries returned by the history command are 0-indexed,
while the history expansion is 1-indexed. We need to offset the index
when we print it so that users can accurately use event expansion.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/1f7dd2d5
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/1f7dd2d5
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/1f7dd2d5
Branch: refs/heads/1.6.0-SNAPSHOT
Commit: 1f7dd2d53ffebb5bac629f61caffa70c50526730
Parents: 0aa4758
Author: Mike Drob <md...@cloudera.com>
Authored: Mon Apr 28 15:14:23 2014 -0400
Committer: Mike Drob <md...@cloudera.com>
Committed: Mon Apr 28 23:20:35 2014 -0400
----------------------------------------------------------------------
.../util/shell/commands/HistoryCommand.java | 31 +++----
.../util/shell/command/HistoryCommandTest.java | 90 ++++++++++++++++++++
2 files changed, 102 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/1f7dd2d5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
index 9531d90..d6068ba 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
@@ -18,7 +18,6 @@ package org.apache.accumulo.core.util.shell.commands;
import java.io.IOException;
import java.util.Iterator;
-import java.util.ListIterator;
import jline.console.history.History.Entry;
@@ -27,39 +26,33 @@ import org.apache.accumulo.core.util.shell.Shell.Command;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
-import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
public class HistoryCommand extends Command {
private Option clearHist;
private Option disablePaginationOpt;
- @SuppressWarnings("unchecked")
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException {
if (cl.hasOption(clearHist.getOpt())) {
shellState.getReader().getHistory().clear();
} else {
- ListIterator<Entry> it = shellState.getReader().getHistory().entries();
- shellState.printLines(new HistoryLineIterator(it), !cl.hasOption(disablePaginationOpt.getOpt()));
+ Iterator<Entry> source = shellState.getReader().getHistory().entries();
+ Iterator<String> historyIterator = Iterators.transform(source, new Function<Entry,String>() {
+ @Override
+ public String apply(Entry input) {
+ return String.format("%d: %s", input.index() + 1, input.value());
+ }
+ });
+
+ shellState.printLines(historyIterator, !cl.hasOption(disablePaginationOpt.getOpt()));
}
return 0;
}
- /**
- * Decorator that converts an Iterator<History.Entry> to an Iterator<String>.
- */
- private static class HistoryLineIterator extends AbstractIteratorDecorator {
- public HistoryLineIterator(Iterator<Entry> iterator) {
- super(iterator);
- }
-
- @Override
- public String next() {
- return super.next().toString();
- }
- }
-
@Override
public String description() {
return ("generates a list of commands previously executed");
http://git-wip-us.apache.org/repos/asf/accumulo/blob/1f7dd2d5/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java b/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java
new file mode 100644
index 0000000..4d379cc
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.command;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import jline.console.ConsoleReader;
+import jline.console.history.History;
+import jline.console.history.MemoryHistory;
+
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.commands.HistoryCommand;
+import org.apache.commons.cli.CommandLine;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HistoryCommandTest {
+
+ HistoryCommand command;
+ CommandLine cl;
+
+ ByteArrayOutputStream baos;
+ ConsoleReader reader;
+ Shell shell;
+
+ @Before
+ public void setUp() throws Exception {
+ command = new HistoryCommand();
+ command.getOptions(); // Make sure everything is initialized
+
+ cl = createMock(CommandLine.class);
+ expect(cl.hasOption("c")).andReturn(false);
+ expect(cl.hasOption("np")).andReturn(true);
+ replay(cl);
+
+ History history = new MemoryHistory();
+ history.add("foo");
+ history.add("bar");
+
+ baos = new ByteArrayOutputStream();
+
+ String input = String.format("!1%n"); // Construct a platform dependent new-line
+ reader = new ConsoleReader(new ByteArrayInputStream(input.getBytes()), baos);
+ reader.setHistory(history);
+
+ shell = new Shell(reader, null);
+ }
+
+ @Test
+ public void testCorrectNumbering() throws IOException {
+ command.execute("", cl, shell);
+ reader.flush();
+
+ assertTrue(baos.toString().contains("2: bar"));
+ }
+
+ @Test
+ public void testEventExpansion() throws IOException {
+ // If we use an unsupported terminal, then history expansion doesn't work because JLine can't do magic buffer manipulations.
+ // This has been observed to be the case on certain versions of Eclipse. However, mvn is usually fine.
+ Assume.assumeTrue(reader.getTerminal().isSupported());
+
+ reader.readLine();
+
+ assertTrue(baos.toString().trim().endsWith("foo"));
+ }
+
+}
[3/3] git commit: Merge branch '1.6.0-SNAPSHOT'
Posted by md...@apache.org.
Merge branch '1.6.0-SNAPSHOT'
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/b48b13ac
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/b48b13ac
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/b48b13ac
Branch: refs/heads/master
Commit: b48b13acbd51ae4e004d5a773bb18a26a491dfe8
Parents: a723216 1f7dd2d
Author: Mike Drob <md...@cloudera.com>
Authored: Mon Apr 28 23:20:51 2014 -0400
Committer: Mike Drob <md...@cloudera.com>
Committed: Mon Apr 28 23:20:51 2014 -0400
----------------------------------------------------------------------
.../util/shell/command/HistoryCommandTest.java | 90 ++++++++++++++++++++
.../accumulo/shell/commands/HistoryCommand.java | 31 +++----
2 files changed, 102 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/b48b13ac/shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
----------------------------------------------------------------------
diff --cc shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
index 1c1314a,0000000..74817a3
mode 100644,000000..100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/HistoryCommand.java
@@@ -1,82 -1,0 +1,75 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.shell.commands;
+
+import java.io.IOException;
+import java.util.Iterator;
- import java.util.ListIterator;
+
+import jline.console.history.History.Entry;
+
+import org.apache.accumulo.shell.Shell;
+import org.apache.accumulo.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
- import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
++
++import com.google.common.base.Function;
++import com.google.common.collect.Iterators;
+
+public class HistoryCommand extends Command {
+ private Option clearHist;
+ private Option disablePaginationOpt;
+
- @SuppressWarnings("unchecked")
+ @Override
+ public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException {
+ if (cl.hasOption(clearHist.getOpt())) {
+ shellState.getReader().getHistory().clear();
+ } else {
- ListIterator<Entry> it = shellState.getReader().getHistory().entries();
- shellState.printLines(new HistoryLineIterator(it), !cl.hasOption(disablePaginationOpt.getOpt()));
++ Iterator<Entry> source = shellState.getReader().getHistory().entries();
++ Iterator<String> historyIterator = Iterators.transform(source, new Function<Entry,String>() {
++ @Override
++ public String apply(Entry input) {
++ return String.format("%d: %s", input.index() + 1, input.value());
++ }
++ });
++
++ shellState.printLines(historyIterator, !cl.hasOption(disablePaginationOpt.getOpt()));
+ }
+
+ return 0;
+ }
+
- /**
- * Decorator that converts an Iterator<History.Entry> to an Iterator<String>.
- */
- private static class HistoryLineIterator extends AbstractIteratorDecorator {
- public HistoryLineIterator(Iterator<Entry> iterator) {
- super(iterator);
- }
-
- @Override
- public String next() {
- return super.next().toString();
- }
- }
-
+ @Override
+ public String description() {
+ return ("generates a list of commands previously executed");
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+
+ @Override
+ public Options getOptions() {
+ final Options o = new Options();
+ clearHist = new Option("c", "clear", false, "clear history file");
+ o.addOption(clearHist);
+ disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of output");
+ o.addOption(disablePaginationOpt);
+ return o;
+ }
+}
[2/3] git commit: ACCUMULO-2742 offset history command by one
Posted by md...@apache.org.
ACCUMULO-2742 offset history command by one
The history entries returned by the history command are 0-indexed,
while the history expansion is 1-indexed. We need to offset the index
when we print it so that users can accurately use event expansion.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/1f7dd2d5
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/1f7dd2d5
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/1f7dd2d5
Branch: refs/heads/master
Commit: 1f7dd2d53ffebb5bac629f61caffa70c50526730
Parents: 0aa4758
Author: Mike Drob <md...@cloudera.com>
Authored: Mon Apr 28 15:14:23 2014 -0400
Committer: Mike Drob <md...@cloudera.com>
Committed: Mon Apr 28 23:20:35 2014 -0400
----------------------------------------------------------------------
.../util/shell/commands/HistoryCommand.java | 31 +++----
.../util/shell/command/HistoryCommandTest.java | 90 ++++++++++++++++++++
2 files changed, 102 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/1f7dd2d5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
index 9531d90..d6068ba 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
@@ -18,7 +18,6 @@ package org.apache.accumulo.core.util.shell.commands;
import java.io.IOException;
import java.util.Iterator;
-import java.util.ListIterator;
import jline.console.history.History.Entry;
@@ -27,39 +26,33 @@ import org.apache.accumulo.core.util.shell.Shell.Command;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
-import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
public class HistoryCommand extends Command {
private Option clearHist;
private Option disablePaginationOpt;
- @SuppressWarnings("unchecked")
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException {
if (cl.hasOption(clearHist.getOpt())) {
shellState.getReader().getHistory().clear();
} else {
- ListIterator<Entry> it = shellState.getReader().getHistory().entries();
- shellState.printLines(new HistoryLineIterator(it), !cl.hasOption(disablePaginationOpt.getOpt()));
+ Iterator<Entry> source = shellState.getReader().getHistory().entries();
+ Iterator<String> historyIterator = Iterators.transform(source, new Function<Entry,String>() {
+ @Override
+ public String apply(Entry input) {
+ return String.format("%d: %s", input.index() + 1, input.value());
+ }
+ });
+
+ shellState.printLines(historyIterator, !cl.hasOption(disablePaginationOpt.getOpt()));
}
return 0;
}
- /**
- * Decorator that converts an Iterator<History.Entry> to an Iterator<String>.
- */
- private static class HistoryLineIterator extends AbstractIteratorDecorator {
- public HistoryLineIterator(Iterator<Entry> iterator) {
- super(iterator);
- }
-
- @Override
- public String next() {
- return super.next().toString();
- }
- }
-
@Override
public String description() {
return ("generates a list of commands previously executed");
http://git-wip-us.apache.org/repos/asf/accumulo/blob/1f7dd2d5/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java b/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java
new file mode 100644
index 0000000..4d379cc
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/util/shell/command/HistoryCommandTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.command;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import jline.console.ConsoleReader;
+import jline.console.history.History;
+import jline.console.history.MemoryHistory;
+
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.commands.HistoryCommand;
+import org.apache.commons.cli.CommandLine;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HistoryCommandTest {
+
+ HistoryCommand command;
+ CommandLine cl;
+
+ ByteArrayOutputStream baos;
+ ConsoleReader reader;
+ Shell shell;
+
+ @Before
+ public void setUp() throws Exception {
+ command = new HistoryCommand();
+ command.getOptions(); // Make sure everything is initialized
+
+ cl = createMock(CommandLine.class);
+ expect(cl.hasOption("c")).andReturn(false);
+ expect(cl.hasOption("np")).andReturn(true);
+ replay(cl);
+
+ History history = new MemoryHistory();
+ history.add("foo");
+ history.add("bar");
+
+ baos = new ByteArrayOutputStream();
+
+ String input = String.format("!1%n"); // Construct a platform dependent new-line
+ reader = new ConsoleReader(new ByteArrayInputStream(input.getBytes()), baos);
+ reader.setHistory(history);
+
+ shell = new Shell(reader, null);
+ }
+
+ @Test
+ public void testCorrectNumbering() throws IOException {
+ command.execute("", cl, shell);
+ reader.flush();
+
+ assertTrue(baos.toString().contains("2: bar"));
+ }
+
+ @Test
+ public void testEventExpansion() throws IOException {
+ // If we use an unsupported terminal, then history expansion doesn't work because JLine can't do magic buffer manipulations.
+ // This has been observed to be the case on certain versions of Eclipse. However, mvn is usually fine.
+ Assume.assumeTrue(reader.getTerminal().isSupported());
+
+ reader.readLine();
+
+ assertTrue(baos.toString().trim().endsWith("foo"));
+ }
+
+}