Search in sources :

Example 1 with SUCCESS

use of com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.SUCCESS in project hedera-mirror-node by hashgraph.

the class TransactionPublisherTest method validationRecovers.

@Test
@Timeout(3)
void validationRecovers() {
    // Initialize publisher internals with first transaction
    var request = request().build();
    cryptoServiceStub.addTransactions(Mono.just(response(OK)));
    transactionPublisher.publish(request).as(StepVerifier::create).expectNextCount(1L).expectComplete().verify(Duration.ofSeconds(1L));
    var scenario = request.getScenario();
    assertThat(scenario.getCount()).isEqualTo(1);
    assertThat(scenario.getErrors()).isEmpty();
    // Validate node as down manually
    NodeProperties nodeProperties = monitorProperties.getNodes().iterator().next();
    cryptoServiceStub.addQueries(Mono.just(receipt(ACCOUNT_DELETED)));
    cryptoServiceStub.addTransactions(Mono.just(response(OK)));
    assertThat(transactionPublisher.validateNode(nodeProperties)).isFalse();
    request = request().build();
    transactionPublisher.publish(request).as(StepVerifier::create).expectErrorSatisfies(t -> assertThat(t).isInstanceOf(PublishException.class).hasMessageContaining("No valid nodes available").hasCauseInstanceOf(IllegalArgumentException.class)).verify(Duration.ofSeconds(1L));
    scenario = request.getScenario();
    assertThat(scenario.getCount()).isZero();
    assertThat(scenario.getErrors()).containsOnly(Map.entry(IllegalArgumentException.class.getSimpleName(), 1));
    // Node recovers
    cryptoServiceStub.addQueries(Mono.just(receipt(SUCCESS)));
    cryptoServiceStub.addTransactions(Mono.just(response(OK)));
    assertThat(transactionPublisher.validateNode(nodeProperties)).isTrue();
    request = request().build();
    cryptoServiceStub.addTransactions(Mono.just(response(OK)));
    transactionPublisher.publish(request).as(StepVerifier::create).expectNextCount(1L).expectComplete().verify(Duration.ofSeconds(1L));
    scenario = request.getScenario();
    assertThat(scenario.getCount()).isEqualTo(1);
    assertThat(scenario.getErrors()).isEmpty();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CryptoServiceGrpc(com.hedera.hashgraph.sdk.proto.CryptoServiceGrpc) NodeProperties(com.hedera.mirror.monitor.NodeProperties) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperatorProperties(com.hedera.mirror.monitor.OperatorProperties) OK(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.OK) TransactionType(com.hedera.mirror.monitor.publish.transaction.TransactionType) TimeoutException(java.util.concurrent.TimeoutException) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) ResponseCodeEnum(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum) Query(com.hedera.hashgraph.sdk.proto.Query) Transaction(com.hedera.hashgraph.sdk.proto.Transaction) StreamObserver(io.grpc.stub.StreamObserver) ResponseHeader(com.hedera.hashgraph.sdk.proto.ResponseHeader) Response(com.hedera.hashgraph.sdk.proto.Response) Duration(java.time.Duration) Map(java.util.Map) TransactionReceipt(com.hedera.hashgraph.sdk.proto.TransactionReceipt) TransactionRecord(com.hedera.hashgraph.sdk.proto.TransactionRecord) Server(io.grpc.Server) ACCOUNT_DELETED(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.ACCOUNT_DELETED) SUCCESS(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.SUCCESS) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Set(java.util.Set) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) TransactionGetRecordResponse(com.hedera.hashgraph.sdk.proto.TransactionGetRecordResponse) Test(org.junit.jupiter.api.Test) TransactionGetReceiptResponse(com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse) AfterEach(org.junit.jupiter.api.AfterEach) TransactionResponse(com.hedera.hashgraph.sdk.proto.TransactionResponse) Data(lombok.Data) Log4j2(lombok.extern.log4j.Log4j2) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) Queue(java.util.Queue) Timeout(org.junit.jupiter.api.Timeout) MonitorProperties(com.hedera.mirror.monitor.MonitorProperties) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) NodeProperties(com.hedera.mirror.monitor.NodeProperties) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)1 CryptoServiceGrpc (com.hedera.hashgraph.sdk.proto.CryptoServiceGrpc)1 Query (com.hedera.hashgraph.sdk.proto.Query)1 Response (com.hedera.hashgraph.sdk.proto.Response)1 ResponseCodeEnum (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum)1 ACCOUNT_DELETED (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.ACCOUNT_DELETED)1 OK (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.OK)1 SUCCESS (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.SUCCESS)1 ResponseHeader (com.hedera.hashgraph.sdk.proto.ResponseHeader)1 Transaction (com.hedera.hashgraph.sdk.proto.Transaction)1 TransactionGetReceiptResponse (com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse)1 TransactionGetRecordResponse (com.hedera.hashgraph.sdk.proto.TransactionGetRecordResponse)1 TransactionReceipt (com.hedera.hashgraph.sdk.proto.TransactionReceipt)1 TransactionRecord (com.hedera.hashgraph.sdk.proto.TransactionRecord)1 TransactionResponse (com.hedera.hashgraph.sdk.proto.TransactionResponse)1 MonitorProperties (com.hedera.mirror.monitor.MonitorProperties)1 NodeProperties (com.hedera.mirror.monitor.NodeProperties)1 OperatorProperties (com.hedera.mirror.monitor.OperatorProperties)1