[
https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16692499#comment-16692499
]
ASF GitHub Bot commented on SCB-963:
------------------------------------
WillemJiang closed pull request #339: SCB-963 Add Test case for saga
transactional compensation.
URL: https://github.com/apache/servicecomb-saga/pull/339
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/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 6b66befb3..85cd3bf54 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.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;
@@ -280,6 +281,17 @@ public void run() {
);
}
+ @Test
+ public void assertCompensationMethodTransactionAware() throws
NoSuchMethodException {
+ userService.add(user);
+ compensationMethod =
TransactionalUserService.class.getDeclaredMethod("deleteTransactional",
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));
+ }
+
@Test
public void passesOmegaContextInThreadPool() throws Exception {
executor.schedule(new Runnable() {
@@ -353,11 +365,6 @@ public void passesOmegaContextAmongActors() throws
Exception {
actorSystem.terminate();
}
- @Test
- public void tccWorkflowTest() {
-
- }
-
private void waitTillSavedUser(final String username) {
await().atMost(1000, MILLISECONDS).until(new Callable<Boolean>() {
@Override
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 11bc4374a..6628f7e49 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,17 @@ public void delete(User user, int count) {
resetCount();
userRepository.delete(user);
}
+
+ @Compensable(compensationMethod = "deleteTransactional")
+ public User addTransactional(User user) {
+ if (ILLEGAL_USER.equals(user.username())) {
+ throw new IllegalArgumentException("User is illegal");
+ }
+ return userRepository.save(user);
+ }
+
+ public void deleteTransactional(User user) {
+ userRepository.delete(user);
+ throw new RuntimeException("saga compensation rollback test");
+ }
}
----------------------------------------------------------------
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:
[email protected]
> Saga transactional method can't work when compensation happens
> --------------------------------------------------------------
>
> Key: SCB-963
> URL: https://issues.apache.org/jira/browse/SCB-963
> Project: Apache ServiceComb
> Issue Type: Bug
> Components: Saga
> Affects Versions: saga-0.2.0, saga-0.3.0
> Reporter: cherrylzhao
> Assignee: cherrylzhao
> Priority: Major
> Fix For: saga-0.3.0, saga-0.2.1
>
>
> currently we cached the compensation method of raw bean in callback context.
> it will make transactional method inefficient, we should cache the
> transaction proxy bean instead.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)