Search in sources :

Example 1 with Transaction

use of com.hedera.hashgraph.sdk.proto.Transaction 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)

Example 2 with Transaction

use of com.hedera.hashgraph.sdk.proto.Transaction in project hedera-sdk-java by hashgraph.

the class RegenerateTransactionIdsTest method regeneratesTransactionIdsWhenTransactionExpiredIsReturned.

@Test
void regeneratesTransactionIdsWhenTransactionExpiredIsReturned() throws PrecheckStatusException, TimeoutException, InterruptedException {
    var transactionIds = new HashSet<TransactionId>();
    AtomicInteger count = new AtomicInteger(0);
    var responses = List.of(TransactionResponse.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.TRANSACTION_EXPIRED).build(), TransactionResponse.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.TRANSACTION_EXPIRED).build(), TransactionResponse.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.TRANSACTION_EXPIRED).build(), TransactionResponse.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.OK).build());
    var call = (Function<Object, Object>) o -> {
        try {
            var transaction = (Transaction) o;
            var signedTransaction = SignedTransaction.parseFrom(transaction.getSignedTransactionBytes());
            var transactionBody = TransactionBody.parseFrom(signedTransaction.getBodyBytes());
            var transactionId = TransactionId.fromProtobuf(transactionBody.getTransactionID());
            if (transactionIds.contains(transactionId)) {
                return Status.Code.ABORTED.toStatus().asRuntimeException();
            }
            transactionIds.add(transactionId);
            return responses.get(count.getAndIncrement());
        } catch (Throwable e) {
            return new RuntimeException(e);
        }
    };
    List<Object> responses1 = List.of(call, call, call, call);
    try (var mocker = Mocker.withResponses(List.of(responses1))) {
        new FileCreateTransaction().execute(mocker.client);
    }
}
Also used : Function(java8.util.function.Function) Transaction(com.hedera.hashgraph.sdk.proto.Transaction) SignedTransaction(com.hedera.hashgraph.sdk.proto.SignedTransaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

Transaction (com.hedera.hashgraph.sdk.proto.Transaction)2 Test (org.junit.jupiter.api.Test)2 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 SignedTransaction (com.hedera.hashgraph.sdk.proto.SignedTransaction)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