diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.java.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.java.gradle.kts index 037c2d2b0..db6a9e48f 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.java.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.java.gradle.kts @@ -73,7 +73,13 @@ tasks.withType().configureEach { } } +tasks.withType().configureEach { + failFast = true + maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1) +} + tasks.jacocoTestReport { + dependsOn(tasks.withType()) // make sure to use any/all test coverage data for the report and run all tests before this report is made executionData.from( tasks.test.map { it.extensions.getByType().destinationFile!! }, diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java index abcbb4938..df5ab47b0 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java @@ -27,6 +27,7 @@ import java.time.Duration; import java.time.Instant; import java.util.Objects; +import java.util.Random; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicLong; @@ -68,6 +69,7 @@ public final class TransactionId implements Comparable { private static final long NANOSECONDS_TO_REMOVE = 10000000000L; + private static final Random randomNanosecs = new Random(); private static final AtomicLong monotonicTime = new AtomicLong(); @@ -115,6 +117,7 @@ public static TransactionId generate(AccountId accountId) { // between the client and the receiving node and prevented spurious INVALID_TRANSACTION_START. currentTime = System.currentTimeMillis() * NANOSECONDS_PER_MILLISECOND - NANOSECONDS_TO_REMOVE; + // Get the last recorded timestamp. lastTime = monotonicTime.get(); @@ -125,7 +128,7 @@ public static TransactionId generate(AccountId accountId) { } } while (!monotonicTime.compareAndSet(lastTime, currentTime)); - return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime)); + return new TransactionId(accountId, Instant.ofEpochSecond(0, currentTime + randomNanosecs.nextLong(1_000))); } /** diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java index 359d24b99..86037ebdc 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java @@ -36,6 +36,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import javax.annotation.Nullable; import org.junit.jupiter.api.Assumptions; @@ -48,6 +50,7 @@ public class IntegrationTestEnv implements AutoCloseable { public PublicKey operatorKey; public AccountId operatorId; public boolean isLocalNode = false; + private static ExecutorService clientExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); public IntegrationTestEnv() throws Exception { this(0); @@ -104,7 +107,7 @@ private static Client createTestEnvClient() throws Exception { network.put(LOCAL_CONSENSUS_NODE_ENDPOINT, LOCAL_CONSENSUS_NODE_ACCOUNT_ID); return Client - .forNetwork(network) + .forNetwork(network, clientExecutor) .setMirrorNetwork(List.of(LOCAL_MIRROR_NODE_GRPC_ENDPOINT)); } else if (!System.getProperty("CONFIG_FILE").equals("")) { try { @@ -152,19 +155,23 @@ public void assumeNotLocalNode() throws Exception { @Override public void close() throws Exception { if (!operatorId.equals(originalClient.getOperatorAccountId())) { - var hbarsBalance = new AccountBalanceQuery() - .setAccountId(operatorId) - .execute(originalClient) - .hbars; - new TransferTransaction() - .addHbarTransfer(operatorId, hbarsBalance.negated()) - .addHbarTransfer(Objects.requireNonNull(originalClient.getOperatorAccountId()), hbarsBalance) - .freezeWith(originalClient) - .signWithOperator(client) - .execute(originalClient); - client.close(); + try { + var hbarsBalance = new AccountBalanceQuery() + .setAccountId(operatorId) + .execute(originalClient) + .hbars; + new TransferTransaction() + .addHbarTransfer(operatorId, hbarsBalance.negated()) + .addHbarTransfer(Objects.requireNonNull(originalClient.getOperatorAccountId()), hbarsBalance) + .freezeWith(originalClient) + .signWithOperator(client) + .execute(originalClient) + .getReceipt(originalClient); + + } catch (Exception e) { + client.close(); + } } - originalClient.close(); }