WillemJiang closed pull request #278: SCB-856 Add onTccCoordinated grpc method
for alpha server.
URL: https://github.com/apache/incubator-servicecomb-saga/pull/278
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/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 e3b89b99..0eaf9563 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.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 void
onTccTransactionEnded(GrpcTccTransactionEndedEvent request, StreamOb
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 2e6e1f23..68597145 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.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 void assertOnTccTransactionSucceedEnded() {
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 @@ private GrpcTccTransactionEndedEvent newTxEnd(String
status) {
.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();
}
----------------------------------------------------------------
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]
With regards,
Apache Git Services