[ 
https://issues.apache.org/jira/browse/SCB-224?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16395342#comment-16395342
 ] 

ASF GitHub Bot commented on SCB-224:
------------------------------------

WillemJiang commented on a change in pull request #138: [WIP] SCB-224 retry 
sub-transaction on failure
URL: 
https://github.com/apache/incubator-servicecomb-saga/pull/138#discussion_r173795656
 
 

 ##########
 File path: 
omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
 ##########
 @@ -125,37 +120,88 @@ public void restoreContextOnCompensableError() throws 
Throwable {
   }
 
   @Test
-  public void returnImmediatelyWhenReceivedRejectResponse() throws Throwable {
-    MessageSender sender = mock(MessageSender.class);
-    when(sender.send(any())).thenReturn(new AlphaResponse(true));
+  public void retryReachesMaximumAndForwardException() throws Throwable {
+    RuntimeException oops = new RuntimeException("oops");
+    when(joinPoint.proceed()).thenThrow(oops);
+    when(compensable.retries()).thenReturn(3);
 
-    TransactionAspect aspect = new TransactionAspect(sender, omegaContext);
     try {
       aspect.advise(joinPoint, compensable);
-      expectFailing(InvalidTransactionException.class);
-    } catch (InvalidTransactionException e) {
-      System.out.println(e.getMessage());
-      assertThat(e.getMessage().contains("Abort sub transaction"), is(true));
+      expectFailing(RuntimeException.class);
+    } catch (RuntimeException e) {
+      assertThat(e.getMessage(), is("oops"));
     }
 
-    verify(sender, times(1)).send(any());
+    assertThat(messages.size(), is(6));
+
+    TxEvent startedEvent1 = messages.get(0);
+    assertThat(startedEvent1.globalTxId(), is(globalTxId));
+    assertThat(startedEvent1.localTxId(), is(newLocalTxId));
+    assertThat(startedEvent1.parentTxId(), is(localTxId));
+    assertThat(startedEvent1.type(), is(EventType.TxStartedEvent));
+    assertThat(startedEvent1.retries(), is(3));
+    assertThat(startedEvent1.retryMethod(), 
is(this.getClass().getDeclaredMethod("doNothing").toString()));
+
+    assertThat(messages.get(1).type(), is(EventType.TxAbortedEvent));
+
+    TxEvent startedEvent2 = messages.get(2);
+    assertThat(startedEvent2.localTxId(), is(newLocalTxId));
+    assertThat(startedEvent2.type(), is(EventType.TxStartedEvent));
+    assertThat(startedEvent2.retries(), is(2));
+
+    assertThat(messages.get(3).type(), is(EventType.TxAbortedEvent));
+
+    TxEvent startedEvent3 = messages.get(4);
+    assertThat(startedEvent3.localTxId(), is(newLocalTxId));
+    assertThat(startedEvent3.type(), is(EventType.TxStartedEvent));
+    assertThat(startedEvent3.retries(), is(1));
+
+    assertThat(messages.get(5).type(), is(EventType.TxAbortedEvent));
+
+    assertThat(omegaContext.globalTxId(), is(globalTxId));
+    assertThat(omegaContext.localTxId(), is(localTxId));
   }
 
   @Test
-  public void recordRetryMethodWhenRetriesIsSet() throws Throwable {
-    int retries = new Random().nextInt(Integer.MAX_VALUE - 1) + 1;
-    when(compensable.retries()).thenReturn(retries);
+  public void keepRetryingTillSuccess() throws Throwable {
+    RuntimeException oops = new RuntimeException("oops");
+    when(joinPoint.proceed()).thenThrow(oops).thenThrow(oops).thenReturn(null);
+    when(compensable.retries()).thenReturn(-1);
 
-    aspect.advise(joinPoint, compensable);
+    try {
+      aspect.advise(joinPoint, compensable);
+    } catch (Exception e) {
 
 Review comment:
   We don't need to catch the exception here, as the JUnit test failed when the 
exception is throw.

----------------------------------------------------------------
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


> [pack] retry sub-transaction on failure
> ---------------------------------------
>
>                 Key: SCB-224
>                 URL: https://issues.apache.org/jira/browse/SCB-224
>             Project: Apache ServiceComb
>          Issue Type: New Feature
>          Components: Saga
>            Reporter: Yin Xiang
>            Assignee: Eric Lee
>            Priority: Major
>             Fix For: saga-0.2.0
>
>
> as a user, i want to retry transaction in my service, so that it can always 
> be done eventually.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to