Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion acb-relayer/r-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -128,4 +133,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

public class GRpcBBCServiceClient implements IBBCServiceClient {

static final long RECEIPT_QUERY_DEADLINE_SECONDS = 30L;

private String psId;

private final String product;
Expand Down Expand Up @@ -108,7 +110,7 @@ public AbstractBBCContext getContext() {

@Override
public CrossChainMessageReceipt readCrossChainMessageReceipt(String txhash) {
Response response = this.blockingStub.bbcCall(
Response response = withReceiptQueryDeadline(this.blockingStub).bbcCall(
CallBBCRequest.newBuilder()
.setProduct(this.getProduct())
.setDomain(this.getDomain())
Expand All @@ -127,6 +129,12 @@ public CrossChainMessageReceipt readCrossChainMessageReceipt(String txhash) {
);
}

static CrossChainServiceGrpc.CrossChainServiceBlockingStub withReceiptQueryDeadline(
CrossChainServiceGrpc.CrossChainServiceBlockingStub stub
) {
return stub.withDeadlineAfter(RECEIPT_QUERY_DEADLINE_SECONDS, TimeUnit.SECONDS);
}

@Override
public List<CrossChainMessage> readCrossChainMessagesByHeight(long height) {
Response response = this.blockingStub.bbcCall(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.alipay.antchain.bridge.relayer.core.types.pluginserver;

import java.util.concurrent.TimeUnit;

import com.alipay.antchain.bridge.pluginserver.service.CrossChainServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.junit.Assert;
import org.junit.Test;

public class GRpcBBCServiceClientTest {

@Test
public void receiptQueryStubHasFiniteDeadline() {
ManagedChannel channel = ManagedChannelBuilder
.forAddress("127.0.0.1", 1)
.usePlaintext()
.build();
try {
CrossChainServiceGrpc.CrossChainServiceBlockingStub stub =
CrossChainServiceGrpc.newBlockingStub(channel);
CrossChainServiceGrpc.CrossChainServiceBlockingStub deadlineStub =
GRpcBBCServiceClient.withReceiptQueryDeadline(stub);

Assert.assertNotNull(deadlineStub.getCallOptions().getDeadline());
long remainingSeconds = deadlineStub.getCallOptions().getDeadline()
.timeRemaining(TimeUnit.SECONDS);
Assert.assertTrue(remainingSeconds >= 0);
Assert.assertTrue(remainingSeconds <= GRpcBBCServiceClient.RECEIPT_QUERY_DEADLINE_SECONDS);
} finally {
channel.shutdownNow();
}
}
}