Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0EE101770A for ; Thu, 2 Jul 2015 22:17:19 +0000 (UTC) Received: (qmail 35566 invoked by uid 500); 2 Jul 2015 22:17:18 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 35500 invoked by uid 500); 2 Jul 2015 22:17:18 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 35275 invoked by uid 99); 2 Jul 2015 22:17:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jul 2015 22:17:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5B183E367E; Thu, 2 Jul 2015 22:17:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Thu, 02 Jul 2015 22:17:21 -0000 Message-Id: In-Reply-To: <2c661e772b464980a184d1579ed56c6e@git.apache.org> References: <2c661e772b464980a184d1579ed56c6e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/6] accumulo git commit: Merge branch '1.6' into 1.7 Merge branch '1.6' into 1.7 Conflicts: shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/acef2e5d Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/acef2e5d Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/acef2e5d Branch: refs/heads/master Commit: acef2e5d4a72c0dcd372ce0d35da4fc307b74496 Parents: ba300ba 62e3b0f Author: Josh Elser Authored: Thu Jul 2 17:57:11 2015 -0400 Committer: Josh Elser Committed: Thu Jul 2 18:17:02 2015 -0400 ---------------------------------------------------------------------- .../java/org/apache/accumulo/shell/mock/MockShell.java | 11 +++++++++++ 1 file changed, 11 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/acef2e5d/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java ---------------------------------------------------------------------- diff --cc shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java index c11aed5,0000000..609f23f mode 100644,000000..100644 --- a/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java +++ b/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java @@@ -1,146 -1,0 +1,157 @@@ +/* + * 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.mock; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import jline.console.ConsoleReader; + ++import org.apache.accumulo.core.client.AccumuloException; ++import org.apache.accumulo.core.client.AccumuloSecurityException; ++import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.shell.Shell; +import org.apache.accumulo.shell.ShellOptionsJC; ++import org.apache.commons.cli.CommandLine; ++import org.apache.commons.vfs2.FileSystemException; + +/** + * An Accumulo Shell implementation that allows a developer to attach an InputStream and Writer to the Shell for testing purposes. + */ +public class MockShell extends Shell { + private static final String NEWLINE = "\n"; + + protected InputStream in; + protected OutputStream out; + + public MockShell(InputStream in, OutputStream out) throws IOException { + super(); + this.in = in; + this.out = out; + } + + @Override + public boolean config(String... args) { + // If configuring the shell failed, fail quickly + if (!super.config(args)) { + return false; + } + + // Update the ConsoleReader with the input and output "redirected" + try { + this.reader = new ConsoleReader(in, out); + } catch (Exception e) { + printException(e); + return false; + } + + // Don't need this for testing purposes + this.reader.setHistoryEnabled(false); + this.reader.setPaginationEnabled(false); + + // Make the parsing from the client easier; + this.verbose = false; + return true; + } + + @Override + protected void setInstance(ShellOptionsJC options) { + // We always want a MockInstance for this test + instance = new MockInstance(); + } + + @Override + public int start() throws IOException { + String input; + if (isVerbose()) + printInfo(); + + if (execFile != null) { + java.util.Scanner scanner = new java.util.Scanner(execFile, UTF_8.name()); + try { + while (scanner.hasNextLine() && !hasExited()) { + execCommand(scanner.nextLine(), true, isVerbose()); + } + } finally { + scanner.close(); + } + } else if (execCommand != null) { + for (String command : execCommand.split("\n")) { + execCommand(command, true, isVerbose()); + } + return exitCode; + } + + while (true) { + if (hasExited()) + return exitCode; + + reader.setPrompt(getDefaultPrompt()); + input = reader.readLine(); + if (input == null) { + reader.println(); + return exitCode; + } // user canceled + + execCommand(input, false, false); + } + } + + /** + * @param in + * the in to set + */ + public void setConsoleInputStream(InputStream in) { + this.in = in; + } + + /** + * @param out + * the output stream to set + */ + public void setConsoleWriter(OutputStream out) { + this.out = out; + } + ++ @Override ++ public ClassLoader getClassLoader(final CommandLine cl, final Shell shellState) throws AccumuloException, TableNotFoundException, AccumuloSecurityException, ++ IOException, FileSystemException { ++ return MockShell.class.getClassLoader(); ++ } ++ + /** + * Convenience method to create the byte-array to hand to the console + * + * @param commands + * An array of commands to run + * @return A byte[] input stream which can be handed to the console. + */ + public static ByteArrayInputStream makeCommands(String... commands) { + StringBuilder sb = new StringBuilder(commands.length * 8); + + for (String command : commands) { + sb.append(command).append(NEWLINE); + } + + return new ByteArrayInputStream(sb.toString().getBytes(UTF_8)); + } +}