[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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() { @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: us...@infra.apache.org > 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)
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16692497#comment-16692497 ] ASF GitHub Bot commented on SCB-963: WillemJiang commented on a change in pull request #339: SCB-963 Add Test case for saga transactional compensation. URL: https://github.com/apache/servicecomb-saga/pull/339#discussion_r234836400 ## File path: 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"); Review comment: We just let the user know this method is supposed to be failed and the repository operation will be rollback. Don't worry I will submit a quick fix for it after merging your PR. 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: us...@infra.apache.org > 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)
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16691524#comment-16691524 ] ASF GitHub Bot commented on SCB-963: cherrylzhao commented on a change in pull request #339: SCB-963 Add Test case for saga transactional compensation. URL: https://github.com/apache/servicecomb-saga/pull/339#discussion_r234564883 ## File path: 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"); Review comment: yes, runtimeException is for transaction rollback. we need change the method name? 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: us...@infra.apache.org > 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)
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16691498#comment-16691498 ] ASF GitHub Bot commented on SCB-963: coveralls commented on issue #339: SCB-963 Add Test case for saga transactional compensation. URL: https://github.com/apache/servicecomb-saga/pull/339#issuecomment-439838304 [![Coverage Status](https://coveralls.io/builds/20176064/badge)](https://coveralls.io/builds/20176064) Coverage increased (+0.3%) to 92.091% when pulling **d044e1d632f27e63a510ec11703cb1c472035a46 on cherrylzhao:master** into **58c2e228fed1f660ac9c5500666c942263947b65 on apache:master**. 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: us...@infra.apache.org > 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)
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16691493#comment-16691493 ] ASF GitHub Bot commented on SCB-963: WillemJiang commented on a change in pull request #339: SCB-963 Add Test case for saga transactional compensation. URL: https://github.com/apache/servicecomb-saga/pull/339#discussion_r234554223 ## File path: 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"); Review comment: If the exception is thrown on purpose we need to change the name. 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: us...@infra.apache.org > 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)
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16691469#comment-16691469 ] ASF GitHub Bot commented on SCB-963: cherrylzhao opened a new pull request #339: SCB-963 Add Test case for saga transactional compensation. URL: https://github.com/apache/servicecomb-saga/pull/339 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: us...@infra.apache.org > 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)
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16658031#comment-16658031 ] ASF GitHub Bot commented on SCB-963: WillemJiang closed pull request #321: SCB-963 Make saga and tcc callback method transactional URL: https://github.com/apache/incubator-servicecomb-saga/pull/321 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-context/src/main/java/org/apache/servicecomb/saga/omega/context/CallbackContext.java b/omega/omega-context/src/main/java/org/apache/servicecomb/saga/omega/context/CallbackContext.java index 0fe2613c..cf5ab508 100644 --- a/omega/omega-context/src/main/java/org/apache/servicecomb/saga/omega/context/CallbackContext.java +++ b/omega/omega-context/src/main/java/org/apache/servicecomb/saga/omega/context/CallbackContext.java @@ -35,9 +35,9 @@ public CallbackContext(OmegaContext omegaContext) { this.omegaContext = omegaContext; } - public void addCallbackContext(Method compensationMethod, Object target) { + public void addCallbackContext(String key, Method compensationMethod, Object target) { compensationMethod.setAccessible(true); -contexts.put(compensationMethod.toString(), new CallbackContextInternal(target, compensationMethod)); +contexts.put(key, new CallbackContextInternal(target, compensationMethod)); } public void apply(String globalTxId, String localTxId, String callbackMethod, Object... payloads) { diff --git a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/CompensableAnnotationProcessor.java b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/CompensableAnnotationProcessor.java index 790394f7..254c3e73 100644 --- a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/CompensableAnnotationProcessor.java +++ b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/CompensableAnnotationProcessor.java @@ -36,13 +36,13 @@ @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { -checkMethod(bean); -checkFields(bean); return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { +checkMethod(bean); +checkFields(bean); return bean; } diff --git a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/MethodCheckingCallback.java b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/MethodCheckingCallback.java index 8a2ac138..6c523134 100644 --- a/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/MethodCheckingCallback.java +++ b/omega/omega-spring-tx/src/main/java/org/apache/servicecomb/saga/omega/transaction/spring/MethodCheckingCallback.java @@ -18,11 +18,15 @@ package org.apache.servicecomb.saga.omega.transaction.spring; import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; import java.lang.reflect.Method; import org.apache.servicecomb.saga.omega.context.CallbackContext; import org.apache.servicecomb.saga.omega.transaction.OmegaException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.AdvisedSupport; +import org.springframework.aop.framework.AopProxy; +import org.springframework.aop.support.AopUtils; import org.springframework.util.ReflectionUtils.MethodCallback; public abstract class MethodCheckingCallback implements MethodCallback { @@ -45,12 +49,50 @@ protected void loadMethodContext(Method method, String ... candidates) { for (String each : candidates) { try { Method signature = bean.getClass().getDeclaredMethod(each, method.getParameterTypes()); -callbackContext.addCallbackContext(signature, bean); +String key = getTargetBean(bean).getClass().getDeclaredMethod(each, method.getParameterTypes()).toString(); +callbackContext.addCallbackContext(key, signature, bean); LOG.debug("Found callback method [{}] in {}", each, bean.getClass().getCanonicalName()); - } catch (NoSuchMethodException ex) { + } catch (Exception ex) { throw new OmegaException( "No such " + callbackType + " method [" + each + "] found in " + bean.getClass().getCanonicalName(), ex); } } } + + private Object getTargetBean(Object proxy) throws Exception { +if(!AopUtils.isAopProxy(proxy)) { + return proxy; +} + +if(AopUtils.isJdkDynamicProxy(proxy)) { + return
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16656634#comment-16656634 ] ASF GitHub Bot commented on SCB-963: coveralls commented on issue #321: SCB-963 Make saga and tcc callback method transactional URL: https://github.com/apache/incubator-servicecomb-saga/pull/321#issuecomment-431324880 [![Coverage Status](https://coveralls.io/builds/19613187/badge)](https://coveralls.io/builds/19613187) Coverage decreased (-0.2%) to 91.992% when pulling **b1492678cf81d1caae3d98bb226c2478a6113dde on cherrylzhao:master** into **5fb192b17d5556952e66ae310f5bd08e5655aeaf on apache:master**. 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: us...@infra.apache.org > 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 > > > 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)
[jira] [Commented] (SCB-963) Saga transactional method can't work when compensation happens
[ https://issues.apache.org/jira/browse/SCB-963?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16656600#comment-16656600 ] ASF GitHub Bot commented on SCB-963: cherrylzhao opened a new pull request #321: SCB-963 Make saga and tcc callback method transactional URL: https://github.com/apache/incubator-servicecomb-saga/pull/321 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: us...@infra.apache.org > 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 > > > 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)