Author: assaf
Date: Thu Sep 28 12:42:17 2006
New Revision: 450985

URL: http://svn.apache.org/viewvc?view=rev&rev=450985
Log:
Added activity recovery test cases

Added:
    
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
   (with props)
    incubator/ode/trunk/bpel-runtime/src/test/resources/
    incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/
    incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml   
(with props)
    incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/process.bpel
    incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl  
 (with props)
    incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd   
(with props)
Modified:
    incubator/ode/trunk/bpel-runtime/build.xml

Modified: incubator/ode/trunk/bpel-runtime/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/build.xml?view=diff&rev=450985&r1=450984&r2=450985
==============================================================================
--- incubator/ode/trunk/bpel-runtime/build.xml (original)
+++ incubator/ode/trunk/bpel-runtime/build.xml Thu Sep 28 12:42:17 2006
@@ -15,6 +15,7 @@
     <copy todir="${maven.project.build.directory}/scratch" flatten="true">
       <fileSet refid="dependency.derby"/>
     </copy>
+    <delete dir="${maven.project.build.directory}/test-classes/derby-db"/>
     <untar 
src="${maven.project.build.directory}/scratch/ode-dao-hibernate-db-derby-${maven.project.version}.tar"
            dest="${maven.project.build.directory}/test-classes/derby-db"/>
   </target>

Added: 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java?view=auto&rev=450985
==============================================================================
--- 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
 (added)
+++ 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
 Thu Sep 28 12:42:17 2006
@@ -0,0 +1,214 @@
+/*
+ * 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.ode.bpel.runtime;
+
+import org.apache.ode.bpel.o.*;
+import org.apache.ode.bpel.o.OMessageVarType.Part;
+import org.apache.ode.bpel.runtime.channels.InvokeResponseChannel;
+import org.apache.ode.bpel.engine.*;
+import org.apache.ode.bpel.iapi.*;
+import org.apache.ode.bpel.pmapi.BpelManagementFacade;
+import org.apache.ode.bpel.pmapi.TInstanceInfo;
+import org.apache.ode.bpel.pmapi.TInstanceStatus;
+import org.apache.ode.bpel.pmapi.TFaultInfo;
+import org.apache.ode.bpel.pmapi.TScopeInfo;
+import org.apache.ode.bpel.pmapi.TScopeRef;
+import org.apache.ode.bpel.pmapi.TActivityInfo;
+import org.apache.ode.bpel.pmapi.TActivityStatus;
+import org.apache.ode.utils.DOMUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Date;
+import java.util.List;
+import java.util.ArrayList;
+
+import java.net.URI;
+import java.io.File;
+import javax.wsdl.Operation;
+import javax.xml.namespace.QName;
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Test core BPEL processing capabilities.
+ */
+public class ActivityRecoveryTest extends TestCase {
+
+  static final String   NAMESPACE = "http://ode.apache.org/bpel/unit-test";;
+  int                   _invoked;
+  int                   _failFor;
+  MockBpelServer        _server;
+  BpelManagementFacade  _management;
+
+
+  public void testSuccessfulInvoke() throws Exception { 
+    execute(null, 0);
+    assertCompleted(true, 1, null);
+  }
+
+  public void testInvokeAndRetry() throws Exception {
+    execute(null, 2);
+    assertCompleted(true, 3, null);
+  }
+
+  public void testRetryRecoveryAction() throws Exception {
+    execute(null, 4);
+    assertRecovery();
+    recover("retry");
+    assertRecovery();
+    recover("retry");
+    assertCompleted(true, 5, null);
+  }
+
+  public void testCancelRecoveryAction() throws Exception {
+    execute(null, 4);
+    assertRecovery();
+    recover("retry");
+    assertRecovery();
+    recover("cancel");
+    assertCompleted(true, 4, null);
+  }
+
+  public void testFaultRecoveryAction() throws Exception {
+    execute(null, 4);
+    assertRecovery();
+    recover("retry");
+    assertRecovery();
+    recover("fault");
+    assertCompleted(false, 4, FailureHandling.FAILURE_FAULT_NAME);
+  }
+
+  protected void setUp() throws Exception {
+    _server = new MockBpelServer() {
+      protected MessageExchangeContext createMessageExchangeContext() {
+        return new MessageExchangeContext() {
+
+          public void invokePartner(final PartnerRoleMessageExchange mex) 
throws ContextException {
+            ++_invoked;
+            if (_invoked > _failFor) {
+              Message response = 
mex.createMessage(mex.getOperation().getOutput().getMessage().getQName());
+              
response.setMessage(DOMUtils.newDocument().createElementNS(NAMESPACE, 
"tns:ResponseElement"));
+              mex.reply(response);
+            } else
+              
mex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, "Bang", 
null);
+              //mex.replyWithFailure(FailureType, String, Element);
+          }
+
+          public void onAsyncReply(MyRoleMessageExchange myRoleMex) { }
+        };
+      }
+    };
+    _server.deploy(new File(new 
URI(this.getClass().getResource("/recovery").toString())));
+    _management = _server.getBpelManagementFacade();
+  }
+
+  protected void tearDown() throws Exception {
+    _server.getBpelManagementFacade().delete(null);
+    _server.shutdown();
+  }
+
+  /**
+   * Call this to execute the process so it fails the specified number of 
times.
+   * Returns when the process has either completed, or waiting for recovery to 
happen.
+   */
+  protected void execute(String process, int failFor) throws Exception {
+    _failFor = failFor;
+    _server.getBpelManagementFacade().delete(null);
+    _server.invoke(new QName(NAMESPACE, "InstantiatingService"), "instantiate",
+                   DOMUtils.newDocument().createElementNS(NAMESPACE, 
"tns:RequestElement"));
+    _server.waitForBlocking();
+  }
+
+  /**
+   * Asserts that the process has completed, successfully or not. If not,
+   * it is either terminated, or faulted with the specified fault name.
+   * This method also checks how many time the process invoked the service.
+   */
+  protected void assertCompleted(boolean successful, int invoked, QName 
faultName) {
+    assertTrue(_invoked == invoked);
+    TInstanceInfo instance = 
_management.listAllInstances().getInstanceInfoList().getInstanceInfoArray(0);
+    TInstanceInfo.Failures failures = instance.getFailures();
+    assertTrue(failures == null || failures.getCount() == 0);
+    if (successful) {
+      assertTrue(instance.getStatus() == TInstanceStatus.COMPLETED);
+    } else if (faultName == null) {
+      assertTrue(instance.getStatus() == TInstanceStatus.TERMINATED);
+    } else {
+      assertTrue(instance.getStatus() == TInstanceStatus.FAILED);
+      TFaultInfo faultInfo = instance.getFaultInfo();
+      assertTrue(faultInfo != null && faultInfo.getName().equals(faultName));
+    }
+  }
+
+  /**
+   * Asserts that the process has one activity in the recovery state.
+   */
+  protected void assertRecovery() {
+    // Test in aggregate to see how many activities we have in this state.
+    TInstanceInfo instance = 
_management.listAllInstances().getInstanceInfoList().getInstanceInfoArray(0);
+    TInstanceInfo.Failures failures = instance.getFailures();
+    assertTrue(failures != null && failures.getCount() == 1);
+    // Look for individual activities inside the process instance.
+    TScopeInfo rootScope = 
_management.getScopeInfoWithActivity(instance.getRootScope().getSiid(), 
true).getScopeInfo();
+    assertTrue(getRecoveriesInScope(instance, null, null).size() == 1);
+  }
+
+  /**
+   * Performs the specified recovery action. Also asserts that there is one
+   * recovery channel for the activity in question.
+   */
+  protected void recover(String action) {
+    TInstanceInfo instance = 
_management.listAllInstances().getInstanceInfoList().getInstanceInfoArray(0);
+    ArrayList<TActivityInfo> recoveries = getRecoveriesInScope(instance, null, 
null);
+    assertTrue(recoveries.size() == 1);
+    TActivityInfo activity = recoveries.get(0);
+    assertNotNull(activity);
+    _management.recoverActivity(Long.valueOf(instance.getIid()), 
Long.valueOf(activity.getAiid()), action);
+    _server.waitForBlocking();
+  }
+
+  protected ArrayList<TActivityInfo> getRecoveriesInScope(TInstanceInfo 
instance, TScopeInfo scope,
+                                                          
ArrayList<TActivityInfo> recoveries) {
+    if (instance == null)
+      instance = 
_management.listAllInstances().getInstanceInfoList().getInstanceInfoArray(0);
+    if (scope == null)
+      scope = 
_management.getScopeInfoWithActivity(instance.getRootScope().getSiid(), 
true).getScopeInfo();
+    if (recoveries == null)
+      recoveries = new ArrayList<TActivityInfo>();
+    TScopeInfo.Activities activities = scope.getActivities();
+    for (int i = 0; i < activities.sizeOfActivityInfoArray(); ++i) {
+      TActivityInfo activity = activities.getActivityInfoArray(i);
+      if (activity.getStatus() == TActivityStatus.FAILURE) {
+        assertNotNull(activity.getFailure());
+        recoveries.add(activity);
+      } else
+        assertNull(activity.getFailure());
+    }
+    for (TScopeRef ref : scope.getChildren().getChildRefList()) {
+      TScopeInfo child = 
_server.getBpelManagementFacade().getScopeInfoWithActivity(ref.getSiid(), 
true).getScopeInfo();
+      if (child != null)
+        getRecoveriesInScope(instance, child, recoveries);
+    }
+    return recoveries;
+  }
+
+}

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/ActivityRecoveryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml?view=auto&rev=450985
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml 
(added)
+++ incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml Thu 
Sep 28 12:42:17 2006
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<deploy xmlns="http://ode.fivesight.com/schemas/2006/06/27/dd";
+        xmlns:pns="http://ode.apache.org/bpel/unit-test";
+        xmlns:wns="http://ode.apache.org/bpel/unit-test";>
+
+  <process name="pns:InvokeFailureAndRecovery">
+    <active>true</active>
+    <provide partnerLink="instantiatingPartnerLink">
+      <service name="wns:InstantiatingService" port="soap"/>
+    </provide>
+    <invoke partnerLink="failingPartnerLink">
+      <service name="wns:FailingService" port="soap"/>
+    </invoke>
+  </process>
+</deploy>
+

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/deploy.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/process.bpel
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/process.bpel?view=auto&rev=450985
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/process.bpel 
(added)
+++ incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/process.bpel 
Thu Sep 28 12:42:17 2006
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<process name="InvokeFailureAndRecovery"
+         targetNamespace="http://ode.apache.org/bpel/unit-test"; 
+         xmlns="http://schemas.xmlsoap.org/ws/2004/03/business-process/";
+         xmlns:tns="http://ode.apache.org/bpel/unit-test";
+         xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+         xmlns:ext="http://ode.apache.org/activityRecovery";>
+
+  <import location="services.wsdl"
+          namespace="http://ode.apache.org/bpel/unit-test";
+          importType="http://schemas.xmlsoap.org/wsdl/"/>
+
+  <partnerLinks>
+    <partnerLink name="instantiatingPartnerLink" 
+                 partnerLinkType="tns:InstantiatingPartnerLinkType" 
+                 myRole="me"/>
+    <partnerLink name="failingPartnerLink" 
+                 partnerLinkType="tns:FailingPartnerLinkType" 
+                 partnerRole="partner" initializePartnerRole="yes"/>
+  </partnerLinks>
+    
+  <variables>
+    <variable name="request" messageType="tns:Request"/>
+    <variable name="response" messageType="tns:Response"/>
+  </variables>
+
+  <sequence>   
+    <receive name="start"
+             partnerLink="instantiatingPartnerLink"
+             portType="tns:InstantiatingPortType"
+             operation="instantiate"
+             variable="request"
+             createInstance="yes"/>
+    <invoke  name="invoke"
+             partnerLink="failingPartnerLink"
+             portType="tns:FailingPortType"
+             operation="invoke"
+             inputVariable="request"
+             outputVariable="response">
+      <ext:failureHandling>
+        <ext:retryFor>2</ext:retryFor>
+        <ext:retryDelay>0</ext:retryDelay>
+      </ext:failureHandling>
+    </invoke>
+  </sequence>
+
+</process>

Added: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl?view=auto&rev=450985
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl 
(added)
+++ incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl 
Thu Sep 28 12:42:17 2006
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8"?>
+<definitions targetNamespace="http://ode.apache.org/bpel/unit-test"; 
+             xmlns="http://schemas.xmlsoap.org/wsdl/";
+             xmlns:tns="http://ode.apache.org/bpel/unit-test";
+             xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
+             
xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/";
+             xmlns:plnk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/";>
+
+  <types>
+    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema";>
+      <import namespace="http://ode.apache.org/bpel/unit-test"; 
schemaLocation="types.xsd"/>
+    </xsd:schema>
+  </types>
+
+  <message name="Request">
+    <part name="main" element="tns:RequestElement"/>
+  </message>
+  <message name="Response">
+    <part name="main" element="tns:ResponseElement"/>
+  </message>
+
+  <portType name="InstantiatingPortType">
+    <operation name="instantiate">
+      <input message="tns:Request"/>
+    </operation>
+  </portType>
+  <portType name="FailingPortType">
+    <operation name="invoke">
+      <input message="tns:Request"/>
+      <output message="tns:Response"/>
+    </operation>
+  </portType>
+
+  <binding name="InstantiatingBinding" type="tns:InstantiatingPortType">
+    <soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http"/>
+    <operation name="instantiate">
+      <soap:operation/>
+      <input>
+        <soap:body use="literal"/>
+      </input>
+    </operation>
+  </binding>
+
+  <binding name="FailingBinding" type="tns:FailingPortType">
+    <soap:binding style="document" 
transport="http://schemas.xmlsoap.org/soap/http"/>
+    <operation name="invoke">
+      <soap:operation/>
+      <input>
+        <soap:body use="literal"/>
+      </input>
+      <output>
+        <soap:body use="literal"/>
+      </output>
+    </operation>
+  </binding>
+
+  <service name="InstantiatingService">
+    <port name="soap" binding="tns:InstantiatingBinding">
+      <soap:address 
location="http://localhost/pxe/soap/InvokeFailureAndRecovery"/>
+    </port>
+  </service>
+
+  <service name="FailingService">
+    <port name="soap" binding="tns:FailingBinding">
+      <soap:address location="http://localhost/FailingEndpoint"/>
+    </port>
+  </service>
+
+  <plnk:partnerLinkType name="InstantiatingPartnerLinkType">
+    <plnk:role name="me" portType="tns:InstantiatingPortType"/>
+  </plnk:partnerLinkType>
+
+  <plnk:partnerLinkType name="FailingPartnerLinkType">
+    <plnk:role name="partner" portType="tns:FailingPortType"/>
+  </plnk:partnerLinkType>
+
+</definitions>

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/services.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd?view=auto&rev=450985
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd 
(added)
+++ incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd Thu 
Sep 28 12:42:17 2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema targetNamespace="http://ode.apache.org/bpel/unit-test"; 
+        xmlns:tns="http://ode.apache.org/bpel/unit-test";
+        elementFormDefault="qualified" 
+        attributeFormDefault="qualified" 
+        xmlns="http://www.w3.org/2001/XMLSchema";
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+
+  <element name="RequestElement" type="xsd:string"/>
+  <element name="ResponseElement" type="xsd:string"/>
+
+</schema>

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/ode/trunk/bpel-runtime/src/test/resources/recovery/types.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to