You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2019/08/16 03:34:02 UTC
[accumulo] branch 1.9 updated: Improve importDirectory tests from
#1299
This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch 1.9
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/1.9 by this push:
new 19bdeb4 Improve importDirectory tests from #1299
19bdeb4 is described below
commit 19bdeb4d908b5eece1ebccb6be1295e8cf0759de
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Thu Aug 15 20:29:18 2019 -0400
Improve importDirectory tests from #1299
* Remove unused variables in test
* Verify mock objects in test
---
.../shell/commands/ImportDirectoryCommandTest.java | 79 +++++++++-------------
.../org/apache/accumulo/test/ShellServerIT.java | 5 --
2 files changed, 32 insertions(+), 52 deletions(-)
diff --git a/shell/src/test/java/org/apache/accumulo/shell/commands/ImportDirectoryCommandTest.java b/shell/src/test/java/org/apache/accumulo/shell/commands/ImportDirectoryCommandTest.java
index c819d6c..06694fd 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/commands/ImportDirectoryCommandTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/commands/ImportDirectoryCommandTest.java
@@ -16,13 +16,17 @@
*/
package org.apache.accumulo.shell.commands;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.shell.Shell;
import org.apache.commons.cli.CommandLine;
-import org.easymock.EasyMock;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -42,11 +46,15 @@ public class ImportDirectoryCommandTest {
// Initialize that internal state
cmd.getOptions();
- conn = EasyMock.createMock(Connector.class);
- cli = EasyMock.createMock(CommandLine.class);
- shellState = EasyMock.createMock(Shell.class);
- tableOperations = EasyMock.createMock(TableOperations.class);
+ conn = createMock(Connector.class);
+ cli = createMock(CommandLine.class);
+ shellState = createMock(Shell.class);
+ tableOperations = createMock(TableOperations.class);
+ }
+ @After
+ public void verifyMocks() {
+ verify(conn, cli, shellState, tableOperations);
}
/**
@@ -57,33 +65,24 @@ public class ImportDirectoryCommandTest {
*/
@Test
public void testOriginalCmdForm() throws Exception {
-
String[] cliArgs = {"in_dir", "fail_dir", "false"};
- //
- // EasyMock.expect(cli.hasOption('t')).andReturn(false);
- EasyMock.expect(cli.hasOption("t")).andReturn(false);
+ // no -t option, use current table context
+ expect(cli.hasOption("t")).andReturn(false).once();
+ expect(shellState.getTableName()).andReturn("tablename").once();
- EasyMock.expect(cli.getArgs()).andReturn(cliArgs);
- EasyMock.expect(cli.getArgs()).andReturn(cliArgs);
- EasyMock.expect(cli.getArgs()).andReturn(cliArgs);
-
- EasyMock.expect(shellState.getConnector()).andReturn(conn);
- EasyMock.expect(shellState.getTableName()).andReturn("tablename");
+ expect(cli.getArgs()).andReturn(cliArgs).atLeastOnce();
+ expect(shellState.getConnector()).andReturn(conn).atLeastOnce();
+ expect(conn.tableOperations()).andReturn(tableOperations);
shellState.checkTableState();
- expectLastCall().andVoid();
-
- // Table exists
- EasyMock.expect(conn.tableOperations()).andReturn(tableOperations);
+ expectLastCall().once();
tableOperations.importDirectory("tablename", "in_dir", "fail_dir", false);
- expectLastCall().times(3);
-
- EasyMock.replay(conn, cli, shellState, tableOperations);
+ expectLastCall().once();
+ replay(conn, cli, shellState, tableOperations);
cmd.execute("importdirectory in_dir fail_dir false", cli, shellState);
-
}
/**
@@ -94,37 +93,23 @@ public class ImportDirectoryCommandTest {
*/
@Test
public void testPassTableOptCmdForm() throws Exception {
-
String[] cliArgs = {"in_dir", "fail_dir", "false"};
- //
- // EasyMock.expect(cli.hasOption('t')).andReturn(false);
- EasyMock.expect(cli.hasOption("t")).andReturn(true);
- EasyMock.expect(cli.hasOption("t")).andReturn(true);
- EasyMock.expect(cli.getOptionValue("t")).andReturn("passedName");
+ // -t option specified, table is from option
+ expect(cli.hasOption("t")).andReturn(true).once();
+ expect(cli.getOptionValue("t")).andReturn("passedName").once();
+ expect(tableOperations.exists("passedName")).andReturn(true).once();
- EasyMock.expect(tableOperations.exists("passedName")).andReturn(true);
- EasyMock.expect(shellState.getConnector()).andReturn(conn);
- EasyMock.expect(conn.tableOperations()).andReturn(tableOperations);
+ expect(cli.getArgs()).andReturn(cliArgs).atLeastOnce();
+ expect(shellState.getConnector()).andReturn(conn).atLeastOnce();
+ expect(conn.tableOperations()).andReturn(tableOperations).atLeastOnce();
- EasyMock.expect(cli.getArgs()).andReturn(cliArgs);
- EasyMock.expect(cli.getArgs()).andReturn(cliArgs);
- EasyMock.expect(cli.getArgs()).andReturn(cliArgs);
-
- EasyMock.expect(shellState.getConnector()).andReturn(conn);
-
- shellState.checkTableState();
- expectLastCall().andVoid();
-
- // Table exists
- EasyMock.expect(conn.tableOperations()).andReturn(tableOperations);
+ // shellState.checkTableState() is NOT called
tableOperations.importDirectory("passedName", "in_dir", "fail_dir", false);
- expectLastCall().times(3);
-
- EasyMock.replay(conn, cli, shellState, tableOperations);
+ expectLastCall().once();
+ replay(conn, cli, shellState, tableOperations);
cmd.execute("importdirectory in_dir fail_dir false", cli, shellState);
-
}
}
diff --git a/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java b/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
index e429898..9b377fb 100644
--- a/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
@@ -1898,7 +1898,6 @@ public class ShellServerIT extends SharedMiniClusterBase {
ts.exec("deletetable -f " + table);
}
-
/**
* Validate importdirectory command accepts addinig -t tablename option or the accepts original
* format that uses the current working table. Currently this test does not validate the actual
@@ -1909,14 +1908,10 @@ public class ShellServerIT extends SharedMiniClusterBase {
*/
@Test
public void importDirectoryCmdFmt() throws Exception {
-
final String table = name.getMethodName();
- Configuration conf = new Configuration();
- FileSystem fs = FileSystem.get(conf);
File importDir = new File(rootPath, "import_" + table);
assertTrue(importDir.mkdir());
-
File errorsDir = new File(rootPath, "errors_" + table);
assertTrue(errorsDir.mkdir());