Skip to content

Commit

Permalink
<fix>(client): add default nodeName to send request. (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay authored Oct 7, 2023
1 parent 1b83f6c commit 0962c09
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {
exclude group: "org.fisco-bcos.java-sdk"
exclude group: "org.slf4j"
}
compile ('com.fasterxml.jackson.core:jackson-databind:2.14.2'){
compile ('com.fasterxml.jackson.core:jackson-databind:2.14.3'){
force true
}
testCompile('com.github.stefanbirkner:system-rules:1.19.0')
Expand Down
2 changes: 1 addition & 1 deletion src/integration-test/java/console/ConsoleClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void clientNotParamsTest() throws IOException {
consoleClientFace.getGroupInfoList(emptyParams);
assertTrue(log.getLog().startsWith("["));
log.clearLog();
consoleClientFace.getNodeName();
consoleClientFace.getNodeName(consoleInitializer);
}

@Test
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/console/client/ConsoleClientFace.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package console.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import console.ConsoleInitializer;
import java.io.IOException;
import org.fisco.bcos.sdk.v3.client.Client;

Expand Down Expand Up @@ -63,9 +64,9 @@ public interface ConsoleClientFace {

void getGroupNodeInfo(String[] params) throws JsonProcessingException;

void setNodeName(String[] params) throws IOException;
void setNodeName(ConsoleInitializer consoleInitializer, String[] params) throws IOException;

void clearNodeName();
void clearNodeName(ConsoleInitializer consoleInitializer);

void getNodeName();
void getNodeName(ConsoleInitializer consoleInitializer);
}
18 changes: 10 additions & 8 deletions src/main/java/console/client/ConsoleClientImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package console.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import console.ConsoleInitializer;
import console.client.model.TotalTransactionCountResult;
import console.common.Common;
import console.common.ConsoleUtils;
Expand Down Expand Up @@ -473,7 +474,7 @@ public void getGroupNodeInfo(String[] params) throws JsonProcessingException {
}

@Override
public void setNodeName(String[] params) {
public void setNodeName(ConsoleInitializer consoleInitializer, String[] params) {
String newNodeName = params[1];
List<BcosGroupNodeInfo.GroupNodeInfo> nodeInfos =
client.getGroupInfo().getResult().getNodeList();
Expand All @@ -491,23 +492,24 @@ public void setNodeName(String[] params) {
+ ", node not contains in node list, check command 'getGroupInfo'.");
return;
}
this.nodeName = newNodeName;
getNodeName();
consoleInitializer.getClient().setNodeToSendRequest(newNodeName);
getNodeName(consoleInitializer);
}

@Override
public void clearNodeName() {
public void clearNodeName(ConsoleInitializer consoleInitializer) {
System.out.println("Clear nodeName to empty.");
this.nodeName = "";
consoleInitializer.getClient().setNodeToSendRequest("");
}

@Override
public void getNodeName() {
if (this.nodeName.isEmpty()) {
public void getNodeName(ConsoleInitializer consoleInitializer) {
String nodeToSendRequest = consoleInitializer.getClient().getNodeToSendRequest();
if (nodeToSendRequest.isEmpty()) {
System.out.println(
"Current default node name is empty, RPC will send request to node randomly.");
return;
}
System.out.println("Current default node name: " + this.nodeName);
System.out.println("Current default node name: " + nodeToSendRequest);
}
}
12 changes: 9 additions & 3 deletions src/main/java/console/command/category/BasicCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) {
"Set default node name to send request.",
HelpInfo::setNodeNameHelp,
(consoleInitializer, params, pwd) ->
consoleInitializer.getConsoleClientFace().setNodeName(params),
consoleInitializer
.getConsoleClientFace()
.setNodeName(consoleInitializer, params),
1,
1);

Expand All @@ -81,7 +83,9 @@ public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) {
"Get default node name in this client.",
HelpInfo::getNodeNameHelp,
(consoleInitializer, params, pwd) ->
consoleInitializer.getConsoleClientFace().getNodeName(),
consoleInitializer
.getConsoleClientFace()
.getNodeName(consoleInitializer),
0,
0);

Expand All @@ -91,7 +95,9 @@ public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) {
"Clear default node name to empty.",
HelpInfo::clearNodeNameHelp,
(consoleInitializer, params, pwd) ->
consoleInitializer.getConsoleClientFace().clearNodeName(),
consoleInitializer
.getConsoleClientFace()
.clearNodeName(consoleInitializer),
0,
0);

Expand Down

0 comments on commit 0962c09

Please sign in to comment.