use of com.hedera.hashgraph.sdk.proto.Response in project hedera-sdk-java by hashgraph.
the class ExecutableTest method executeQueryDelay.
@Test
void executeQueryDelay() throws PrecheckStatusException, TimeoutException {
when(node3.isHealthy()).thenReturn(true);
when(node4.isHealthy()).thenReturn(true);
when(node3.channelFailedToConnect()).thenReturn(false);
when(node4.channelFailedToConnect()).thenReturn(false);
AtomicInteger i = new AtomicInteger();
var tx = new DummyQuery() {
@Override
Status mapResponseStatus(com.hedera.hashgraph.sdk.proto.Response response) {
return Status.RECEIPT_NOT_FOUND;
}
@Override
ExecutionState shouldRetry(Status status, Response response) {
return i.getAndIncrement() == 0 ? ExecutionState.Retry : ExecutionState.Success;
}
};
var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5));
tx.setNodeAccountIds(nodeAccountIds);
var receipt = com.hedera.hashgraph.sdk.proto.TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.OK).build();
var receiptResp = com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse.newBuilder().setReceipt(receipt).build();
var resp = Response.newBuilder().setTransactionGetReceipt(receiptResp).build();
tx.blockingUnaryCall = (grpcRequest) -> resp;
TransactionReceipt rcp = (TransactionReceipt) tx.execute(client);
verify(node3).channelFailedToConnect();
verify(node4).channelFailedToConnect();
}
use of com.hedera.hashgraph.sdk.proto.Response in project hedera-sdk-java by hashgraph.
the class ExecutableTest method executeWithAllUnhealthyNodes.
@Test
void executeWithAllUnhealthyNodes() throws PrecheckStatusException, TimeoutException {
AtomicInteger i = new AtomicInteger();
// 1st round, pick node3, fail channel connect
// 2nd round, pick node4, fail channel connect
// 3rd round, pick node5, fail channel connect
// 4th round, pick node 3, wait for delay, channel connect ok
when(node3.isHealthy()).thenAnswer((Answer<Boolean>) inv -> i.get() == 0);
when(node4.isHealthy()).thenAnswer((Answer<Boolean>) inv -> i.get() == 0);
when(node5.isHealthy()).thenAnswer((Answer<Boolean>) inv -> i.get() == 0);
when(node3.channelFailedToConnect()).thenAnswer((Answer<Boolean>) inv -> i.get() == 0);
when(node4.channelFailedToConnect()).thenAnswer((Answer<Boolean>) inv -> i.get() == 0);
when(node5.channelFailedToConnect()).thenAnswer((Answer<Boolean>) inv -> i.getAndIncrement() == 0);
when(node3.getRemainingTimeForBackoff()).thenReturn(500L);
when(node4.getRemainingTimeForBackoff()).thenReturn(600L);
when(node5.getRemainingTimeForBackoff()).thenReturn(700L);
var now = org.threeten.bp.Instant.now();
var tx = new DummyTransaction() {
@Nullable
@Override
TransactionResponse mapResponse(com.hedera.hashgraph.sdk.proto.TransactionResponse response, AccountId nodeId, com.hedera.hashgraph.sdk.proto.Transaction request) {
return new TransactionResponse(new AccountId(3), TransactionId.withValidStart(new AccountId(3), now), null, null);
}
};
var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5));
tx.setNodeAccountIds(nodeAccountIds);
var txResp = com.hedera.hashgraph.sdk.proto.TransactionResponse.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.OK).build();
tx.blockingUnaryCall = (grpcRequest) -> txResp;
com.hedera.hashgraph.sdk.TransactionResponse resp = (com.hedera.hashgraph.sdk.TransactionResponse) tx.execute(client);
verify(node3, times(2)).channelFailedToConnect();
verify(node4).channelFailedToConnect();
verify(node5).channelFailedToConnect();
assertThat(resp.nodeId).isEqualTo(new AccountId(3));
}
use of com.hedera.hashgraph.sdk.proto.Response in project hedera-mirror-node by hashgraph.
the class TransactionPublisherTest method publishRetrySameRequest.
@Test
@Timeout(3)
void publishRetrySameRequest() {
ResponseCodeEnum errorResponseCode = ResponseCodeEnum.PLATFORM_NOT_ACTIVE;
cryptoServiceStub.addTransactions(Mono.just(response(errorResponseCode)), Mono.just(response(errorResponseCode)));
var request = request().build();
transactionPublisher.publish(request).as(StepVerifier::create).expectErrorSatisfies(t -> assertThat(t).isInstanceOf(PublishException.class).hasMessageContaining("exceeded maximum attempts for request with last exception being").getRootCause().hasMessageContaining(errorResponseCode.toString())).verify(Duration.ofSeconds(2L));
cryptoServiceStub.addTransactions(Mono.just(response(OK)));
transactionPublisher.publish(request).as(StepVerifier::create).expectNextCount(1L).expectComplete().verify(Duration.ofSeconds(1L));
}
use of com.hedera.hashgraph.sdk.proto.Response in project hedera-mirror-node by hashgraph.
the class TransactionPublisherTest method publishPreCheckError.
@Test
@Timeout(3)
void publishPreCheckError() {
ResponseCodeEnum errorResponseCode = ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE;
cryptoServiceStub.addTransactions(Mono.just(response(errorResponseCode)));
transactionPublisher.publish(request().build()).as(StepVerifier::create).expectErrorSatisfies(t -> assertThat(t).isInstanceOf(PublishException.class).hasMessageContaining(errorResponseCode.toString())).verify(Duration.ofSeconds(1L));
}
use of com.hedera.hashgraph.sdk.proto.Response in project hedera-mirror-node by hashgraph.
the class TransactionPublisherTest method publishRetryError.
@Test
@Timeout(3)
void publishRetryError() {
ResponseCodeEnum errorResponseCode = ResponseCodeEnum.PLATFORM_TRANSACTION_NOT_CREATED;
cryptoServiceStub.addTransactions(Mono.just(response(errorResponseCode)), Mono.just(response(errorResponseCode)));
transactionPublisher.publish(request().build()).as(StepVerifier::create).expectErrorSatisfies(t -> assertThat(t).isInstanceOf(PublishException.class).hasMessageContaining("exceeded maximum attempts for request with last exception being").getRootCause().hasMessageContaining(errorResponseCode.toString())).verify(Duration.ofSeconds(2L));
}
Aggregations