Skip to content

Commit c1b9008

Browse files
committed
hip-1299 add more integration tests
Signed-off-by: emiliyank <[email protected]>
1 parent ae7dcc3 commit c1b9008

File tree

3 files changed

+461
-72
lines changed

3 files changed

+461
-72
lines changed

sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -473,40 +473,6 @@ public synchronized Client setMirrorNetwork(List<String> network) throws Interru
473473
return this;
474474
}
475475

476-
/**
477-
* Trigger an immediate address book update.
478-
* This will fetch the address book even if periodic updates are disabled.
479-
*/
480-
public synchronized Client updateNetworkFromAddressBook() {
481-
try {
482-
var fileId = FileId.getAddressBookFileIdFor(this.shard, this.realm);
483-
484-
logger.debug("Fetching address book from file {}", fileId);
485-
System.out.println("Fetching address book from file " + fileId);
486-
487-
// Execute synchronously - no async complexity
488-
var addressBook = new AddressBookQuery()
489-
.setFileId(fileId)
490-
.execute(this); // ← Synchronous!
491-
492-
logger.debug("Received address book with {} nodes", addressBook.nodeAddresses.size());
493-
System.out.println("address book size: " + addressBook.nodeAddresses.size());
494-
495-
// Update the network
496-
this.setNetworkFromAddressBook(addressBook);
497-
498-
logger.info("Address book update completed successfully");
499-
System.out.println("Address book update completed successfully");
500-
501-
} catch (TimeoutException e) {
502-
logger.warn("Failed to fetch address book: {}", e.getMessage());
503-
} catch (Exception e) {
504-
logger.warn("Failed to update address book", e);
505-
}
506-
507-
return this;
508-
}
509-
510476
private synchronized void scheduleNetworkUpdate(@Nullable Duration delay) {
511477
if (delay == null) {
512478
networkUpdateFuture = null;
@@ -1445,26 +1411,33 @@ public synchronized Client setNetworkUpdatePeriod(Duration networkUpdatePeriod)
14451411
*
14461412
* @return {@code this}
14471413
*/
1448-
// public synchronized Client updateNetworkFromAddressBook() {
1449-
//// scheduleNetworkUpdate(Duration.ZERO);
1450-
// updateNetworkFromAddressBook2();
1451-
//
1452-
// if (networkUpdateFuture != null) {
1453-
// try {
1454-
// networkUpdateFuture.get(30, TimeUnit.SECONDS);
1455-
// logger.debug("Address book update completed successfully");
1456-
// } catch (TimeoutException e) {
1457-
// logger.warn("Address book update timed out after 30 seconds", e);
1458-
// } catch (InterruptedException e) {
1459-
// Thread.currentThread().interrupt();
1460-
// logger.warn("Address book update was interrupted", e);
1461-
// } catch (ExecutionException e) {
1462-
// logger.warn("Address book update failed", e);
1463-
// }
1464-
// }
1465-
//
1466-
// return this;
1467-
// }
1414+
public synchronized Client updateNetworkFromAddressBook() {
1415+
try {
1416+
var fileId = FileId.getAddressBookFileIdFor(this.shard, this.realm);
1417+
1418+
logger.debug("Fetching address book from file {}", fileId);
1419+
System.out.println("Fetching address book from file " + fileId);
1420+
1421+
// Execute synchronously - no async complexity
1422+
var addressBook = new AddressBookQuery().setFileId(fileId).execute(this); // ← Synchronous!
1423+
1424+
logger.debug("Received address book with {} nodes", addressBook.nodeAddresses.size());
1425+
System.out.println("address book size: " + addressBook.nodeAddresses.size());
1426+
1427+
// Update the network
1428+
this.setNetworkFromAddressBook(addressBook);
1429+
1430+
logger.info("Address book update completed successfully");
1431+
System.out.println("Address book update completed successfully");
1432+
1433+
} catch (TimeoutException e) {
1434+
logger.warn("Failed to fetch address book: {}", e.getMessage());
1435+
} catch (Exception e) {
1436+
logger.warn("Failed to update address book", e);
1437+
}
1438+
1439+
return this;
1440+
}
14681441

14691442
public Logger getLogger() {
14701443
return this.logger;

sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,10 @@ void setNodesFromNodeAccountIds(Client client) {
613613
if (nodeAccountIds.size() == 1) {
614614
var nodeProxies = client.network.getNodeProxies(nodeAccountIds.get(0));
615615
if (nodeProxies == null || nodeProxies.isEmpty()) {
616-
logger.warn("Node {} not found in network, fetching latest address book",
617-
nodeAccountIds.get(0));
616+
logger.warn("Node {} not found in network, fetching latest address book", nodeAccountIds.get(0));
618617

619618
try {
620-
client.updateNetworkFromAddressBook(); // Synchronous update
619+
client.updateNetworkFromAddressBook(); // Synchronous update
621620
nodeProxies = client.network.getNodeProxies(nodeAccountIds.get(0));
622621
} catch (Exception e) {
623622
logger.error("Failed to update address book", e);
@@ -915,14 +914,11 @@ ExecutionState getExecutionState(Status status, ResponseT response) {
915914
return ExecutionState.SERVER_ERROR;
916915
case BUSY:
917916
return ExecutionState.RETRY;
918-
//TODO - use ExecutionState.SUCCESS otherwise there is issue with transaction receipt - raised status INVALID_NODE_ACCOUNT
919-
// case INVALID_NODE_ACCOUNT:
920-
// // Matches Go SDK's executionStateRetryWithAnotherNode behavior:
921-
// // immediately retry with next node without delay
922-
// // This occurs when a node's account ID has changed
923-
// return ExecutionState.SERVER_ERROR;
924-
case INVALID_NODE_ACCOUNT:
925-
case OK:
917+
case INVALID_NODE_ACCOUNT:
918+
return ExecutionState
919+
.SERVER_ERROR; // immediately retry with next node without delay. This occurs when a node's
920+
// account ID has changed
921+
case OK:
926922
return ExecutionState.SUCCESS;
927923
default:
928924
return ExecutionState.REQUEST_ERROR; // user error

0 commit comments

Comments
 (0)