You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by rk...@apache.org on 2013/04/12 22:30:59 UTC

svn commit: r1467452 - in /oozie/trunk: core/src/test/java/org/apache/oozie/action/ssh/TestSshActionExecutor.java release-log.txt

Author: rkanter
Date: Fri Apr 12 20:30:58 2013
New Revision: 1467452

URL: http://svn.apache.org/r1467452
Log:
OOZIE-1307 Cover package org.apache.oozie.action.ssh with unit tests (vbondarev via rkanter)

Modified:
    oozie/trunk/core/src/test/java/org/apache/oozie/action/ssh/TestSshActionExecutor.java
    oozie/trunk/release-log.txt

Modified: oozie/trunk/core/src/test/java/org/apache/oozie/action/ssh/TestSshActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/action/ssh/TestSshActionExecutor.java?rev=1467452&r1=1467451&r2=1467452&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/action/ssh/TestSshActionExecutor.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/action/ssh/TestSshActionExecutor.java Fri Apr 12 20:30:58 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,7 +17,8 @@
  */
 package org.apache.oozie.action.ssh;
 
-import org.apache.oozie.service.CallbackService;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
 
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -29,17 +30,19 @@ import java.util.Properties;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
-import org.apache.oozie.client.WorkflowJob;
-import org.apache.oozie.client.OozieClient;
-import org.apache.oozie.client.WorkflowAction.Status;
 import org.apache.oozie.WorkflowActionBean;
 import org.apache.oozie.WorkflowJobBean;
 import org.apache.oozie.action.ActionExecutor;
 import org.apache.oozie.action.ActionExecutorException;
-import org.apache.oozie.service.WorkflowAppService;
+import org.apache.oozie.client.OozieClient;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.client.WorkflowAction.Status;
+import org.apache.oozie.client.WorkflowJob;
+import org.apache.oozie.service.CallbackService;
 import org.apache.oozie.service.Services;
 import org.apache.oozie.service.UUIDService;
 import org.apache.oozie.service.UUIDService.ApplicationType;
+import org.apache.oozie.service.WorkflowAppService;
 import org.apache.oozie.test.XFsTestCase;
 import org.apache.oozie.util.ELEvaluator;
 import org.apache.oozie.util.PropertiesUtils;
@@ -536,6 +539,111 @@ public class TestSshActionExecutor exten
         assertEquals("something", PropertiesUtils.stringToProperties(action.getData()).getProperty("prop1"));
     }
 
+    /**
+     * test {@code SshActionExecutor.check()} method with invalid
+     * xml configuration
+     */
+    public void testSshCheckWithInvalidXml() throws Exception  {
+        String baseDir = getTestCaseDir();
+        Path appPath = new Path(getNameNodeUri(), baseDir);
+
+        XConfiguration protoConf = new XConfiguration();
+        protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
+
+        XConfiguration wfConf = new XConfiguration();
+        wfConf.set(OozieClient.APP_PATH, appPath.toString());
+
+        WorkflowJobBean workflow = new WorkflowJobBean();
+        workflow.setConf(wfConf.toXmlString());
+        workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
+        workflow.setProtoActionConf(protoConf.toXmlString());
+        workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
+
+        WorkflowActionBean action = new WorkflowActionBean();
+        action.setId("actionId");
+        action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'> invalid body ");
+        action.setName("ssh");
+        final SshActionExecutor ssh = new SshActionExecutor();
+        final Context context = new Context(workflow, action);
+        try {
+            ssh.check(context, action);
+            fail("testSshCheckWithInvalidXml expected ex error");
+        }
+        catch (ActionExecutorException aex) {
+            //ActionExecutorException should be thrown to pass the test
+            assertEquals("ERR_XML_PARSE_FAILED", aex.getErrorCode());
+            assertEquals(ActionExecutorException.ErrorType.ERROR, aex.getErrorType());
+        }
+    }
+
+    /**
+     * test {@code SshActionExecutor.start()} method with invalid
+     * xml configuration
+     */
+    public void testSshStartWithInvalidXml() throws Exception {
+        String baseDir = getTestCaseDir();
+        Path appPath = new Path(getNameNodeUri(), baseDir);
+        XConfiguration protoConf = new XConfiguration();
+        protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
+
+        XConfiguration wfConf = new XConfiguration();
+        wfConf.set(OozieClient.APP_PATH, appPath.toString());
+
+        WorkflowJobBean workflow = new WorkflowJobBean();
+        workflow.setConf(wfConf.toXmlString());
+        workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
+        workflow.setProtoActionConf(protoConf.toXmlString());
+        workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
+
+        WorkflowActionBean action = new WorkflowActionBean();
+        action.setId("actionId");
+        action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'> invalid body ");
+        action.setName("ssh");
+        final SshActionExecutor ssh = new SshActionExecutor();
+        final Context context = new Context(workflow, action);
+        try {
+            ssh.start(context, action);
+            fail("testSshStartWithInvalidXml expected ex error");
+        } catch (ActionExecutorException ex) {
+            //ActionExecutorException should be thrown to pass the test
+        }
+    }
+
+    /**
+     * test {@code SshActionExecutor.start()/kill()}
+     * sequence call
+     */
+    public void testJobStartAndKill() throws Exception {
+        String baseDir = getTestCaseDir();
+        Path appPath = new Path(getNameNodeUri(), baseDir);
+        XConfiguration protoConf = new XConfiguration();
+        protoConf.setStrings(WorkflowAppService.HADOOP_USER, getTestUser());
+
+        XConfiguration wfConf = new XConfiguration();
+        wfConf.set(OozieClient.APP_PATH, appPath.toString());
+
+        WorkflowJobBean workflow = new WorkflowJobBean();
+        workflow.setConf(wfConf.toXmlString());
+        workflow.setAppPath(wfConf.get(OozieClient.APP_PATH));
+        workflow.setProtoActionConf(protoConf.toXmlString());
+        workflow.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.WORKFLOW));
+
+        WorkflowActionBean action = new WorkflowActionBean();
+        action.setId("actionId");
+        action.setConf("<ssh xmlns='" + getActionXMLSchema() + "'>" +
+                       "<host>localhost</host>" +
+                       "<command>top</command>" +
+                       "<capture-output/>" +
+                       "</ssh>");
+        action.setName("ssh");
+        final SshActionExecutor ssh = new SshActionExecutor();
+        final Context context = new Context(workflow, action);
+        ssh.start(context, action);
+        Context contextMock = mock(Context.class);
+        ssh.kill(contextMock, action);
+        verify(contextMock).setEndData(WorkflowAction.Status.KILLED, "ERROR");
+    }
+
     @Override
     protected void tearDown() throws Exception {
         services.destroy();

Modified: oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1467452&r1=1467451&r2=1467452&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Fri Apr 12 20:30:58 2013
@@ -1,5 +1,6 @@
 -- Oozie 4.1.0 release (trunk - unreleased)
 
+OOZIE-1307 Cover package org.apache.oozie.action.ssh with unit tests (vbondarev via rkanter)
 OOZIE-1317 TestEventGeneration.testCoordinatorActionEvent fails (mona)
 OOZIE-1292 Add Hadoop 0.23 Poms in hadooplibs to enable a build/tests against branch 0.23 (mona)
 OOZIE-1320 Tests for sharelib actions fail with ClassNotFoundException against Hadoop 2 (rkanter)