Skip to content

Commit

Permalink
Merge branch 'main' into 2035-Client-should-not-shutdown-provided-exe…
Browse files Browse the repository at this point in the history
…cutor
  • Loading branch information
0xivanov authored Nov 6, 2024
2 parents 68dc1f1 + 3c1912b commit e422507
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugins {
repositories.gradlePluginPortal()

dependencies {
implementation("com.autonomousapps:dependency-analysis-gradle-plugin:2.3.0")
implementation("com.autonomousapps:dependency-analysis-gradle-plugin:2.4.2")
implementation("com.google.protobuf:protobuf-gradle-plugin:0.9.4")
implementation("io.github.gradle-nexus:publish-plugin:1.3.0")
implementation("org.gradlex:extra-java-module-info:1.9")
Expand Down
6 changes: 3 additions & 3 deletions sdk-dependency-versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ dependencies.constraints {
api("com.google.code.findbugs:jsr305:3.0.2") {
because("java.annotation")
}
api("org.bouncycastle:bcpkix-jdk18on:1.78.1") {
api("org.bouncycastle:bcpkix-jdk18on:1.79") {
because("org.bouncycastle.pkix")
}
api("org.bouncycastle:bcprov-jdk18on:1.78.1") {
api("org.bouncycastle:bcprov-jdk18on:1.79") {
because("org.bouncycastle.provider")
}
api("org.slf4j:slf4j-api:2.0.9") {
Expand All @@ -69,7 +69,7 @@ dependencies.constraints {
}

// Testing
api("com.fasterxml.jackson.core:jackson-core:2.18.0") {
api("com.fasterxml.jackson.core:jackson-core:2.18.1") {
because("com.fasterxml.jackson.core")
}
api("io.github.cdimascio:java-dotenv:5.3.1") {
Expand Down
11 changes: 7 additions & 4 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void setNodesFromNodeAccountIds(Client client) {
// failure the system can retry with different proxy on each attempt
if (nodeAccountIds.size() == 1) {
var nodeProxies = client.network.getNodeProxies(nodeAccountIds.get(0));
if (nodeProxies == null || nodeProxies.size() == 0) {
if (nodeProxies == null || nodeProxies.isEmpty()) {
throw new IllegalStateException("Account ID did not map to valid node in the client's network");
}

Expand All @@ -615,15 +615,18 @@ void setNodesFromNodeAccountIds(Client client) {
for (var accountId : nodeAccountIds) {
@Nullable
var nodeProxies = client.network.getNodeProxies(accountId);
if (nodeProxies == null || nodeProxies.size() == 0) {
throw new IllegalStateException(
"Some node account IDs did not map to valid nodes in the client's network");
if (nodeProxies == null || nodeProxies.isEmpty()) {
continue;
}

var node = nodeProxies.get(random.nextInt(nodeProxies.size()));

nodes.add(Objects.requireNonNull(node));
}
if (nodes.isEmpty()) {
throw new IllegalStateException(
"All node account IDs did not map to valid nodes in the client's network");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.hedera.hashgraph.sdk.test.integration;

import com.hedera.hashgraph.sdk.*;
import java.util.Collections;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.time.Duration;
Expand All @@ -32,14 +33,47 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

public class ClientIntegrationTest {

@Test
@DisplayName("fails when all the manually set nodes are not matching the address book")
void failsWhenNoNodesAreMatching() throws Exception {
var client = Client.forTestnet()
.setTransportSecurity(true);

var nodes = new ArrayList<AccountId>();
nodes.add(new AccountId(1000));
nodes.add(new AccountId(1001));
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> new AccountBalanceQuery()
.setNodeAccountIds(nodes)
.setAccountId(new AccountId(7))
.execute(client)).withMessageContaining("All node account IDs did not map to valid nodes in the client's network");
client.close();
}

@Test
@DisplayName("can skip invalid nodes")
void canSkipNodes() throws Exception {
var client = Client.forTestnet()
.setTransportSecurity(true);

var nodes = new ArrayList<>(client.getNetwork().values().stream().toList());
nodes.add(new AccountId(1000));
new AccountBalanceQuery()
.setNodeAccountIds(nodes)
.setAccountId(new AccountId(7))
.execute(client);

client.close();
}

@Test
@DisplayName("setNetwork() functions correctly")
void testReplaceNodes() throws Exception {
Map<String, AccountId> network = new HashMap<>();
network.put("0.testnet.hedera.com:50211", new AccountId(3));
network.put("1.testnet.hedera.com:50211", new AccountId(4));

try(var testEnv = new IntegrationTestEnv(1)){
try (var testEnv = new IntegrationTestEnv(1)) {

testEnv.client
.setMaxQueryPayment(new Hbar(2))
Expand Down Expand Up @@ -88,7 +122,7 @@ void transactionIdNetworkIsVerified() {
@Test
@DisplayName("`setMaxNodesPerTransaction()`")
void testMaxNodesPerTransaction() throws Exception {
try(var testEnv = new IntegrationTestEnv(1)){
try (var testEnv = new IntegrationTestEnv(1)) {

testEnv.client.setMaxNodesPerTransaction(1);

Expand All @@ -104,7 +138,7 @@ void testMaxNodesPerTransaction() throws Exception {

@Test
void ping() throws Exception {
try(var testEnv = new IntegrationTestEnv(1)){
try (var testEnv = new IntegrationTestEnv(1)) {
var network = testEnv.client.getNetwork();
var nodes = new ArrayList<>(network.values());

Expand All @@ -119,7 +153,7 @@ void ping() throws Exception {

@Test
void pingAll() throws Exception {
try(var testEnv = new IntegrationTestEnv()){
try (var testEnv = new IntegrationTestEnv()) {

testEnv.client.setMaxNodeAttempts(1);
testEnv.client.pingAll();
Expand All @@ -140,7 +174,7 @@ void pingAll() throws Exception {

@Test
void pingAllBadNetwork() throws Exception {
try(var testEnv = new IntegrationTestEnv(3)){
try (var testEnv = new IntegrationTestEnv(3)) {

// Skip if using local node.
// Note: this check should be removed once the local node is supporting multiple nodes.
Expand All @@ -161,7 +195,6 @@ void pingAllBadNetwork() throws Exception {

testEnv.client.setNetwork(network);


assertThatExceptionOfType(MaxAttemptsExceededException.class).isThrownBy(() -> {
testEnv.client.pingAll();
}).withMessageContaining("exceeded maximum attempts");
Expand All @@ -177,12 +210,12 @@ void pingAllBadNetwork() throws Exception {

assertThat(testEnv.client.getNetwork().values().size()).isEqualTo(1);
}

}

@Test
void pingAsync() throws Exception {
try(var testEnv = new IntegrationTestEnv(1)){
try (var testEnv = new IntegrationTestEnv(1)) {
var network = testEnv.client.getNetwork();
var nodes = new ArrayList<>(network.values());

Expand All @@ -197,7 +230,7 @@ void pingAsync() throws Exception {

@Test
void pingAllAsync() throws Exception {
try(var testEnv = new IntegrationTestEnv()){
try (var testEnv = new IntegrationTestEnv()) {

testEnv.client.setMaxNodeAttempts(1);
testEnv.client.pingAllAsync().get();
Expand All @@ -212,7 +245,7 @@ void pingAllAsync() throws Exception {
new AccountBalanceQuery()
.setAccountId(node)
.execute(testEnv.client);

}
}
}

0 comments on commit e422507

Please sign in to comment.