You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@servicecomb.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/05/10 01:20:00 UTC

[jira] [Commented] (SCB-300) [pack] acceptance tests of transaction timeout and retry

    [ https://issues.apache.org/jira/browse/SCB-300?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16469793#comment-16469793 ] 

ASF GitHub Bot commented on SCB-300:
------------------------------------

lijasonvip closed pull request #173: [SCB-300] acceptance test for @Compensable event timeout
URL: https://github.com/apache/incubator-servicecomb-saga/pull/173
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/acceptance-tests/acceptance-pack/src/test/resources/car_timeout.btm b/acceptance-tests/acceptance-pack/src/test/resources/car_timeout.btm
new file mode 100644
index 00000000..c8c132f9
--- /dev/null
+++ b/acceptance-tests/acceptance-pack/src/test/resources/car_timeout.btm
@@ -0,0 +1,35 @@
+# 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 timeout the car after invoking the services
+#
+###############################################################
+RULE set the saga compensable timeout to 5s
+INTERFACE org.apache.servicecomb.saga.omega.transaction.annotations.Compensable
+METHOD timeout
+AT EXIT
+IF TRUE
+DO RETURN 5
+ENDRULE
+
+RULE sleep when postCarBooking until timeout happens
+CLASS org.apache.servicecomb.saga.demo.pack.car.CarBookingService
+METHOD postCarBooking
+AT ENTRY
+IF TRUE
+DO debug("delay 10s until the car booking timeout"),
+   Thread.sleep(10000)
+ENDRULE
diff --git a/acceptance-tests/acceptance-pack/src/test/resources/hotel_timeout.btm b/acceptance-tests/acceptance-pack/src/test/resources/hotel_timeout.btm
new file mode 100644
index 00000000..5a7632e7
--- /dev/null
+++ b/acceptance-tests/acceptance-pack/src/test/resources/hotel_timeout.btm
@@ -0,0 +1,35 @@
+# 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 timeout the car after invoking the services
+#
+###############################################################
+RULE set the saga compensable timeout to 2s
+INTERFACE org.apache.servicecomb.saga.omega.transaction.annotations.Compensable
+METHOD timeout
+AT EXIT
+IF TRUE
+DO RETURN 2
+ENDRULE
+
+RULE sleep when postHotelBooking until timeout happens
+CLASS org.apache.servicecomb.saga.demo.pack.hotel.HotelBookingService
+METHOD postHotelBooking
+AT ENTRY
+IF TRUE
+DO debug("delay 10s until the car booking timeout"),
+   Thread.sleep(4000)
+ENDRULE
diff --git a/acceptance-tests/acceptance-pack/src/test/resources/pack_car_timeout_scenario.feature b/acceptance-tests/acceptance-pack/src/test/resources/pack_car_timeout_scenario.feature
new file mode 100644
index 00000000..278502fc
--- /dev/null
+++ b/acceptance-tests/acceptance-pack/src/test/resources/pack_car_timeout_scenario.feature
@@ -0,0 +1,39 @@
+# 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.
+
+Feature: Alpha records transaction events
+
+  Scenario: Car transaction timeout and will be compensated
+    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_timeout.btm to Car Service
+
+    When User Jason requests to book 1 cars and 1 rooms
+
+    Then Alpha records the following events
+      | serviceName  | type               |
+      | pack-booking | SagaStartedEvent   |
+      | pack-car     | TxStartedEvent     |
+      | pack-car     | TxAbortedEvent     |
+      | pack-car     | TxCompensatedEvent |
+      | pack-car     | SagaEndedEvent     |
+      | pack-car     | TxEndedEvent       |
+
+    Then Car Service contains the following booking orders
+      | name  | amount | confirmed | cancelled |
+      | Jason | 1      | true      | false     |
\ No newline at end of file
diff --git a/acceptance-tests/acceptance-pack/src/test/resources/pack_hotel_timeout_scenario.feature b/acceptance-tests/acceptance-pack/src/test/resources/pack_hotel_timeout_scenario.feature
new file mode 100644
index 00000000..c272359d
--- /dev/null
+++ b/acceptance-tests/acceptance-pack/src/test/resources/pack_hotel_timeout_scenario.feature
@@ -0,0 +1,47 @@
+# 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.
+
+Feature: Alpha records transaction events
+
+  Scenario: Hotel transaction timeout and will be compensated
+    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 hotel_timeout.btm to Hotel Service
+
+    When User Jason requests to book 1 cars and 1 rooms
+
+    Then Alpha records the following events
+      | serviceName  | type               |
+      | pack-booking | SagaStartedEvent   |
+      | pack-car     | TxStartedEvent     |
+      | pack-car     | TxEndedEvent       |
+      | pack-hotel   | TxStartedEvent     |
+      | pack-hotel   | TxAbortedEvent     |
+      | pack-car     | TxCompensatedEvent |
+      | pack-hotel   | TxCompensatedEvent |
+      | pack-hotel   | SagaEndedEvent     |
+      | pack-hotel   | TxEndedEvent       |
+      | pack-booking | SagaEndedEvent     |
+
+    Then Car Service contains the following booking orders
+      | name  | amount | confirmed | cancelled |
+      | Jason | 1      | false     | true      |
+
+    And Hotel Service contains the following booking orders
+      | name  | amount | confirmed | cancelled |
+      | Jason | 1      | true      | false     |
\ No newline at end of file
diff --git a/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingService.java b/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingService.java
index 3be4d36d..6dcabce4 100644
--- a/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingService.java
+++ b/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingService.java
@@ -30,6 +30,7 @@
 
   @Compensable(compensationMethod = "cancel")
   void order(CarBooking booking) {
+    postCarBooking();
     booking.confirm();
     bookings.put(booking.getId(), booking);
   }
@@ -48,4 +49,7 @@ void cancel(CarBooking booking) {
   void clearAllBookings() {
     bookings.clear();
   }
+
+  //used by byteman to inject fault
+  private void postCarBooking(){}
 }
diff --git a/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingService.java b/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingService.java
index 9abf0407..8a0d5453 100644
--- a/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingService.java
+++ b/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingService.java
@@ -30,6 +30,7 @@
 
   @Compensable(compensationMethod = "cancel")
   void order(HotelBooking booking) {
+    postHotelBooking();
     if (booking.getAmount() > 2) {
       throw new IllegalArgumentException("can not order the rooms large than two");
     }
@@ -51,4 +52,7 @@ void cancel(HotelBooking booking) {
   void clearAllBookings() {
     bookings.clear();
   }
+
+  //used by byteman to inject fault
+  private void postHotelBooking(){}
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> [pack] acceptance tests of transaction timeout and retry
> --------------------------------------------------------
>
>                 Key: SCB-300
>                 URL: https://issues.apache.org/jira/browse/SCB-300
>             Project: Apache ServiceComb
>          Issue Type: Sub-task
>          Components: Saga
>            Reporter: Yin Xiang
>            Assignee: Zheng Feng
>            Priority: Major
>             Fix For: saga-0.2.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)