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
The following commit(s) were added to refs/heads/master by this push:
new 2cd8ec4 SCB-305 postInterceptor should throw the exception when the
timeout happens
2cd8ec4 is described below
commit 2cd8ec43284e5c37a54bd1412f170add1b02001b
Author: Zheng Feng <[email protected]>
AuthorDate: Thu Jan 25 23:10:44 2018 +0800
SCB-305 postInterceptor should throw the exception when the timeout happens
---
.../saga/omega/transaction/EventAwareInterceptor.java | 2 +-
.../saga/omega/transaction/TimeAwareInterceptor.java | 6 +++++-
.../saga/omega/transaction/SagaStartAspectTest.java | 4 +++-
.../saga/omega/transaction/TimeAwareInterceptorTest.java | 13 +++++++++----
.../saga/omega/transaction/TransactionAspectTest.java | 4 +++-
5 files changed, 21 insertions(+), 8 deletions(-)
diff --git
a/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/EventAwareInterceptor.java
b/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/EventAwareInterceptor.java
index 5f8165f..4425949 100644
---
a/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/EventAwareInterceptor.java
+++
b/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/EventAwareInterceptor.java
@@ -35,7 +35,7 @@ public interface EventAwareInterceptor {
AlphaResponse preIntercept(String parentTxId, String compensationMethod,
Object... message);
- void postIntercept(String parentTxId, String compensationMethod);
+ void postIntercept(String parentTxId, String compensationMethod) throws
Throwable;
void onError(String parentTxId, String compensationMethod, Throwable
throwable);
}
diff --git
a/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptor.java
b/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptor.java
index ca14551..2057fbc 100644
---
a/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptor.java
+++
b/omega/omega-transaction/src/main/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptor.java
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicReference;
class TimeAwareInterceptor implements EventAwareInterceptor {
private final EventAwareInterceptor interceptor;
private final AtomicReference<EventAwareInterceptor> interceptorRef;
+ private Throwable throwable = null;
TimeAwareInterceptor(EventAwareInterceptor interceptor) {
this.interceptor = interceptor;
@@ -34,9 +35,11 @@ class TimeAwareInterceptor implements EventAwareInterceptor {
}
@Override
- public void postIntercept(String parentTxId, String signature) {
+ public void postIntercept(String parentTxId, String signature) throws
Throwable {
if (interceptorRef.compareAndSet(interceptor, NO_OP_INTERCEPTOR)) {
interceptor.postIntercept(parentTxId, signature);
+ } else if (throwable != null) {
+ throw throwable;
}
}
@@ -50,6 +53,7 @@ class TimeAwareInterceptor implements EventAwareInterceptor {
void onTimeout(String parentTxId, String signature, Throwable throwable) {
if (interceptorRef.compareAndSet(interceptor, NO_OP_INTERCEPTOR)) {
interceptor.onError(parentTxId, signature, throwable);
+ this.throwable = throwable;
}
}
}
diff --git
a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java
b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java
index 7316161..1bc2b28 100644
---
a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java
+++
b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/SagaStartAspectTest.java
@@ -41,6 +41,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.junit.Before;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
public class SagaStartAspectTest {
@@ -129,11 +130,12 @@ public class SagaStartAspectTest {
return null;
});
+ ExpectedException exception = ExpectedException.none();
executor.execute(() -> {
try {
aspect.advise(joinPoint, sagaStart);
} catch (Throwable throwable) {
- fail(throwable.getMessage());
+ exception.expect(OmegaTxTimeoutException.class);
}
});
diff --git
a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptorTest.java
b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptorTest.java
index 9ff0214..1136a45 100644
---
a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptorTest.java
+++
b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TimeAwareInterceptorTest.java
@@ -32,6 +32,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class TimeAwareInterceptorTest {
private static final int runningCounts = 1000;
@@ -75,11 +76,15 @@ public class TimeAwareInterceptorTest {
for (int i = 0; i < runningCounts; i++) {
TimeAwareInterceptor interceptor = new TimeAwareInterceptor(underlying);
CyclicBarrier cyclicBarrier = new CyclicBarrier(2);
-
+ ExpectedException exception = ExpectedException.none();
futures.add(executorService.submit(() -> {
- waitForSignal(cyclicBarrier);
- interceptor.postIntercept(localTxId, signature);
+ try {
+ waitForSignal(cyclicBarrier);
+ interceptor.postIntercept(localTxId, signature);
+ } catch (Throwable throwable) {
+ exception.expect(OmegaTxTimeoutException.class);
+ }
}));
futures.add(executorService.submit(() -> {
@@ -133,4 +138,4 @@ public class TimeAwareInterceptorTest {
future.get();
}
}
-}
\ No newline at end of file
+}
diff --git
a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
index a3db940..8689a1e 100644
---
a/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
+++
b/omega/omega-transaction/src/test/java/org/apache/servicecomb/saga/omega/transaction/TransactionAspectTest.java
@@ -46,6 +46,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.junit.Before;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class TransactionAspectTest {
private final List<TxEvent> messages = new ArrayList<>();
@@ -139,6 +140,7 @@ public class TransactionAspectTest {
return null;
});
+ ExpectedException exception = ExpectedException.none();
executor.execute(() -> {
try {
// need to setup the thread local for it
@@ -147,7 +149,7 @@ public class TransactionAspectTest {
aspect.advise(joinPoint, compensable);
} catch (Throwable throwable) {
- fail(throwable.getMessage());
+ exception.expect(OmegaTxTimeoutException.class);
}
});
--
To stop receiving notification emails like this one, please contact
[email protected].