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/incubator-servicecomb-saga.git


The following commit(s) were added to refs/heads/master by this push:
     new f2f8a25  [SCB-300] Update to add the timeout scenario feature in the 
acceptance-tests
f2f8a25 is described below

commit f2f8a2580a562b63e80948b954e7ad5253668458
Author: Zheng Feng <zh.f...@gmail.com>
AuthorDate: Thu Apr 12 17:02:03 2018 +0800

    [SCB-300] Update to add the timeout scenario feature in the acceptance-tests
---
 .../org/apache/servicecomb/saga/PackStepdefs.java  | 28 +++++++++++--
 .../src/test/resources/booking_timeout.btm         | 13 ++++++
 .../test/resources/pack_timeout_scenario.feature   | 47 ++++++++++++++++++++++
 .../saga/demo/pack/booking/BookingController.java  |  9 ++++-
 4 files changed, 92 insertions(+), 5 deletions(-)

diff --git 
a/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java
 
b/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java
index e256be9..857bb9f 100644
--- 
a/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java
+++ 
b/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java
@@ -26,6 +26,7 @@ import static org.hamcrest.core.Is.is;
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Consumer;
@@ -51,6 +52,8 @@ public class PackStepdefs implements En {
   private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = 
(dataMap) -> {
   };
 
+  private static final Map<String, Submit> submits = new HashMap<>();
+
   public PackStepdefs() {
     Given("^Car Service is up and running$", () -> {
       probe(System.getProperty(CAR_SERVICE_ADDRESS));
@@ -69,12 +72,10 @@ public class PackStepdefs implements En {
     });
 
     Given("^Install the byteman script ([A-Za-z0-9_\\.]+) to ([A-Za-z]+) 
Service$", (String script, String service) -> {
-      String address = System.getProperty("byteman.address");
-      String port = System.getProperty(service.toLowerCase() + 
".byteman.port");
-      log.info("Install the byteman script {} to {} service with {}:{}", 
script, service, address, port);
-      Submit bm = new Submit(address, Integer.parseInt(port));
+      log.info("Install the byteman script {} to {} service", script, service);
       List<String> rules = new ArrayList<>();
       rules.add("target/test-classes/" + script);
+      Submit bm = getBytemanSubmit(service);
       bm.addRulesFromFiles(rules);
     });
 
@@ -123,6 +124,14 @@ public class PackStepdefs implements En {
         .delete(System.getProperty(ALPHA_REST_ADDRESS) + "/events")
         .then()
         .statusCode(is(200));
+
+    for (Submit bm : submits.values()) {
+      try {
+        bm.deleteAllRules();
+      } catch (Exception e) {
+        log.warn("Fail to delete the byteman rules " + e);
+      }
+    }
   }
 
   @SuppressWarnings("unchecked")
@@ -178,4 +187,15 @@ public class PackStepdefs implements En {
         .statusCode(is(200));
   }
 
+  private Submit getBytemanSubmit(String service) {
+    if (submits.containsKey(service)) {
+      return submits.get(service);
+    } else {
+      String address = System.getProperty("byteman.address");
+      String port = System.getProperty(service.toLowerCase() + 
".byteman.port");
+      Submit bm = new Submit(address, Integer.parseInt(port));
+      submits.put(service, bm);
+      return bm;
+    }
+  }
 }
diff --git 
a/acceptance-tests/acceptance-pack/src/test/resources/booking_timeout.btm 
b/acceptance-tests/acceptance-pack/src/test/resources/booking_timeout.btm
new file mode 100644
index 0000000..efc6902
--- /dev/null
+++ b/acceptance-tests/acceptance-pack/src/test/resources/booking_timeout.btm
@@ -0,0 +1,13 @@
+##############################################################
+# rules to timeout the booking after invoking the services
+#
+###############################################################
+
+RULE sleep when postBooking until timeout happens
+CLASS org.apache.servicecomb.saga.demo.pack.booking.BookingController
+METHOD postBooking
+AT ENTRY
+IF TRUE
+DO debug("delay 10s until the booking timeout"),
+   Thread.sleep(10000)
+ENDRULE
diff --git 
a/acceptance-tests/acceptance-pack/src/test/resources/pack_timeout_scenario.feature
 
b/acceptance-tests/acceptance-pack/src/test/resources/pack_timeout_scenario.feature
new file mode 100644
index 0000000..2a3e59d
--- /dev/null
+++ 
b/acceptance-tests/acceptance-pack/src/test/resources/pack_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: A 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 booking_timeout.btm to Booking Service
+
+    When User Sean 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   | TxEndedEvent       |
+      | pack-booking | TxAbortedEvent     |
+      | pack-hotel   | TxCompensatedEvent |
+      | pack-car     | TxCompensatedEvent |
+      | pack-booking | SagaEndedEvent     |
+
+    Then Car Service contains the following booking orders
+      | name | amount | confirmed | cancelled |
+      | Sean | 1      | false     | true      |
+
+    Then Hotel Service contains the following booking orders
+      | name | amount | confirmed | cancelled |
+      | Sean | 1      | false     | true      |
+
diff --git 
a/saga-demo/booking/booking/src/main/java/org/apache/servicecomb/saga/demo/pack/booking/BookingController.java
 
b/saga-demo/booking/booking/src/main/java/org/apache/servicecomb/saga/demo/pack/booking/BookingController.java
index f580a58..3d6c2ce 100644
--- 
a/saga-demo/booking/booking/src/main/java/org/apache/servicecomb/saga/demo/pack/booking/BookingController.java
+++ 
b/saga-demo/booking/booking/src/main/java/org/apache/servicecomb/saga/demo/pack/booking/BookingController.java
@@ -37,7 +37,7 @@ public class BookingController {
   @Autowired
   private RestTemplate template;
 
-  @SagaStart
+  @SagaStart(timeout = 5)
   @PostMapping("/booking/{name}/{rooms}/{cars}")
   public String order(@PathVariable String name,  @PathVariable Integer rooms, 
@PathVariable Integer cars) {
     template.postForEntity(
@@ -48,6 +48,13 @@ public class BookingController {
         hotelServiceUrl + "/order/{name}/{rooms}",
         null, String.class, name, rooms);
 
+    postBooking();
+
     return name + " booking " + rooms + " rooms and " + cars + " cars OK";
   }
+
+  // This method is used by the byteman to inject the faults such as the 
timeout or the crash
+  private void postBooking() {
+
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
ningji...@apache.org.

Reply via email to