Skip to content

Commit 4079b88

Browse files
committed
add withDeadlineAfter for newBlockingStub
1 parent 8a4066b commit 4079b88

File tree

5 files changed

+49
-33
lines changed

5 files changed

+49
-33
lines changed

framework/src/test/java/org/tron/core/services/RpcApiServicesTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.grpc.ManagedChannelBuilder;
1212
import java.io.IOException;
1313
import java.util.Objects;
14+
import java.util.concurrent.TimeUnit;
1415
import org.junit.AfterClass;
1516
import org.junit.Assert;
1617
import org.junit.BeforeClass;
@@ -167,12 +168,18 @@ public static void init() throws IOException {
167168
.usePlaintext()
168169
.build();
169170
context = new TronApplicationContext(DefaultConfig.class);
170-
databaseBlockingStubFull = DatabaseGrpc.newBlockingStub(channelFull);
171-
databaseBlockingStubSolidity = DatabaseGrpc.newBlockingStub(channelSolidity);
172-
databaseBlockingStubPBFT = DatabaseGrpc.newBlockingStub(channelPBFT);
173-
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
174-
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
175-
blockingStubPBFT = WalletSolidityGrpc.newBlockingStub(channelPBFT);
171+
databaseBlockingStubFull = DatabaseGrpc.newBlockingStub(channelFull)
172+
.withDeadlineAfter(5, TimeUnit.SECONDS);
173+
databaseBlockingStubSolidity = DatabaseGrpc.newBlockingStub(channelSolidity)
174+
.withDeadlineAfter(5, TimeUnit.SECONDS);
175+
databaseBlockingStubPBFT = DatabaseGrpc.newBlockingStub(channelPBFT)
176+
.withDeadlineAfter(5, TimeUnit.SECONDS);
177+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull)
178+
.withDeadlineAfter(5, TimeUnit.SECONDS);
179+
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity)
180+
.withDeadlineAfter(5, TimeUnit.SECONDS);
181+
blockingStubPBFT = WalletSolidityGrpc.newBlockingStub(channelPBFT)
182+
.withDeadlineAfter(5, TimeUnit.SECONDS);
176183

177184
Manager manager = context.getBean(Manager.class);
178185

framework/src/test/java/org/tron/core/services/WalletApiTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.grpc.ManagedChannelBuilder;
44
import java.io.IOException;
5+
import java.util.concurrent.TimeUnit;
56
import lombok.extern.slf4j.Slf4j;
67
import org.junit.AfterClass;
78
import org.junit.Assert;
@@ -32,7 +33,7 @@ public class WalletApiTest {
3233

3334
@BeforeClass
3435
public static void init() throws IOException {
35-
Args.setParam(new String[]{ "-d", temporaryFolder.newFolder().toString(),
36+
Args.setParam(new String[] {"-d", temporaryFolder.newFolder().toString(),
3637
"--p2p-disable", "true"}, Constant.TEST_CONF);
3738
Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort());
3839
Args.getInstance().setRpcEnable(true);
@@ -49,7 +50,8 @@ public void listNodesTest() {
4950
.usePlaintext()
5051
.build();
5152
try {
52-
WalletGrpc.WalletBlockingStub walletStub = WalletGrpc.newBlockingStub(channel);
53+
WalletGrpc.WalletBlockingStub walletStub = WalletGrpc.newBlockingStub(channel)
54+
.withDeadlineAfter(5, TimeUnit.SECONDS);
5355
Assert.assertTrue(walletStub.listNodes(EmptyMessage.getDefaultInstance())
5456
.getNodesList().isEmpty());
5557
} finally {

framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class LiteFnQueryGrpcInterceptorTest {
5151
*/
5252
@BeforeClass
5353
public static void init() throws IOException {
54-
Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF);
54+
Args.setParam(new String[] {"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF);
5555
Args.getInstance().setRpcEnable(true);
5656
Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort());
5757
Args.getInstance().setRpcSolidityEnable(true);
@@ -60,24 +60,27 @@ public static void init() throws IOException {
6060
Args.getInstance().setRpcOnPBFTPort(PublicMethod.chooseRandomPort());
6161
Args.getInstance().setP2pDisable(true);
6262
String fullnode = String.format("%s:%d", Constant.LOCAL_HOST,
63-
Args.getInstance().getRpcPort());
63+
Args.getInstance().getRpcPort());
6464
String solidityNode = String.format("%s:%d", Constant.LOCAL_HOST,
65-
Args.getInstance().getRpcOnSolidityPort());
65+
Args.getInstance().getRpcOnSolidityPort());
6666
String pBFTNode = String.format("%s:%d", Constant.LOCAL_HOST,
6767
Args.getInstance().getRpcOnPBFTPort());
6868
channelFull = ManagedChannelBuilder.forTarget(fullnode)
69-
.usePlaintext()
70-
.build();
69+
.usePlaintext()
70+
.build();
7171
channelSolidity = ManagedChannelBuilder.forTarget(solidityNode)
7272
.usePlaintext()
7373
.build();
7474
channelpBFT = ManagedChannelBuilder.forTarget(pBFTNode)
75-
.usePlaintext()
76-
.build();
75+
.usePlaintext()
76+
.build();
7777
context = new TronApplicationContext(DefaultConfig.class);
78-
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
79-
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
80-
blockingStubpBFT = WalletSolidityGrpc.newBlockingStub(channelpBFT);
78+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull)
79+
.withDeadlineAfter(5, TimeUnit.SECONDS);
80+
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity)
81+
.withDeadlineAfter(5, TimeUnit.SECONDS);
82+
blockingStubpBFT = WalletSolidityGrpc.newBlockingStub(channelpBFT)
83+
.withDeadlineAfter(5, TimeUnit.SECONDS);
8184
chainBaseManager = context.getBean(ChainBaseManager.class);
8285
Application appTest = ApplicationFactory.create(context);
8386
appTest.startup();

framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Collections;
1515
import java.util.List;
1616
import java.util.Objects;
17+
import java.util.concurrent.TimeUnit;
1718
import lombok.extern.slf4j.Slf4j;
1819
import org.junit.AfterClass;
1920
import org.junit.BeforeClass;
@@ -83,9 +84,12 @@ public static void init() throws IOException {
8384

8485
context = new TronApplicationContext(DefaultConfig.class);
8586

86-
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
87-
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
88-
blockingStubPBFT = WalletSolidityGrpc.newBlockingStub(channelPBFT);
87+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull)
88+
.withDeadlineAfter(5, TimeUnit.SECONDS);
89+
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity)
90+
.withDeadlineAfter(5, TimeUnit.SECONDS);
91+
blockingStubPBFT = WalletSolidityGrpc.newBlockingStub(channelPBFT)
92+
.withDeadlineAfter(5, TimeUnit.SECONDS);
8993

9094
Application appTest = ApplicationFactory.create(context);
9195
appTest.startup();

plugins/src/test/java/org/tron/plugins/DbLiteTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.concurrent.TimeUnit;
1111
import lombok.extern.slf4j.Slf4j;
1212
import org.junit.After;
13-
import org.junit.ClassRule;
1413
import org.junit.Rule;
1514
import org.junit.rules.TemporaryFolder;
1615
import org.tron.api.WalletGrpc;
@@ -54,7 +53,8 @@ public void startApp() {
5453
channelFull = ManagedChannelBuilder.forTarget(fullNode)
5554
.usePlaintext()
5655
.build();
57-
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
56+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull)
57+
.withDeadlineAfter(5, TimeUnit.SECONDS);
5858
}
5959

6060
/**
@@ -69,8 +69,8 @@ public void shutdown() throws InterruptedException {
6969

7070
public void init(String dbType) throws IOException {
7171
dbPath = folder.newFolder().toString();
72-
Args.setParam(new String[]{
73-
"-d", dbPath, "-w", "--p2p-disable", "true", "--storage-db-engine", dbType},
72+
Args.setParam(new String[] {
73+
"-d", dbPath, "-w", "--p2p-disable", "true", "--storage-db-engine", dbType},
7474
"config-localtest.conf");
7575
// allow account root
7676
Args.getInstance().setAllowAccountStateRoot(1);
@@ -92,15 +92,15 @@ public void testTools(String dbType, int checkpointVersion)
9292
dbPath = String.format("%s_%s_%d", dbPath, dbType, System.currentTimeMillis());
9393
init(dbType);
9494
final String[] argsForSnapshot =
95-
new String[]{"-o", "split", "-t", "snapshot", "--fn-data-path",
95+
new String[] {"-o", "split", "-t", "snapshot", "--fn-data-path",
9696
dbPath + File.separator + databaseDir, "--dataset-path",
9797
dbPath};
9898
final String[] argsForHistory =
99-
new String[]{"-o", "split", "-t", "history", "--fn-data-path",
99+
new String[] {"-o", "split", "-t", "history", "--fn-data-path",
100100
dbPath + File.separator + databaseDir, "--dataset-path",
101101
dbPath};
102102
final String[] argsForMerge =
103-
new String[]{"-o", "merge", "--fn-data-path", dbPath + File.separator + databaseDir,
103+
new String[] {"-o", "merge", "--fn-data-path", dbPath + File.separator + databaseDir,
104104
"--dataset-path", dbPath + File.separator + "history"};
105105
Args.getInstance().getStorage().setCheckpointVersion(checkpointVersion);
106106
DbLite.setRecentBlks(3);
@@ -126,15 +126,15 @@ public void testTools(String dbType, int checkpointVersion)
126126
File database = new File(Paths.get(dbPath, databaseDir).toString());
127127
if (!database.renameTo(new File(Paths.get(dbPath, databaseDir + "_bak").toString()))) {
128128
throw new RuntimeException(
129-
String.format("rename %s to %s failed", database.getPath(),
130-
Paths.get(dbPath, databaseDir)));
129+
String.format("rename %s to %s failed", database.getPath(),
130+
Paths.get(dbPath, databaseDir)));
131131
}
132132
// change snapshot to the new database
133133
File snapshot = new File(Paths.get(dbPath, "snapshot").toString());
134134
if (!snapshot.renameTo(new File(Paths.get(dbPath, databaseDir).toString()))) {
135135
throw new RuntimeException(
136-
String.format("rename snapshot to %s failed",
137-
Paths.get(dbPath, databaseDir)));
136+
String.format("rename snapshot to %s failed",
137+
Paths.get(dbPath, databaseDir)));
138138
}
139139
// start and validate the snapshot
140140
startApp();
@@ -161,7 +161,7 @@ private void generateSomeTransactions(int during) {
161161
String sunPri = getRandomPrivateKey();
162162
byte[] sunAddress = PublicMethod.getFinalAddress(sunPri);
163163
PublicMethod.sendcoin(address, 1L,
164-
sunAddress, sunPri, blockingStubFull);
164+
sunAddress, sunPri, blockingStubFull);
165165
try {
166166
Thread.sleep(sleepOnce);
167167
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)