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 2018/11/20 01:35:58 UTC
[servicecomb-saga] branch 0.2.x updated: SCB-963 Added the unit
test of Saga
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch 0.2.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-saga.git
The following commit(s) were added to refs/heads/0.2.x by this push:
new 50cd4cf SCB-963 Added the unit test of Saga
50cd4cf is described below
commit 50cd4cf83374e564bb8977c85a2e063099a77f27
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Mon Aug 13 18:44:14 2018 +0800
SCB-963 Added the unit test of Saga
---
.../transaction/spring/TransactionInterceptionTest.java | 12 ++++++++++++
.../transaction/spring/TransactionalUserService.java | 16 ++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionInterceptionTest.java b/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionInterceptionTest.java
index 64ebc35..42a943b 100644
--- a/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionInterceptionTest.java
+++ b/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionInterceptionTest.java
@@ -29,6 +29,7 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
@@ -329,6 +330,17 @@ public class TransactionInterceptionTest {
actorSystem.terminate();
}
+ @Test
+ public void assertCompensationMethodTransactionAware() throws NoSuchMethodException {
+ userService.add(user);
+ compensationMethod = TransactionalUserService.class.getDeclaredMethod("deleteWithTransactional", User.class).toString();
+ messageHandler.onReceive(globalTxId, newLocalTxId, globalTxId, compensationMethod, user);
+ User actualUser = userRepository.findByUsername(user.username());
+ assertNotNull(actualUser);
+ assertThat(actualUser.username(), is(username));
+ assertThat(actualUser.email(), is(email));
+ }
+
private void waitTillSavedUser(String username) {
await().atMost(1000, MILLISECONDS).until(() -> userRepository.findByUsername(username) != null);
}
diff --git a/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionalUserService.java b/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionalUserService.java
index 11bc437..b4ae5bc 100644
--- a/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionalUserService.java
+++ b/omega/omega-spring-tx/src/test/java/org/apache/servicecomb/saga/omega/transaction/spring/TransactionalUserService.java
@@ -65,4 +65,20 @@ public class TransactionalUserService {
resetCount();
userRepository.delete(user);
}
+
+ @Compensable(compensationMethod = "deleteWithTransactional")
+ public User addWithTransactional(User user) {
+ if (ILLEGAL_USER.equals(user.username())) {
+ throw new IllegalArgumentException("User is illegal");
+ }
+ return userRepository.save(user);
+ }
+
+ // This method is failed on purpose which could rollback the call
+ public void deleteWithTransactional(User user) {
+ userRepository.delete(user);
+ throw new RuntimeException("saga compensation rollback test");
+ }
+
+
}