Author: virag
Date: Thu May 16 17:03:33 2013
New Revision: 1483447
URL: http://svn.apache.org/r1483447
Log:
OOZIE-1328 Cover package org.apache.oozie.cli with unit tests (vbondarev via
virag)
Added:
oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestOozieCLIMethods.java
Modified:
oozie/trunk/client/pom.xml
oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestCLIParser.java
oozie/trunk/core/src/test/java/org/apache/oozie/client/TestOozieCLI.java
oozie/trunk/release-log.txt
Modified: oozie/trunk/client/pom.xml
URL:
http://svn.apache.org/viewvc/oozie/trunk/client/pom.xml?rev=1483447&r1=1483446&r2=1483447&view=diff
==============================================================================
--- oozie/trunk/client/pom.xml (original)
+++ oozie/trunk/client/pom.xml Thu May 16 17:03:33 2013
@@ -47,7 +47,15 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
Modified: oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
URL:
http://svn.apache.org/viewvc/oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java?rev=1483447&r1=1483446&r2=1483447&view=diff
==============================================================================
--- oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
(original)
+++ oozie/trunk/client/src/main/java/org/apache/oozie/cli/OozieCLI.java Thu May
16 17:03:33 2013
@@ -56,13 +56,12 @@ import org.apache.oozie.client.BulkRespo
import org.apache.oozie.client.BundleJob;
import org.apache.oozie.client.CoordinatorAction;
import org.apache.oozie.client.CoordinatorJob;
-import org.apache.oozie.client.JMSConnectionInfo;
import org.apache.oozie.client.OozieClient;
+import org.apache.oozie.client.OozieClient.SYSTEM_MODE;
import org.apache.oozie.client.OozieClientException;
import org.apache.oozie.client.WorkflowAction;
import org.apache.oozie.client.WorkflowJob;
import org.apache.oozie.client.XOozieClient;
-import org.apache.oozie.client.OozieClient.SYSTEM_MODE;
import org.apache.oozie.client.rest.RestConstants;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
@@ -72,6 +71,8 @@ import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
+import com.google.common.annotations.VisibleForTesting;
+
/**
* Oozie command line utility.
*/
@@ -966,7 +967,8 @@ public class OozieCLI {
}
}
- private void printCoordJob(CoordinatorJob coordJob, String timeZoneId,
boolean verbose) {
+ @VisibleForTesting
+ void printCoordJob(CoordinatorJob coordJob, String timeZoneId, boolean
verbose) {
System.out.println("Job ID : " + coordJob.getId());
System.out.println(RULER);
@@ -1020,7 +1022,8 @@ public class OozieCLI {
}
}
- private void printBundleJob(BundleJob bundleJob, String timeZoneId,
boolean verbose) {
+ @VisibleForTesting
+ void printBundleJob(BundleJob bundleJob, String timeZoneId, boolean
verbose) {
System.out.println("Job ID : " + bundleJob.getId());
System.out.println(RULER);
@@ -1045,7 +1048,8 @@ public class OozieCLI {
}
}
- private void printCoordAction(CoordinatorAction coordAction, String
timeZoneId) {
+ @VisibleForTesting
+ void printCoordAction(CoordinatorAction coordAction, String timeZoneId) {
System.out.println("ID : " + maskIfNull(coordAction.getId()));
System.out.println(RULER);
@@ -1082,7 +1086,9 @@ public class OozieCLI {
}
- private void printWorkflowAction(WorkflowAction action, String timeZoneId,
boolean verbose) {
+ @VisibleForTesting
+ void printWorkflowAction(WorkflowAction action, String timeZoneId, boolean
verbose) {
+
System.out.println("ID : " + maskIfNull(action.getId()));
System.out.println(RULER);
@@ -1117,7 +1123,8 @@ public class OozieCLI {
private static final String COORD_ACTION_FORMATTER =
"%-43s%-10s%-37s%-10s%-21s%-21s";
private static final String BULK_RESPONSE_FORMATTER =
"%-13s%-38s%-13s%-41s%-10s%-38s%-21s%-38s";
- private void printJob(WorkflowJob job, String timeZoneId, boolean verbose)
throws IOException {
+ @VisibleForTesting
+ void printJob(WorkflowJob job, String timeZoneId, boolean verbose) throws
IOException {
System.out.println("Job ID : " + maskIfNull(job.getId()));
System.out.println(RULER);
@@ -1220,7 +1227,8 @@ public class OozieCLI {
}
}
- private void printCoordJobs(List<CoordinatorJob> jobs, String timeZoneId,
boolean verbose) throws IOException {
+ @VisibleForTesting
+ void printCoordJobs(List<CoordinatorJob> jobs, String timeZoneId, boolean
verbose) throws IOException {
if (jobs != null && jobs.size() > 0) {
if (verbose) {
System.out.println("Job ID" + VERBOSE_DELIMITER + "App Name" +
VERBOSE_DELIMITER + "App Path"
@@ -1266,7 +1274,8 @@ public class OozieCLI {
}
}
- private void printBulkJobs(List<BulkResponse> jobs, String timeZoneId,
boolean verbose) throws IOException {
+ @VisibleForTesting
+ void printBulkJobs(List<BulkResponse> jobs, String timeZoneId, boolean
verbose) throws IOException {
if (jobs != null && jobs.size() > 0) {
for (BulkResponse response : jobs) {
BundleJob bundle = response.getBundle();
@@ -1307,7 +1316,8 @@ public class OozieCLI {
}
}
- private void printBundleJobs(List<BundleJob> jobs, String timeZoneId,
boolean verbose) throws IOException {
+ @VisibleForTesting
+ void printBundleJobs(List<BundleJob> jobs, String timeZoneId, boolean
verbose) throws IOException {
if (jobs != null && jobs.size() > 0) {
if (verbose) {
System.out.println("Job ID" + VERBOSE_DELIMITER + "Bundle
Name" + VERBOSE_DELIMITER + "Bundle Path"
@@ -1423,7 +1433,8 @@ public class OozieCLI {
+
BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION));
}
- private void printJobs(List<WorkflowJob> jobs, String timeZoneId, boolean
verbose) throws IOException {
+ @VisibleForTesting
+ void printJobs(List<WorkflowJob> jobs, String timeZoneId, boolean verbose)
throws IOException {
if (jobs != null && jobs.size() > 0) {
if (verbose) {
System.out.println("Job ID" + VERBOSE_DELIMITER + "App Name" +
VERBOSE_DELIMITER + "App Path"
Modified:
oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestCLIParser.java
URL:
http://svn.apache.org/viewvc/oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestCLIParser.java?rev=1483447&r1=1483446&r2=1483447&view=diff
==============================================================================
--- oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestCLIParser.java
(original)
+++ oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestCLIParser.java
Thu May 16 17:03:33 2013
@@ -6,9 +6,9 @@
* 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.
@@ -17,13 +17,24 @@
*/
package org.apache.oozie.cli;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.PrintStream;
+
import junit.framework.TestCase;
+
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.junit.Test;
+
+import com.google.common.io.ByteStreams;
public class TestCLIParser extends TestCase {
+ @Test
public void testEmptyParser() throws Exception {
try {
CLIParser parser = new CLIParser("oozie", new String[]{});
@@ -35,6 +46,7 @@ public class TestCLIParser extends TestC
}
}
+ @Test
public void testCommandParser() throws Exception {
try {
CLIParser parser = new CLIParser("oozie", new String[]{});
@@ -48,6 +60,7 @@ public class TestCLIParser extends TestC
}
}
+ @Test
public void testCommandParserX() throws Exception {
Option opt = new Option("o", false, "O");
Options opts = new Options();
@@ -58,4 +71,44 @@ public class TestCLIParser extends TestC
assertEquals("-X", c.getCommandLine().getArgList().get(0));
assertEquals(3, c.getCommandLine().getArgList().size());
}
+
+ @Test
+ public void testCommandParserShowHelp() throws Exception {
+ String pattern = "oozie job <A>: AAAAA";
+ CLIParser parser = new CLIParser("oozie", new String[]{});
+ parser.addCommand("job", "<A>", "AAAAA", new Options(), false);
+ CLIParser.Command c = parser.parse(new String[]{"job", "b"});
+ assertTrue(readCommandOutput(parser, c).contains(pattern));
+ }
+
+ @Test
+ public void testCommandParserShowHelpWithOptions() throws Exception {
+ String pattern = "oozie job <OPTIONS> : job operations";
+ CLIParser parser = new CLIParser("oozie", new String[]{});
+ parser.addCommand("job", "", "job operations", createCommandOptions(),
false);
+ CLIParser.Command c = parser.parse(new String[]{ "job", "-url",
"test-name", "-verbose" });
+ assertTrue(readCommandOutput(parser, c).contains(pattern));
+ }
+
+ private Options createCommandOptions() {
+ Option oozie = new Option("url", true, "URL");
+ Option name = new Option("verbose", false, "verbose");
+ Options complexOptions = new Options();
+ complexOptions.addOption(oozie);
+ complexOptions.addOption(name);
+ return complexOptions;
+ }
+
+ private String readCommandOutput(CLIParser parser, CLIParser.Command c)
throws IOException {
+ ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+ PipedOutputStream pipeOut = new PipedOutputStream();
+ PipedInputStream pipeIn = new PipedInputStream(pipeOut, 1024 * 10);
+ System.setOut(new PrintStream(pipeOut));
+
+ parser.showHelp(c.getCommandLine());
+ pipeOut.close();
+ ByteStreams.copy(pipeIn, outBytes);
+ pipeIn.close();
+ return new String(outBytes.toByteArray());
+ }
}
Added:
oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestOozieCLIMethods.java
URL:
http://svn.apache.org/viewvc/oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestOozieCLIMethods.java?rev=1483447&view=auto
==============================================================================
---
oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestOozieCLIMethods.java
(added)
+++
oozie/trunk/client/src/test/java/org/apache/oozie/cli/TestOozieCLIMethods.java
Thu May 16 17:03:33 2013
@@ -0,0 +1,554 @@
+/**
+ * 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.oozie.cli;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import junit.framework.TestCase;
+
+import org.apache.oozie.client.BulkResponse;
+import org.apache.oozie.client.BundleJob;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.client.WorkflowJob;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.io.ByteStreams;
+
+public class TestOozieCLIMethods extends TestCase {
+
+ static final String jobIdPattern = "Job ID[\\s|:]+";
+ static final String jobNamePattern = "Job Name[\\s|:]+";
+ static final String workflowNamePattern = "Workflow Name[\\s|:]+";
+ static final String appPathPattern = "App Path[\\s|:]+";
+ static final String statusPattern = "Status[\\s|:]+RUNNING";
+ static final String actionIdPattern = "ID[\\s|:]+";
+ static final String actionJobIdPattern = "Job ID[\\s|:]+";
+ static final String actionNamePattern = "Name[\\s|:]+";
+
+ static class DataObject {
+ String deamonName;
+ String appName;
+ String appPath;
+ }
+
+ private abstract class OutputReaderTemplate {
+ protected String read() throws IOException {
+ ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+ PipedOutputStream pipeOut = new PipedOutputStream();
+ PipedInputStream pipeIn = new PipedInputStream(pipeOut, 1024 * 50);
+ System.setOut(new PrintStream(pipeOut));
+ execute();
+ pipeOut.close();
+ ByteStreams.copy(pipeIn, outBytes);
+ pipeIn.close();
+ return new String(outBytes.toByteArray());
+ }
+
+ abstract void execute() throws IOException;
+ }
+
+ /**
+ *
+ * Create {@code CoordinatorJob} and {@code CoordinatorActions} mocks,
+ * call {@code new OozieCLI().printCoordJob() },
+ * and validate {@code System.out} output on match with
+ * expected pattern.
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidatePrintCoordJobMethodOutput() throws IOException {
+ final DataObject dtObject = new DataObject() {
+ {
+ this.deamonName = "testCoordJob";
+ this.appName = "testCoordinatorJobApp";
+ this.appPath = "testCoordinatorJobAppPath";
+ }
+ };
+
+ CoordinatorJob coordJob = createCoordinatorJob(dtObject);
+
+ assertPrintCoordJobOutput(readCoordJobOutput(coordJob, true),
dtObject);
+ assertPrintCoordJobOutput(readCoordJobOutput(coordJob, false),
dtObject);
+ }
+
+ /**
+ *
+ * Create {@code CoordinatorAction} mock,
+ * call {@code new OozieCLI().printCoordAction() },
+ * and validate {@code System.out} output on match with
+ * expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidateReadPrintCoordActionOutput() throws IOException {
+ final DataObject dtObject = new DataObject() {
+ {
+ this.deamonName = "testCoordinatorAction";
+ this.appName = "testCoordinatorJobApp";
+ this.appPath = "testCoordinatorJobAppPath";
+ }
+ };
+
+ CoordinatorAction coordinatorAction =
createCoordinatorAction(dtObject);
+ assertPrintCoordActionOutput(readCoordAction(coordinatorAction),
dtObject);
+ }
+
+ /**
+ *
+ * Create {@code WorkflowJob}, {@code WorkflowAction} mocks,
+ * call {@code new OozieCLI().printJob() },
+ * and validate {@code System.out} on match with expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidatePrintJobOutput() throws IOException {
+ final DataObject dtObject = new DataObject() {
+ {
+ this.deamonName = "testWorkflowJob";
+ this.appName = "testWorkflowJobApp";
+ this.appPath = "testWorkflowJobAppPath";
+ }
+ };
+
+ WorkflowJob workflowJob = createWorkflowJob(dtObject);
+ assertPrintWorkflowJobOutput1(readWorkflowJobOutput(workflowJob,
true), dtObject);
+ assertPrintWorkflowJobOutput1(readWorkflowJobOutput(workflowJob,
false), dtObject);
+ }
+
+ /**
+ *
+ * Create {@code WorkflowAction} mock
+ * call {@code new OozieCLI().printWorkflowAction() }
+ * and validate {@code System.out} on match with expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidatePrintWorkflowActionOutput() throws IOException {
+ final DataObject dtObject = new DataObject() {
+ {
+ this.deamonName = "testWorkflowAction111";
+ this.appName = "testWorkflowActionAppName";
+ this.appPath = "unused";
+ }
+ };
+
+ WorkflowAction workflowAction = createWorkflowAction(dtObject);
+
assertPrintWorkflowActionOutput(readWorkflowActionOutput(workflowAction, true),
dtObject);
+
assertPrintWorkflowActionOutput(readWorkflowActionOutput(workflowAction,
false), dtObject);
+ }
+
+ /**
+ * Create {@code CoordinatorJob} mock,
+ * call {@code new OozieCLI().printCoordJobs() }
+ * and validate {@code System.out} on match with expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidatePrintCoordJobsOutput() throws IOException {
+ final DataObject dtObject1 = new DataObject() {
+ {
+ this.deamonName = "testCoordJob1";
+ this.appName = "testCoordinatorJobApp1";
+ this.appPath = "testCoordinatorJobAppPath1";
+ }
+ };
+ final DataObject dtObject2 = new DataObject() {
+ {
+ this.deamonName = "testCoordJob2";
+ this.appName = "testCoordinatorJobApp2";
+ this.appPath = "testCoordinatorJobAppPath2";
+ }
+ };
+
+ final ImmutableList<CoordinatorJob> coordJobs =
+ ImmutableList.of(createCoordinatorJob(dtObject1),
createCoordinatorJob(dtObject2));
+
+ Pattern pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" +
+ dtObject1.appName + "[\\s]+" + dtObject1.appPath);
+ assertPrintCoordJobsOutput(readCoordJobsOutput(coordJobs, true),
pattern);
+
+ pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" +
dtObject1.appName);
+ assertPrintCoordJobsOutput(readCoordJobsOutput(coordJobs, false),
pattern);
+ }
+
+ /**
+ * Create {@code CoordinatorJob} mock,
+ * call {@code new OozieCLI().printJobs() }
+ * and validate {@code System.out} on match with expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidatePrintJobsOutput() throws IOException {
+ final DataObject dtObject1 = new DataObject() {
+ {
+ this.deamonName = "testWorkflowJob1";
+ this.appName = "testWorkflowJobApp1";
+ this.appPath = "testWorkflowJobAppPath1";
+ }
+ };
+ final DataObject dtObject2 = new DataObject() {
+ {
+ this.deamonName = "testWorkflowJob2";
+ this.appName = "testWorkflowJobApp2";
+ this.appPath = "testWorkflowJobAppPath2";
+ }
+ };
+
+ ImmutableList<WorkflowJob> workflowJobs =
ImmutableList.of(createWorkflowJob(dtObject1),
+ createWorkflowJob(dtObject2));
+
+ Pattern pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" +
+ dtObject1.appName + "[\\s]+" + dtObject1.appPath);
+ assertPrintWorkflowJobOutput(readWorkflowJobsOutput(workflowJobs,
true), pattern);
+
+ pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" +
dtObject1.appName);
+ assertPrintWorkflowJobOutput(readWorkflowJobsOutput(workflowJobs,
false), pattern);
+ }
+
+ /**
+ * Create list of {@code BundleJob} mocks,
+ * call {@code new OozieCLI().printBundleJobs()}
+ * and validate {@code System.out} on match with expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidationPrintBundleJobsOutput() throws IOException {
+ final DataObject dtObject1 = new DataObject() {
+ {
+ this.deamonName = "testBundleJob1";
+ this.appName = "testBundleJobApp1";
+ this.appPath = "testBundleJobAppPath1";
+ }
+ };
+
+ final DataObject dtObject2 = new DataObject() {
+ {
+ this.deamonName = "testBundleJob2";
+ this.appName = "testBundleJobApp2";
+ this.appPath = "testBundleJobAppPath2";
+ }
+ };
+
+ ImmutableList<BundleJob> bundleJobs =
ImmutableList.of(createBundleJob(dtObject1), createBundleJob(dtObject2));
+
+ Pattern pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+"
+ + dtObject1.appName + "[\\s]+" + dtObject1.appPath);
+ assertPrintBundleJobsOutput(readBundleJobsOutput(bundleJobs, true),
pattern);
+
+ pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" +
dtObject1.appName);
+ assertPrintBundleJobsOutput(readBundleJobsOutput(bundleJobs, false),
pattern);
+ }
+
+ /**
+ * Create {@code BundleJob} mock,
+ * call {@code new OozieCLI().printBundleJobs()}
+ * and validate {@code System.out} on match with expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidationPrintBundleJobOutput() throws IOException {
+ final DataObject dtObject = new DataObject() {
+ {
+ this.deamonName = "testBundleJob99";
+ this.appName = "testBundleJobApp99";
+ this.appPath = "testBundleJobAppPath99";
+ }
+ };
+
+
assertPrintBundleJobsOutput(readBundleJobOutput(createBundleJob(dtObject),
true), dtObject);
+
assertPrintBundleJobsOutput(readBundleJobOutput(createBundleJob(dtObject),
false), dtObject);
+ }
+
+ /**
+ * Create list of {@code BulkResponse} mock,
+ * call {@code new OozieCLI().printBundleJobs()}
+ * and validate {@code System.out} on match with expected pattern
+ * <p>
+ * Method do pass only if output matched with predefined pattern
+ * </p>
+ */
+ @Test
+ public void testValidationPrintBulkJobsOutput() throws IOException {
+ final DataObject dtObject = new DataObject() {
+ {
+ this.deamonName = "";
+ this.appName = "testBundleName";
+ this.appPath = "";
+ }
+ };
+
+ Pattern pattern = Pattern.compile("Bundle Name[ |:]+" +
dtObject.appName);
+
assertPrintBulkResponseOutput(readBulkResponseOutput(ImmutableList.of(createBulkResponse(dtObject)),
true), pattern);
+
+ pattern = Pattern.compile(dtObject.appName + "-" +"\\s+" +
dtObject.appName + "-");
+
assertPrintBulkResponseOutput(readBulkResponseOutput(ImmutableList.of(createBulkResponse(dtObject)),
false), pattern);
+ }
+
+ private String readBulkResponseOutput(final List<BulkResponse>
bulkResponses, final boolean verbose) throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printBulkJobs(bulkResponses, null, verbose);
+ }
+ }.read();
+ }
+
+ private String readBundleJobOutput(final BundleJob bundleJob, final
boolean verbose) throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printBundleJob(bundleJob, null, verbose);
+ }
+ }.read();
+ }
+
+ private String readBundleJobsOutput(final ImmutableList<BundleJob>
bundleJobs, final boolean verbose)
+ throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printBundleJobs(bundleJobs, null, verbose);
+ }
+ }.read();
+ }
+
+ private String readWorkflowJobOutput(final WorkflowJob workflowJob, final
boolean verbose)
+ throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printJob(workflowJob, null, verbose);
+ }
+ }.read();
+ }
+
+ private String readWorkflowJobsOutput(final ImmutableList<WorkflowJob>
workflowJobs, final boolean verbose)
+ throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printJobs(workflowJobs, null, verbose);
+ }
+ }.read();
+ }
+
+ private String readCoordJobOutput(final CoordinatorJob coordJob, final
boolean verbose)
+ throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printCoordJob(coordJob, null, verbose);
+ }
+ }.read();
+ }
+
+ private String readCoordJobsOutput(final ImmutableList<CoordinatorJob>
coordJobs, final boolean verbose)
+ throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printCoordJobs(coordJobs, null, verbose);
+ }
+ }.read();
+ }
+
+ private String readWorkflowActionOutput(final WorkflowAction
workflowAction, final boolean verbose)
+ throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printWorkflowAction(workflowAction, null,
verbose);
+ }
+ }.read();
+ }
+
+ private String readCoordAction(final CoordinatorAction coordinatorAction)
+ throws IOException {
+ return new OutputReaderTemplate() {
+ @Override
+ void execute() throws IOException {
+ new OozieCLI().printCoordAction(coordinatorAction, null);
+ }
+ }.read();
+ }
+
+ private void assertPrintBulkResponseOutput(String bulkResponseOutput,
Pattern pattern) {
+ assertTrue("assertPrintBulkResponseOutput error",
pattern.matcher(bulkResponseOutput).find());
+ }
+
+ private void assertPrintBundleJobsOutput(String bundleJobOutput,
DataObject dtObject) {
+ assertTrue("assertPrintBundleJobsOutput Job ID error",
Pattern.compile(jobIdPattern + dtObject.deamonName)
+ .matcher(bundleJobOutput).find());
+ assertTrue("assertPrintBundleJobsOutput Job Name error",
Pattern.compile(jobNamePattern + dtObject.appName)
+ .matcher(bundleJobOutput).find());
+ assertTrue("assertPrintBundleJobsOutput App Path error",
Pattern.compile(appPathPattern + dtObject.appPath)
+ .matcher(bundleJobOutput).find());
+ }
+
+ private void assertPrintBundleJobsOutput(String bundleJobsOutput, Pattern
pattern) {
+ assertTrue("assertPrintWorkflowJobOutput error",
pattern.matcher(bundleJobsOutput).find());
+ }
+
+ private void assertPrintWorkflowJobOutput(String workflowJobOutput,
Pattern pattern) {
+ assertTrue("assertPrintWorkflowJobOutput error",
pattern.matcher(workflowJobOutput).find());
+ }
+
+ private void assertPrintCoordJobsOutput(String coordJobsOutput, Pattern
pattern) {
+ assertTrue("assertPrintCoordJobsOutput error",
pattern.matcher(coordJobsOutput).find());
+ }
+
+ private void assertPrintWorkflowActionOutput(String workflowActionOutput,
DataObject dtObject) {
+ assertTrue("assertPrintWorkflowActionOutput ID error",
Pattern.compile(actionIdPattern + dtObject.deamonName)
+ .matcher(workflowActionOutput).find());
+ assertTrue("assertPrintWorkflowActionOutput Name error",
Pattern.compile(actionNamePattern + dtObject.appName)
+ .matcher(workflowActionOutput).find());
+ }
+
+ private void assertPrintWorkflowJobOutput1(String workflowJobOutput,
DataObject dtObject) {
+ assertTrue("assertPrintWorkflowJobOutput Job ID error",
Pattern.compile(jobIdPattern + dtObject.deamonName)
+ .matcher(workflowJobOutput).find());
+ assertTrue("assertPrintWorkflowJobOutput Job Name error",
Pattern.compile(workflowNamePattern + dtObject.appName)
+ .matcher(workflowJobOutput).find());
+ assertTrue("assertPrintWorkflowJobOutput App Path error",
Pattern.compile(appPathPattern + dtObject.appPath)
+ .matcher(workflowJobOutput).find());
+ }
+
+ private void assertPrintCoordActionOutput(String output, DataObject
dtObject) {
+ assertTrue("assertPrintCoordActionOutput Job ID error",
Pattern.compile(actionIdPattern + dtObject.deamonName)
+ .matcher(output).find());
+ assertTrue("assertPrintCoordActionOutput ID error ",
Pattern.compile(actionJobIdPattern + dtObject.appName)
+ .matcher(output).find());
+ }
+
+ private void assertPrintCoordJobOutput(String line, DataObject dtObject) {
+ assertTrue("assertPrintCoordJobOutput Job ID error",
Pattern.compile(jobIdPattern + dtObject.deamonName)
+ .matcher(line).find());
+ assertTrue("assertPrintCoordJobOutput Job Name error",
Pattern.compile(jobNamePattern + dtObject.appName)
+ .matcher(line).find());
+ assertTrue("assertPrintCoordJobOutput App Path error",
Pattern.compile(appPathPattern + dtObject.appPath)
+ .matcher(line).find());
+ assertTrue("assertPrintCoordJobOutput Status error",
Pattern.compile(statusPattern).matcher(line).find());
+ }
+
+ private static BundleJob createBundleJob(DataObject dtObject) {
+ BundleJob bundleJobMock = mock(BundleJob.class);
+ when(bundleJobMock.getId()).thenReturn(dtObject.deamonName);
+ when(bundleJobMock.getAppName()).thenReturn(dtObject.appName);
+ when(bundleJobMock.getAppPath()).thenReturn(dtObject.appPath);
+
when(bundleJobMock.getStatus()).thenReturn(org.apache.oozie.client.Job.Status.RUNNING);
+
+ CoordinatorJob coordinatorJobMock = createCoordinatorJob(dtObject);
+
when(bundleJobMock.getCoordinators()).thenReturn(ImmutableList.of(coordinatorJobMock));
+ return bundleJobMock;
+ }
+
+ private static CoordinatorJob createCoordinatorJob(DataObject dtObject) {
+ CoordinatorJob coordinatorJobMock = mock(CoordinatorJob.class);
+ when(coordinatorJobMock.getId()).thenReturn(dtObject.deamonName);
+ when(coordinatorJobMock.getAppName()).thenReturn(dtObject.appName);
+ when(coordinatorJobMock.getAppPath()).thenReturn(dtObject.appPath);
+ when(coordinatorJobMock.getConcurrency()).thenReturn(15);
+
when(coordinatorJobMock.getStatus()).thenReturn(CoordinatorJob.Status.RUNNING);
+ when(coordinatorJobMock.getUser()).thenReturn("test");
+ when(coordinatorJobMock.getGroup()).thenReturn("test-group");
+
+ ImmutableList.Builder<CoordinatorAction> builder =
ImmutableList.builder();
+
+ for (final String id : Arrays.asList("1", "2"))
+ builder.add(createCoordinatorAction(new DataObject() {
+ {
+ this.deamonName = id;
+ this.appName = "testCoordinatorAction";
+ }
+ }));
+
+ when(coordinatorJobMock.getActions()).thenReturn(builder.build());
+ return coordinatorJobMock;
+ }
+
+ private WorkflowJob createWorkflowJob(DataObject dtObject) {
+ WorkflowJob workflowJobMock = mock(WorkflowJob.class);
+ when(workflowJobMock.getId()).thenReturn(dtObject.deamonName);
+ when(workflowJobMock.getAppName()).thenReturn(dtObject.appName);
+ when(workflowJobMock.getAppPath()).thenReturn(dtObject.appPath);
+
when(workflowJobMock.getStatus()).thenReturn(WorkflowJob.Status.RUNNING);
+ WorkflowAction ac = createWorkflowAction(dtObject);
+ WorkflowAction ac0 = createWorkflowAction(dtObject);
+ when(workflowJobMock.getActions()).thenReturn(Arrays.asList(ac, ac0));
+ return workflowJobMock;
+ }
+
+ private static CoordinatorAction createCoordinatorAction(DataObject
dtObject) {
+ CoordinatorAction crdActionMock = mock(CoordinatorAction.class);
+ when(crdActionMock.getId()).thenReturn(dtObject.deamonName);
+ when(crdActionMock.getJobId()).thenReturn(dtObject.appName);
+ when(crdActionMock.getActionNumber()).thenReturn(11);
+
when(crdActionMock.getStatus()).thenReturn(CoordinatorAction.Status.SUBMITTED);
+ return crdActionMock;
+ }
+
+ private static WorkflowAction createWorkflowAction(DataObject dtObject) {
+ WorkflowAction workflowActionMock = mock(WorkflowAction.class);
+ when(workflowActionMock.getId()).thenReturn(dtObject.deamonName);
+ when(workflowActionMock.getName()).thenReturn(dtObject.appName);
+ return workflowActionMock;
+ }
+
+ private static BulkResponse createBulkResponse(DataObject dtObject) {
+ BulkResponse bulkResponse = mock(BulkResponse.class);
+
+ BundleJob bundleJob = createBundleJob(dtObject);
+ when(bulkResponse.getBundle()).thenReturn(bundleJob);
+
+ CoordinatorAction coordinatorAction =
createCoordinatorAction(dtObject);
+ when(bulkResponse.getAction()).thenReturn(coordinatorAction);
+
+ CoordinatorJob coordinatorJob = createCoordinatorJob(dtObject);
+ when(bulkResponse.getCoordinator()).thenReturn(coordinatorJob);
+ return bulkResponse;
+ }
+}
Modified:
oozie/trunk/core/src/test/java/org/apache/oozie/client/TestOozieCLI.java
URL:
http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/client/TestOozieCLI.java?rev=1483447&r1=1483446&r2=1483447&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/client/TestOozieCLI.java
(original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/client/TestOozieCLI.java
Thu May 16 17:03:33 2013
@@ -18,7 +18,9 @@
package org.apache.oozie.client;
import java.io.DataOutputStream;
+import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Properties;
@@ -36,6 +38,7 @@ import org.apache.oozie.servlet.V1JobSer
import org.apache.oozie.servlet.V1JobsServlet;
import org.apache.oozie.servlet.V2AdminServlet;
import org.apache.oozie.servlet.V2JobServlet;
+import org.apache.oozie.util.IOUtils;
import org.apache.oozie.util.XConfiguration;
//hardcoding options instead using constants on purpose, to detect changes to
option names if any and correct docs.
@@ -160,6 +163,7 @@ public class TestOozieCLI extends DagSer
public void testSubmit() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
int wfCount = MockDagEngineService.INIT_WF_COUNT;
@@ -202,6 +206,7 @@ public class TestOozieCLI extends DagSer
public void testSubmitPig() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
int wfCount = MockDagEngineService.INIT_WF_COUNT;
@@ -221,6 +226,7 @@ public class TestOozieCLI extends DagSer
public void testSubmitMapReduce() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
int wfCount = MockDagEngineService.INIT_WF_COUNT;
@@ -240,6 +246,7 @@ public class TestOozieCLI extends DagSer
public void testSubmitDoAs() throws Exception {
setSystemProperty("oozie.authentication.simple.anonymous.allowed",
"false");
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
@@ -259,6 +266,7 @@ public class TestOozieCLI extends DagSer
public void testSubmitWithPropertyArguments() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
int wfCount = MockDagEngineService.INIT_WF_COUNT;
@@ -282,6 +290,7 @@ public class TestOozieCLI extends DagSer
public void testRun() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
Path appPath = new Path(getFsTestCaseDir(), "app");
getFileSystem().mkdirs(appPath);
@@ -306,6 +315,7 @@ public class TestOozieCLI extends DagSer
*/
public void testRunWithDebug() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
Path appPath = new Path(getFsTestCaseDir(), "app");
getFileSystem().mkdirs(appPath);
@@ -325,6 +335,7 @@ public class TestOozieCLI extends DagSer
public void testStart() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
String[] args = new String[]{"job", "-oozie", oozieUrl,
"-start", MockDagEngineService.JOB_ID + "1" +
@@ -343,6 +354,7 @@ public class TestOozieCLI extends DagSer
public void testSuspend() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
String[] args = new String[]{"job", "-oozie", oozieUrl,
"-suspend", MockDagEngineService.JOB_ID + "1" +
@@ -360,6 +372,7 @@ public class TestOozieCLI extends DagSer
public void testResume() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
String[] args = new String[]{"job", "-oozie", oozieUrl,
"-resume", MockDagEngineService.JOB_ID + "1" +
@@ -377,6 +390,7 @@ public class TestOozieCLI extends DagSer
public void testKill() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
String[] args = new String[]{"job", "-oozie", oozieUrl,
"-kill", MockDagEngineService.JOB_ID + "1" +
@@ -394,6 +408,7 @@ public class TestOozieCLI extends DagSer
public void testReRun() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
Path appPath = new Path(getFsTestCaseDir(), "app");
getFileSystem().mkdirs(appPath);
@@ -416,6 +431,7 @@ public class TestOozieCLI extends DagSer
*/
public void testCoordReRun1() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
Path appPath = new Path(getFsTestCaseDir(), "app");
getFileSystem().mkdirs(appPath);
@@ -439,6 +455,7 @@ public class TestOozieCLI extends DagSer
*/
public void testCoordReRun2() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
Path appPath = new Path(getFsTestCaseDir(), "app");
getFileSystem().mkdirs(appPath);
@@ -456,12 +473,60 @@ public class TestOozieCLI extends DagSer
}
/**
+ *
+ * Test: oozie -rerun coord_job_id -action 0 -refresh
+ *
+ */
+ public void testCoordReRun3() throws Exception {
+ runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ Path appPath = new Path(getFsTestCaseDir(), "app");
+ getFileSystem().mkdirs(appPath);
+ getFileSystem().create(new Path(appPath,
"coordinator.xml")).close();
+ String oozieUrl = getContextURL();
+ String[] args = new String[] { "job", "-oozie", oozieUrl,
"-rerun",
+ MockCoordinatorEngineService.JOB_ID + "0",
+ "-action", "0", "-refresh" };
+ assertEquals(0, new OozieCLI().run(args));
+ assertEquals(RestConstants.JOB_COORD_ACTION_RERUN,
MockCoordinatorEngineService.did);
+ assertTrue(MockCoordinatorEngineService.started.get(0));
+ return null;
+ }
+ });
+ }
+ /**
+ *
+ * Test: oozie -rerun coord_job_id -action 0 -nocleanup
+ *
+ */
+ public void testCoordReRun4() throws Exception {
+ runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ Path appPath = new Path(getFsTestCaseDir(), "app");
+ getFileSystem().mkdirs(appPath);
+ getFileSystem().create(new Path(appPath,
"coordinator.xml")).close();
+ String oozieUrl = getContextURL();
+ String[] args = new String[] { "job", "-oozie", oozieUrl,
"-rerun",
+ MockCoordinatorEngineService.JOB_ID + "0",
+ "-action", "0", "-nocleanup" };
+ assertEquals(0, new OozieCLI().run(args));
+ assertEquals(RestConstants.JOB_COORD_ACTION_RERUN,
MockCoordinatorEngineService.did);
+ assertTrue(MockCoordinatorEngineService.started.get(0));
+ return null;
+ }
+ });
+ }
+
+ /**
* Negative Test: oozie -rerun coord_job_id -date 2009-12-15T01:00Z
-action 1
*
* @throws Exception
*/
public void testCoordReRunNeg1() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
Path appPath = new Path(getFsTestCaseDir(), "app");
getFileSystem().mkdirs(appPath);
@@ -485,6 +550,7 @@ public class TestOozieCLI extends DagSer
*/
public void testCoordReRunNeg2() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
Path appPath = new Path(getFsTestCaseDir(), "app");
getFileSystem().mkdirs(appPath);
@@ -500,8 +566,59 @@ public class TestOozieCLI extends DagSer
});
}
+ /**
+ *
+ * Negative Test: date or action option expected
+ * @throws Exception
+ *
+ */
+ public void testCoordReRunNeg3() throws Exception {
+ runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ Path appPath = new Path(getFsTestCaseDir(), "app");
+ getFileSystem().mkdirs(appPath);
+ getFileSystem().create(new Path(appPath,
"coordinator.xml")).close();
+ String oozieUrl = getContextURL();
+
+ String[] args = new String[] {"job", "-oozie", oozieUrl,
"-config", createConfigFile(appPath.toString()),
+ "-rerun", MockCoordinatorEngineService.JOB_ID + "0" };
+ assertEquals(-1, new OozieCLI().run(args));
+ assertNull(MockCoordinatorEngineService.did);
+ assertFalse(MockCoordinatorEngineService.started.get(1));
+ return null;
+ }
+ });
+ }
+
+ /**
+ * Negative Test: Invalid options provided for rerun: eitherdate or action
expected. Don't use both at the same time
+ * @throws Exception
+ */
+ public void testCoordReRunNeg4() throws Exception {
+ runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ Path appPath = new Path(getFsTestCaseDir(), "app");
+ getFileSystem().mkdirs(appPath);
+ getFileSystem().create(new Path(appPath,
"coordinator.xml")).close();
+ String oozieUrl = getContextURL();
+
+ String[] args = new String[] {"job", "-oozie", oozieUrl,
"-config", createConfigFile(appPath.toString()),
+ "-rerun", MockCoordinatorEngineService.JOB_ID + "0",
+ "-date", "2009-12-15T01:00Z", "-action", "1"};
+
+ assertEquals(-1, new OozieCLI().run(args));
+ assertNull(MockCoordinatorEngineService.did);
+ assertFalse(MockCoordinatorEngineService.started.get(1));
+ return null;
+ }
+ });
+ }
+
public void testJobStatus() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
MockDagEngineService.reset();
@@ -535,6 +652,7 @@ public class TestOozieCLI extends DagSer
public void testJobsStatus() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
String[] args = new String[]{"jobs", "-len", "3", "-offset",
"2", "-oozie", oozieUrl, "-filter",
@@ -562,6 +680,7 @@ public class TestOozieCLI extends DagSer
public void testHeaderPropagation() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
HeaderTestingVersionServlet.OOZIE_HEADERS.clear();
setSystemProperty(OozieCLI.WS_HEADER_PREFIX + "header",
"test");
@@ -581,6 +700,7 @@ public class TestOozieCLI extends DagSer
public void testOozieStatus() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
HeaderTestingVersionServlet.OOZIE_HEADERS.clear();
@@ -597,6 +717,7 @@ public class TestOozieCLI extends DagSer
public void testServerBuildVersion() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
HeaderTestingVersionServlet.OOZIE_HEADERS.clear();
@@ -616,6 +737,7 @@ public class TestOozieCLI extends DagSer
public void testJobInfo() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
MockDagEngineService.reset();
@@ -646,6 +768,7 @@ public class TestOozieCLI extends DagSer
public void testJobLog() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
MockDagEngineService.reset();
@@ -654,6 +777,14 @@ public class TestOozieCLI extends DagSer
assertEquals(0, new OozieCLI().run(args));
assertEquals(RestConstants.JOB_SHOW_LOG,
MockDagEngineService.did);
+ args = new String[]{"job", "-oozie", oozieUrl, "-log",
MockCoordinatorEngineService.JOB_ID + "0"};
+ assertEquals(0, new OozieCLI().run(args));
+ assertEquals(RestConstants.JOB_SHOW_LOG,
MockDagEngineService.did);
+
+ args = new String[]{"job", "-oozie", oozieUrl, "-log",
MockCoordinatorEngineService.JOB_ID + "0",
+ "-action", "0", "-date",
"2009-12-16T01:00Z"};
+ assertEquals(0, new OozieCLI().run(args));
+ assertEquals(RestConstants.JOB_SHOW_LOG,
MockDagEngineService.did);
return null;
}
@@ -662,6 +793,7 @@ public class TestOozieCLI extends DagSer
public void testJobDefinition() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
String oozieUrl = getContextURL();
MockDagEngineService.reset();
@@ -678,6 +810,7 @@ public class TestOozieCLI extends DagSer
public void testPropertiesWithTrailingSpaces() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
MockDagEngineService.reset();
String oozieUrl = getContextURL();
@@ -701,6 +834,7 @@ public class TestOozieCLI extends DagSer
public void testAdminQueueDump() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
public Void call() throws Exception {
HeaderTestingVersionServlet.OOZIE_HEADERS.clear();
@@ -716,5 +850,82 @@ public class TestOozieCLI extends DagSer
public void testInfo() throws Exception {
String[] args = new String[]{"info"};
assertEquals(0, new OozieCLI().run(args));
+
+ args = new String[]{"info", "-timezones"};
+ assertEquals(0, new OozieCLI().run(args));
+ }
+
+ public void testValidateWorkFlowCommand() throws Exception {
+ runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ String validFileName = "./test-workflow-app.xml";
+ String invalidFileName = "./test-invalid-workflow-app.xml";
+
+ String validContent = "<workflow-app
xmlns=\"uri:oozie:workflow:0.2\" name=\"no-op-wf\"> "+
+ " <start to=\"end\"/> <end name=\"end\"/>
</workflow-app>";
+ String invalidContent = "<workflow-app
xmlns=\"uri:oozie:workflow:0.2\" name=\"f\"> "+
+ " <tag=\"end\"/> <tag=\"end\"/> </workflow-app>";
+ File validfile = new File(validFileName);
+ File invalidfile = new File(invalidFileName);
+ validfile.delete();
+ invalidfile.delete();
+
+
+ IOUtils.copyCharStream(new StringReader(validContent), new
FileWriter(validfile));
+ String [] args = new String[] { "validate", validFileName };
+ assertEquals(0, new OozieCLI().run(args));
+
+ IOUtils.copyCharStream(new StringReader(invalidContent), new
FileWriter(invalidfile));
+ args = new String[] { "validate", invalidFileName };
+ assertEquals(-1, new OozieCLI().run(args));
+
+ return null;
+ }
+ });
+ }
+
+ /**
+ *
+ * oozie -change coord_job_id -value concurrency=10
+ *
+ */
+ public void testChangeValue() throws Exception {
+ runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ Path appPath = new Path(getFsTestCaseDir(), "app");
+ getFileSystem().mkdirs(appPath);
+ getFileSystem().create(new Path(appPath,
"coordinator.xml")).close();
+ String oozieUrl = getContextURL();
+
+ String[] args = new String[] {"job", "-oozie", oozieUrl,
"-change",
+ MockCoordinatorEngineService.JOB_ID + "0", "-value",
"concurrency=10" };
+
+ assertEquals(0, new OozieCLI().run(args));
+ assertEquals(RestConstants.JOB_ACTION_CHANGE,
MockCoordinatorEngineService.did);
+
+ return null;
+ }
+ });
}
+
+ /**
+ * Could not authenticate, Authentication failed, status: 404, message:
Not Found
+ */
+ public void testSlaEvents() throws Exception {
+ runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new
Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ Path appPath = new Path(getFsTestCaseDir(), "app");
+ getFileSystem().mkdirs(appPath);
+ String oozieUrl = getContextURL();
+ String[] args = new String[] {"sla", "-oozie", oozieUrl,
"-len", "1" };
+
+ assertEquals(-1, new OozieCLI().run(args));
+
+ return null;
+ }
+ });
+ }
}
Modified: oozie/trunk/release-log.txt
URL:
http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1483447&r1=1483446&r2=1483447&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Thu May 16 17:03:33 2013
@@ -1,5 +1,6 @@
-- Oozie 4.1.0 release (trunk - unreleased)
+OOZIE-1328 Cover package org.apache.oozie.cli with unit tests (vbondarev via
virag)
OOZIE-1327 enhance unit-test coverage of package org.apache.oozie (iveselovsky
via rkanter)
OOZIE-1356 Bundle job in PAUSEWITHERROR state does not goto SUSPENDEDWITHERROR
state on suspending it (bowenzhangusa via virag)
OOZIE-1313 coverage fix for org.apache.oozie.client (aleksgor via virag)