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();
}
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);
}
}
Aggregations