📄 activityrecoverytest.java
字号:
/* * 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.engine.BpelManagementFacadeImpl;import org.apache.ode.bpel.iapi.Message;import org.apache.ode.bpel.iapi.MessageExchange;import org.apache.ode.bpel.iapi.MessageExchangeContext;import org.apache.ode.bpel.iapi.PartnerRoleMessageExchange;import org.apache.ode.bpel.o.OFailureHandling;import org.apache.ode.bpel.pmapi.BpelManagementFacade;import org.apache.ode.bpel.pmapi.TActivityInfo;import org.apache.ode.bpel.pmapi.TActivityStatus;import org.apache.ode.bpel.pmapi.TFailureInfo;import org.apache.ode.bpel.pmapi.TFailuresInfo;import org.apache.ode.bpel.pmapi.TInstanceInfo;import org.apache.ode.bpel.pmapi.TInstanceInfoList;import org.apache.ode.bpel.pmapi.TInstanceStatus;import org.apache.ode.bpel.pmapi.TInstanceSummary;import org.apache.ode.bpel.pmapi.TScopeInfo;import org.apache.ode.bpel.pmapi.TScopeRef;import org.apache.ode.utils.DOMUtils;import org.jmock.Mock;import org.jmock.MockObjectTestCase;import org.jmock.core.Invocation;import org.jmock.core.InvocationMatcher;import org.jmock.core.Stub;import org.jmock.core.matcher.StatelessInvocationMatcher;import org.jmock.core.stub.CustomStub;import org.jmock.core.stub.StubSequence;import javax.xml.namespace.QName;import java.io.File;import java.net.URI;import java.util.ArrayList;/** * Test activity recovery and failure handling. */public class ActivityRecoveryTest extends MockObjectTestCase { static final String NAMESPACE = "http://ode.apache.org/bpel/unit-test"; static final String[] ACTIONS = new String[]{ "retry", "cancel", "fault" }; MockBpelServer _server; BpelManagementFacade _management; QName _processQName; QName _processId; private Mock _testService; /** * The process calls the failing service, simulated by a call to invoke. * The method returns true if the call succeeded, false for failure. * If the process completes, it calls the completed method. */ interface TestService { public boolean invoke(); public void completed(); } public void testInvokeSucceeds() throws Exception { // Since the service invocation succeeds, the process completes. _testService.expects(once()).method("invoke").will(returnValue(true)); _testService.expects(once()).method("completed").after("invoke"); execute("FailureToRecovery"); assertTrue(lastInstance().getStatus() == TInstanceStatus.COMPLETED); assertNoFailures(); } public void testFailureWithRecoveryAfterRetry() throws Exception { // Since the invocation is repeated 3 times, the process completes after // the third (successful) invocation. _testService.expects(exactly(3)).method("invoke").will(failTheFirst(2)); _testService.expects(once()).method("completed").after("invoke"); execute("FailureToRecovery"); assertTrue(lastInstance().getStatus() == TInstanceStatus.COMPLETED); assertNoFailures(); } public void testFailureWithManualRecovery() throws Exception { // Recovery required after three failures. Only one attempt made after recovery. // Only the fifth invocation succeeds. _testService.expects(exactly(5)).method("invoke").will(failTheFirst(4)); _testService.expects(once()).method("completed").after("invoke"); execute("FailureToRecovery"); recover("retry"); recover("retry"); assertTrue(lastInstance().getStatus() == TInstanceStatus.COMPLETED); assertNoFailures(); } public void testFailureWithFaultAction() throws Exception { // Recovery required after three failures. Only one attempt made after recovery. // Use the last failure to cause a fault. _testService.expects(exactly(4)).method("invoke").will(failTheFirst(4)); _testService.expects(never()).method("completed").after("invoke"); execute("FailureToRecovery"); recover("retry"); recover("fault"); assertTrue(lastInstance().getStatus() == TInstanceStatus.FAILED); assertTrue(OFailureHandling.FAILURE_FAULT_NAME.equals(lastInstance().getFaultInfo().getName())); assertNoFailures(); } public void testFailureWithCancelAction() throws Exception { // Recovery required after three failures. Only one attempt made after recovery. // Use the last failure to cancel the activity, allowing the process to complete. _testService.expects(exactly(4)).method("invoke").will(failTheFirst(4)); _testService.expects(once()).method("completed").after("invoke"); execute("FailureToCancel"); recover("retry"); recover("cancel"); assertTrue(lastInstance().getStatus() == TInstanceStatus.COMPLETED); assertNoFailures(); } public void testImmediateFailure() throws Exception { // This process does not attempt to retry, entering recovery immediately. _testService.expects(exactly(1)).method("invoke").will(returnValue(false)); _testService.expects(never()).method("completed").after("invoke"); execute("FailureNoRetry"); assertRecovery(1, ACTIONS); } public void testImmediateFailureAndFault() throws Exception { // This process responds to failure with a fault. _testService.expects(exactly(1)).method("invoke").will(returnValue(false)); _testService.expects(never()).method("completed").after("invoke"); execute("FailureToFault"); assertTrue(lastInstance().getStatus() == TInstanceStatus.FAILED); assertTrue(OFailureHandling.FAILURE_FAULT_NAME.equals(lastInstance().getFaultInfo().getName())); assertNoFailures(); } public void testFailureHandlingInheritence() throws Exception { // Since the invocation is repeated 3 times, the process completes after // the third (successful) invocation. _testService.expects(exactly(3)).method("invoke").will(failTheFirst(2)); _testService.expects(once()).method("completed").after("invoke"); execute("FailureInheritence"); assertTrue(lastInstance().getStatus() == TInstanceStatus.COMPLETED); assertNoFailures(); } public void testInstanceSummary() throws Exception { _processQName = new QName(NAMESPACE, "FailureToRecovery"); _processId = new QName(NAMESPACE, "FailureToRecovery-1"); // Failing the first three times and recovering, the process completes. _testService.expects(exactly(4)).method("invoke").will(failTheFirst(3)); _testService.expects(once()).method("completed").after("invoke"); _server.invoke(_processQName, "instantiate", DOMUtils.newDocument().createElementNS(NAMESPACE, "tns:RequestElement")); _server.waitForBlocking(); recover("retry"); // Completed. // Failing the first three times, we can then fault the process. _testService.expects(exactly(3)).method("invoke").will(failTheFirst(3)); _server.invoke(_processQName, "instantiate", DOMUtils.newDocument().createElementNS(NAMESPACE, "tns:RequestElement")); _server.waitForBlocking(); recover("fault"); // Faulted. // Failing the first three times, we can then leave it waiting for recovery. _testService.expects(exactly(3)).method("invoke").will(failTheFirst(3)); _server.invoke(_processQName, "instantiate", DOMUtils.newDocument().createElementNS(NAMESPACE, "tns:RequestElement")); _server.waitForBlocking(); // Active, recovery. // Stay active, awaiting recovery.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -