This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git
commit a448291d61640a8360085688de4bd8c9995a4a9d Author: Lei Zhang <zhang...@apache.org> AuthorDate: Mon Jan 13 02:15:27 2020 +0800 SCB-1696 Added compensation failure test cases --- .../alpha_records_transaction_events.feature | 34 +++++++++++++++++--- .../test/resources/car_compensate_failed_retry.btm | 36 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/resources/alpha_records_transaction_events.feature b/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/resources/alpha_records_transaction_events.feature index 1e914b5..4f0aa48 100644 --- a/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/resources/alpha_records_transaction_events.feature +++ b/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/resources/alpha_records_transaction_events.feature @@ -57,7 +57,7 @@ Feature: Alpha records transaction events | car | TxStartedEvent | | car | TxEndedEvent | | booking | SagaAbortedEvent | - | car | TxCompensatedEvent | + | car | TxCompensateAckSucceedEvent | Then Car Service contains the following booking orders | id | name | amount | confirmed | cancelled | @@ -84,8 +84,8 @@ Feature: Alpha records transaction events | hotel | TxStartedEvent | | hotel | TxEndedEvent | | booking | SagaAbortedEvent | - | hotel | TxCompensatedEvent | - | car | TxCompensatedEvent | + | hotel | TxCompensateAckSucceedEvent | + | car | TxCompensateAckSucceedEvent | Then Car Service contains the following booking orders | id | name | amount | confirmed | cancelled | @@ -159,11 +159,37 @@ Feature: Alpha records transaction events | hotel | TxStartedEvent | | hotel | TxAbortedEvent | | booking | SagaAbortedEvent | - | car | TxCompensatedEvent | + | car | TxCompensateAckSucceedEvent | Then Car Service contains the following booking orders | id | name | amount | confirmed | cancelled | | 1 | Sean | 5 | false | true | Then Hotel Service contains the following booking orders + | id | name | amount | confirmed | cancelled | + + Scenario: 7.Hotel sub-transaction failed and Car sub-transaction compensate failed and global transaction suspended + Given Car Service is up and running + And Hotel Service is up and running + And Booking Service is up and running + And Alpha is up and running + Given Install the byteman script car_compensate_failed_retry.btm to Car Service + When User Sean requests to book 5 cars and 3 rooms fail + Then Alpha records the following events + | serviceName | type | + | booking | SagaStartedEvent | + | car | TxStartedEvent | + | car | TxEndedEvent | + | hotel | TxStartedEvent | + | hotel | TxAbortedEvent | + | booking | SagaAbortedEvent | + | car | TxCompensateAckFailedEvent | + | car | TxCompensateAckFailedEvent | + | car | TxCompensateAckFailedEvent | + + Then Car Service contains the following booking orders + | id | name | amount | confirmed | cancelled | + | 1 | Sean | 5 | true | false | + + Then Hotel Service contains the following booking orders | id | name | amount | confirmed | cancelled | \ No newline at end of file diff --git a/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/resources/car_compensate_failed_retry.btm b/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/resources/car_compensate_failed_retry.btm new file mode 100644 index 0000000..f79e00e --- /dev/null +++ b/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/resources/car_compensate_failed_retry.btm @@ -0,0 +1,36 @@ +# 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. + +############################################################## +# rules to compensable failed after car order failed +# +############################################################### + +RULE set_the_compensable_reverseretries_to_3 +INTERFACE org.apache.servicecomb.pack.omega.transaction.annotations.Compensable +METHOD reverseRetries +AT EXIT +IF TRUE +DO RETURN 3 +ENDRULE + +RULE car_cancel_exception +CLASS org.apache.servicecomb.pack.demo.car.CarBookingService +METHOD cancel +AT ENTRY +IF TRUE +DO debug("throw RuntimeException here"), + throw new RuntimeException("Car cancel failed!") +ENDRULE