You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2017/12/27 04:55:18 UTC
[incubator-servicecomb-saga] 11/11: SCB-97 ensured tx ids are
linked between services
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
commit 43ab34ccc51f537587d0403586dd43cd45b333fe
Author: seanyinx <se...@huawei.com>
AuthorDate: Wed Dec 27 09:13:32 2017 +0800
SCB-97 ensured tx ids are linked between services
Signed-off-by: seanyinx <se...@huawei.com>
---
.../saga/alpha/server/AlphaIntegrationTest.java | 2 ++
integration-tests/coverage-aggregate/pom.xml | 5 +++++
.../saga/integration/pack/tests/GreetingController.java | 15 +++++++++++++--
.../saga/integration/pack/tests/GreetingService.java | 9 +++++++++
.../servicecomb/saga/integration/pack/tests/PackIT.java | 15 ++++++++++++---
.../saga/integration/pack/tests/TxEventEnvelope.java | 8 ++++++++
6 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java b/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java
index 1e1ce99..acce006 100644
--- a/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java
+++ b/alpha/alpha-server/src/test/java/io/servicecomb/saga/alpha/server/AlphaIntegrationTest.java
@@ -77,5 +77,7 @@ public class AlphaIntegrationTest {
assertThat(envelope.parentTxId(), is(parentTxId));
assertThat(envelope.type(), is(TX_STARTED_EVENT));
assertThat(envelope.payloads(), is(payload.getBytes()));
+
+ endpoint.close();
}
}
diff --git a/integration-tests/coverage-aggregate/pom.xml b/integration-tests/coverage-aggregate/pom.xml
index 452fc56..ffebdee 100644
--- a/integration-tests/coverage-aggregate/pom.xml
+++ b/integration-tests/coverage-aggregate/pom.xml
@@ -71,6 +71,11 @@
<groupId>io.servicecomb.saga</groupId>
<artifactId>alpha-server</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.servicecomb.saga.tests</groupId>
+ <artifactId>pack-tests</artifactId>
+ <version>0.0.3-SNAPSHOT</version>
+ </dependency>
</dependencies>
<profiles>
diff --git a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingController.java b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingController.java
index 1a6d489..e7c6c25 100644
--- a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingController.java
+++ b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingController.java
@@ -23,20 +23,31 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.client.RestTemplate;
@Controller
@RequestMapping("/")
public class GreetingController {
private final GreetingService greetingService;
+ private final RestTemplate restTemplate;
@Autowired
- public GreetingController(GreetingService greetingService) {
+ public GreetingController(GreetingService greetingService, RestTemplate restTemplate) {
this.greetingService = greetingService;
+ this.restTemplate = restTemplate;
}
@GetMapping("/greet")
ResponseEntity<String> greet(@RequestParam String name) {
- return ResponseEntity.ok(greetingService.greet(name));
+ String greetings = greetingService.greet(name);
+ String bonjour = restTemplate.getForObject("http://localhost:8080/bonjour?name={name}", String.class, name);
+
+ return ResponseEntity.ok(greetings + "; " + bonjour);
+ }
+
+ @GetMapping("/bonjour")
+ ResponseEntity<String> bonjour(@RequestParam String name) {
+ return ResponseEntity.ok(greetingService.bonjour(name));
}
}
diff --git a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingService.java b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingService.java
index d65899b..fe0f16a 100644
--- a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingService.java
+++ b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/GreetingService.java
@@ -31,4 +31,13 @@ public class GreetingService {
String goodbye(String name) {
return "Goodbye, " + name;
}
+
+ @Compensable(compensationMethod = "auRevoir")
+ String bonjour(String name) {
+ return "Bonjour, " + name;
+ }
+
+ String auRevoir(String name) {
+ return "Au revoir, " + name;
+ }
}
diff --git a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java
index b32eeb6..334e60c 100644
--- a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java
+++ b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/PackIT.java
@@ -18,6 +18,7 @@
package io.servicecomb.saga.integration.pack.tests;
import static io.servicecomb.saga.omega.context.OmegaContext.GLOBAL_TX_ID_KEY;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
@@ -40,7 +41,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import io.servicecomb.saga.omega.context.OmegaContext;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = GreetingApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
+@SpringBootTest(classes = GreetingApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT,
+ properties = {"server.port=8080"})
public class PackIT {
private final String globalTxId = UUID.randomUUID().toString();
@@ -66,12 +68,19 @@ public class PackIT {
"mike");
assertThat(entity.getStatusCode(), is(OK));
- assertThat(entity.getBody(), is("Greetings, mike"));
+ assertThat(entity.getBody(), is("Greetings, mike; Bonjour, mike"));
List<TxEventEnvelope> envelopes = repository.findByGlobalTxIdOrderByCreationTime(globalTxId);
- assertThat(envelopes.size(), is(2));
+ assertThat(envelopes.size(), is(4));
assertThat(envelopes.get(0).type(), is("TxStartedEvent"));
+ assertThat(envelopes.get(0).parentTxId(), is(nullValue()));
assertThat(envelopes.get(1).type(), is("TxEndedEvent"));
+ assertThat(envelopes.get(1).parentTxId(), is(nullValue()));
+
+ assertThat(envelopes.get(2).type(), is("TxStartedEvent"));
+ assertThat(envelopes.get(2).parentTxId(), is(envelopes.get(0).localTxId()));
+ assertThat(envelopes.get(3).type(), is("TxEndedEvent"));
+ assertThat(envelopes.get(3).parentTxId(), is(envelopes.get(0).localTxId()));
}
}
diff --git a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelope.java b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelope.java
index 1ff04e9..ae7a302 100644
--- a/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelope.java
+++ b/integration-tests/pack-tests/src/test/java/io/servicecomb/saga/integration/pack/tests/TxEventEnvelope.java
@@ -39,6 +39,14 @@ class TxEventEnvelope {
private TxEventEnvelope() {
}
+ String localTxId() {
+ return localTxId;
+ }
+
+ String parentTxId() {
+ return parentTxId;
+ }
+
String type() {
return type;
}
--
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.