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 5b1688e SCB-856 Add onTccCoordinated grpc method for alpha server.
5b1688e is described below
commit 5b1688e3fcdef474898c80974dd942480288b8af
Author: cherrylzhao <[email protected]>
AuthorDate: Wed Aug 29 11:48:15 2018 +0800
SCB-856 Add onTccCoordinated grpc method for alpha server.
---
.../saga/alpha/server/tcc/GrpcTccEventService.java | 11 +++++++++++
.../saga/alpha/tcc/server/AlphaTccServerTest.java | 16 ++++++++++++++++
2 files changed, 27 insertions(+)
diff --git
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java
index e3b89b9..0eaf956 100644
---
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java
+++
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java
@@ -27,6 +27,7 @@ import
org.apache.servicecomb.saga.alpha.server.tcc.registry.TransactionEventReg
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcAck;
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcServiceConfig;
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccCoordinateCommand;
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccCoordinatedEvent;
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccParticipatedEvent;
import
org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccTransactionEndedEvent;
import
org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccTransactionStartedEvent;
@@ -78,6 +79,16 @@ public class GrpcTccEventService extends
TccEventServiceGrpc.TccEventServiceImpl
responseObserver.onNext(tccCallbackEngine.execute(request) ? ALLOW :
REJECT);
responseObserver.onCompleted();
}
+
+ @Override
+ public void onTccCoordinated(GrpcTccCoordinatedEvent request,
StreamObserver<GrpcAck> responseObserver) {
+ LOG.info("Received coordinated event, global tx: {}, local tx: {}, parent
id: {}, "
+ + "method: {}, status: {}, service [{}] instanceId [{}]",
+ request.getGlobalTxId(), request.getLocalTxId(),
request.getParentTxId(),
+ request.getMethodName(), request.getStatus(),
request.getServiceName(), request.getInstanceId());
+ responseObserver.onNext(ALLOW);
+ responseObserver.onCompleted();
+ }
@Override
public void onDisconnected(GrpcServiceConfig request,
StreamObserver<GrpcAck> responseObserver) {
diff --git
a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java
b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java
index 2e6e1f2..6859714 100644
---
a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java
+++
b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java
@@ -38,6 +38,7 @@ import org.apache.servicecomb.saga.common.TransactionStatus;
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcAck;
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcServiceConfig;
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccCoordinateCommand;
+import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccCoordinatedEvent;
import org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccParticipatedEvent;
import
org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccTransactionEndedEvent;
import
org.apache.servicecomb.saga.pack.contract.grpc.GrpcTccTransactionStartedEvent;
@@ -157,6 +158,9 @@ public class AlphaTccServerTest {
assertThat(command.getMethod(), is("confirm"));
assertThat(command.getGlobalTxId(), is(globalTxId));
assertThat(command.getServiceName(), is(serviceName));
+
+ GrpcAck result =
blockingStub.onTccCoordinated(newCoordinatedEvent("Succeed", "Confirm"));
+ assertThat(result.getAborted(), is(false));
}
@Test
@@ -256,6 +260,18 @@ public class AlphaTccServerTest {
.build();
}
+ private GrpcTccCoordinatedEvent newCoordinatedEvent(String status, String
method) {
+ return GrpcTccCoordinatedEvent.newBuilder()
+ .setGlobalTxId(globalTxId)
+ .setLocalTxId(localTxId)
+ .setServiceName(serviceName)
+ .setInstanceId(instanceId)
+ .setMethodName(method)
+ .setStatus(status)
+ .build();
+ }
+
+
private GrpcAck onReceivedCoordinateCommand(GrpcTccCoordinateCommand
command) {
return GrpcAck.newBuilder().setAborted(false).build();
}