accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject accumulo git commit: ACCUMULO-3642 Create empty client configuration file to make unit tests pass.
Date Fri, 06 Mar 2015 02:45:11 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master 76ddd9105 -> a864c6054


ACCUMULO-3642 Create empty client configuration file to make unit tests pass.

If a client configuration exists on the current system, the Shell will
attempt to pick it up when one is not provided as an argument. This causes
spurious unit-test failures. These tests should be isolated from the
host environment and now set an empty client configuration as the
tests inherently expect.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/a864c605
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/a864c605
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/a864c605

Branch: refs/heads/master
Commit: a864c60546839952d5300330eaba3b8e9ec45f33
Parents: 76ddd91
Author: Josh Elser <elserj@apache.org>
Authored: Thu Mar 5 18:16:27 2015 -0800
Committer: Josh Elser <elserj@apache.org>
Committed: Thu Mar 5 18:16:27 2015 -0800

----------------------------------------------------------------------
 .../apache/accumulo/shell/ShellConfigTest.java  | 29 ++++++++++++++++----
 .../org/apache/accumulo/shell/ShellTest.java    | 11 ++++++--
 .../shell/commands/FormatterCommandTest.java    |  6 +++-
 3 files changed, 38 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/a864c605/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
index 922ef8c..ce05183 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
@@ -19,10 +19,12 @@ package org.apache.accumulo.shell;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.nio.file.Files;
 
 import jline.console.ConsoleReader;
 
@@ -39,6 +41,7 @@ public class ShellConfigTest {
   TestOutputStream output;
   Shell shell;
   PrintStream out;
+  File config;
 
   @Before
   public void setUp() throws Exception {
@@ -47,6 +50,7 @@ public class ShellConfigTest {
     out = System.out;
     output = new TestOutputStream();
     System.setOut(new PrintStream(output));
+    config = Files.createTempFile(null, null).toFile();
 
     shell = new Shell(new ConsoleReader(new FileInputStream(FileDescriptor.in), output),
new PrintWriter(output));
     shell.setLogErrorsToConsole();
@@ -57,34 +61,49 @@ public class ShellConfigTest {
     shell.shutdown();
     output.clear();
     System.setOut(out);
+    if (config.exists()) {
+      config.delete();
+    }
+  }
+
+  public String[] args(String... args) {
+    // Avoid a locally installed client configuration file from breaking the test
+    String[] finalArgs = new String[args.length + 2];
+    int i = 0;
+    finalArgs[i++] = "--config-file";
+    finalArgs[i++] = config.toString();
+    for (String arg : args) {
+      finalArgs[i++] = arg;
+    }
+    return finalArgs;
   }
 
   @Test
   public void testHelp() {
-    assertFalse(shell.config("--help"));
+    assertFalse(shell.config(args("--help")));
     assertTrue("Did not print usage", output.get().startsWith("Usage"));
   }
 
   @Test
   public void testBadArg() {
-    assertFalse(shell.config("--bogus"));
+    assertFalse(shell.config(args("--bogus")));
     assertTrue("Did not print usage", output.get().startsWith("Usage"));
   }
 
   @Test
   public void testTokenWithoutOptions() {
-    assertFalse(shell.config("--fake", "-tc", PasswordToken.class.getCanonicalName()));
+    assertFalse(shell.config(args("--fake", "-tc", PasswordToken.class.getCanonicalName())));
     assertFalse(output.get().contains(ParameterException.class.getCanonicalName()));
   }
 
   @Test
   public void testTokenAndOption() {
-    assertTrue(shell.config("--fake", "-tc", PasswordToken.class.getCanonicalName(), "-u",
"foo", "-l", "password=foo"));
+    assertTrue(shell.config(args("--fake", "-tc", PasswordToken.class.getCanonicalName(),
"-u", "foo", "-l", "password=foo")));
   }
 
   @Test
   public void testTokenAndOptionAndPassword() {
-    assertFalse(shell.config("--fake", "-tc", PasswordToken.class.getCanonicalName(), "-l",
"password=foo", "-p", "bar"));
+    assertFalse(shell.config(args("--fake", "-tc", PasswordToken.class.getCanonicalName(),
"-l", "password=foo", "-p", "bar")));
     assertTrue(output.get().contains(ParameterException.class.getCanonicalName()));
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/a864c605/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
index 82e61fd..567cdad 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
@@ -19,11 +19,13 @@ package org.apache.accumulo.shell;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.file.Files;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
@@ -78,6 +80,7 @@ public class ShellTest {
   private StringInputStream input;
   private TestOutputStream output;
   private Shell shell;
+  private File config;
 
   void execExpectList(String cmd, boolean expecteGoodExit, List<String> expectedStrings)
throws IOException {
     exec(cmd);
@@ -123,14 +126,18 @@ public class ShellTest {
     Shell.log.setLevel(Level.OFF);
     output = new TestOutputStream();
     input = new StringInputStream();
+    config = Files.createTempFile(null, null).toFile();
     PrintWriter pw = new PrintWriter(new OutputStreamWriter(output));
     shell = new Shell(new ConsoleReader(input, output), pw);
     shell.setLogErrorsToConsole();
-    shell.config("--fake", "-u", "test", "-p", "secret");
+    shell.config("--config-file", config.toString(), "--fake", "-u", "test", "-p", "secret");
   }
 
   @After
   public void teardown() {
+    if (config.exists()) {
+      config.delete();
+    }
     shell.shutdown();
   }
 
@@ -262,7 +269,7 @@ public class ShellTest {
   @Test
   public void execFileTest() throws IOException {
     Shell.log.debug("Starting exec file test --------------------------");
-    shell.config("--fake", "-u", "test", "-p", "secret", "-f", "src/test/resources/shelltest.txt");
+    shell.config("--config-file", config.toString(), "--fake", "-u", "test", "-p", "secret",
"-f", "src/test/resources/shelltest.txt");
     assertEquals(0, shell.start());
     assertGoodExit("Unknown command", false);
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/a864c605/shell/src/test/java/org/apache/accumulo/shell/commands/FormatterCommandTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/commands/FormatterCommandTest.java
b/shell/src/test/java/org/apache/accumulo/shell/commands/FormatterCommandTest.java
index 577be37..866e716 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/commands/FormatterCommandTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/commands/FormatterCommandTest.java
@@ -19,8 +19,10 @@ package org.apache.accumulo.shell.commands;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.Iterator;
 import java.util.Map.Entry;
 
@@ -49,7 +51,9 @@ public class FormatterCommandTest {
     // Keep the Shell AUDIT log off the test output
     Logger.getLogger(Shell.class).setLevel(Level.WARN);
 
-    final String[] args = new String[] {"--fake", "-u", "root", "-p", ""};
+    File config = Files.createTempFile(null, null).toFile();
+    config.deleteOnExit();
+    final String[] args = new String[] {"--config-file", config.toString(), "--fake", "-u",
"root", "-p", ""};
 
     final String[] commands = createCommands();
 


Mime
View raw message