Skip to content

Commit 482ff30

Browse files
committed
<fix>(integration): fix integration client not exit bug.
1 parent 50ed1ac commit 482ff30

19 files changed

+338
-99
lines changed

.ci/ci_check.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ check_standard_node()
138138
prepare_environment "${2}"
139139
## run integration test
140140
bash gradlew clean integrationTest --info
141+
# if $? is not 0, then exit
142+
if [ ${?} -ne 0 ]; then
143+
cat log/*.log
144+
fi
141145
## clean
142146
clean_node "${1}"
143147
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ext {
2424
webankJavaCryptoVersion = "1.0.3"
2525
junitVersion = '4.13.2'
2626
commonsCollections4Version = "4.4"
27-
bcosSdkJniVersion = "3.6.0-DEV-SNAPSHOT"
27+
bcosSdkJniVersion = "3.6.0-SNAPSHOT"
2828
slf4jApiVerison = '1.7.36'
2929
mockitoVersion = '4.8.0'
3030
gsonVersion = '2.10.1'

src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java

Lines changed: 91 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ public void testClient() {
8484
BcosSDK sdk = BcosSDK.build(configFile);
8585

8686
Client client = sdk.getClient(GROUP);
87-
Assert.assertThrows(BcosSDKException.class,
88-
() -> sdk.getClient("errorClient"));
87+
Assert.assertThrows(BcosSDKException.class, () -> sdk.getClient("errorClient"));
8988

90-
sdk.registerBlockNotifier(GROUP,
89+
sdk.registerBlockNotifier(
90+
GROUP,
9191
(groupId, blockNumber) ->
92-
System.out.println("New block, group: " + groupId + ", blockNumber: " + blockNumber));
92+
System.out.println(
93+
"New block, group: " + groupId + ", blockNumber: " + blockNumber));
9394

9495
// test getBlockNumber
9596
BlockNumber blockNumber = client.getBlockNumber();
@@ -100,7 +101,8 @@ public void testClient() {
100101

101102
// test getBlockByNumber only header
102103
BcosBlock onlyHeader = client.getBlockByNumber(blockNumber.getBlockNumber(), true, false);
103-
Assert.assertEquals(onlyHeader.getBlock().getHash(), blockHashByNumber.getBlockHashByNumber());
104+
Assert.assertEquals(
105+
onlyHeader.getBlock().getHash(), blockHashByNumber.getBlockHashByNumber());
104106

105107
// test getBlockByNumber
106108
BcosBlock block = client.getBlockByNumber(blockNumber.getBlockNumber(), false, false);
@@ -132,7 +134,12 @@ public void testClient() {
132134

133135
// get getTotalTransactionCount
134136
TotalTransactionCount totalTransactionCount = client.getTotalTransactionCount();
135-
Assert.assertTrue(Integer.parseInt(totalTransactionCount.getTotalTransactionCount().getTransactionCount()) >= 0);
137+
Assert.assertTrue(
138+
Integer.parseInt(
139+
totalTransactionCount
140+
.getTotalTransactionCount()
141+
.getTransactionCount())
142+
>= 0);
136143

137144
// get getPeers
138145
Peers peers = client.getPeers();
@@ -145,11 +152,12 @@ public void testClient() {
145152
// get getSyncStatus
146153
SyncStatus syncStatus = client.getSyncStatus();
147154
System.out.println(syncStatus.getSyncStatus().toString());
155+
client.stop();
156+
client.destroy();
148157
}
149158

150159
@Test
151-
public void testClientAsync()
152-
throws ConfigException, ExecutionException, InterruptedException {
160+
public void testClientAsync() throws ConfigException, ExecutionException, InterruptedException {
153161

154162
ConfigOption configOption = Config.load(configFile);
155163
Client client = Client.build(GROUP, configOption);
@@ -172,8 +180,7 @@ public void onResponse(BcosBlock bcosBlock) {
172180
@Override
173181
public void onError(Response errorResponse) {
174182
System.out.println(
175-
"getBlockByNumberAsync failed: " +
176-
errorResponse.getErrorMessage());
183+
"getBlockByNumberAsync failed: " + errorResponse.getErrorMessage());
177184
}
178185
});
179186
genesisHash[0] = hashFuture.get();
@@ -187,22 +194,27 @@ public void onError(Response errorResponse) {
187194
@Override
188195
public void onResponse(BcosBlock bcosBlock) {
189196
System.out.println("getBlockByNumberAsync=" + bcosBlock.getBlock());
190-
client.getBlockHashByNumberAsync(BigInteger.valueOf(bcosBlock.getBlock().getNumber()), new RespCallback<BlockHash>() {
191-
@Override
192-
public void onResponse(BlockHash blockHash) {
193-
System.out.println("getBlockHashByNumberAsync=" + blockHash.getBlockHashByNumber());
194-
}
195-
196-
@Override
197-
public void onError(Response errorResponse) {
198-
System.out.println(errorResponse);
199-
}
200-
});
197+
client.getBlockHashByNumberAsync(
198+
BigInteger.valueOf(bcosBlock.getBlock().getNumber()),
199+
new RespCallback<BlockHash>() {
200+
@Override
201+
public void onResponse(BlockHash blockHash) {
202+
System.out.println(
203+
"getBlockHashByNumberAsync="
204+
+ blockHash.getBlockHashByNumber());
205+
}
206+
207+
@Override
208+
public void onError(Response errorResponse) {
209+
System.out.println(errorResponse);
210+
}
211+
});
201212
}
202213

203214
@Override
204215
public void onError(Response errorResponse) {
205-
System.out.println("getBlockByNumberAsync failed: " + errorResponse.getErrorMessage());
216+
System.out.println(
217+
"getBlockByNumberAsync failed: " + errorResponse.getErrorMessage());
206218
}
207219
});
208220

@@ -246,7 +258,12 @@ public void onError(Response errorResponse) {
246258

247259
// get getTotalTransactionCount
248260
TotalTransactionCount totalTransactionCount = client.getTotalTransactionCount();
249-
Assert.assertTrue(Integer.parseInt(totalTransactionCount.getTotalTransactionCount().getTransactionCount()) >= 0);
261+
Assert.assertTrue(
262+
Integer.parseInt(
263+
totalTransactionCount
264+
.getTotalTransactionCount()
265+
.getTransactionCount())
266+
>= 0);
250267

251268
// get getPeers
252269
Peers peers = client.getPeers();
@@ -256,17 +273,23 @@ public void onError(Response errorResponse) {
256273
SyncStatus syncStatus = client.getSyncStatus();
257274
System.out.println(syncStatus.getSyncStatus());
258275

259-
client.getTotalTransactionCountAsync(new RespCallback<TotalTransactionCount>() {
260-
@Override
261-
public void onResponse(TotalTransactionCount totalTransactionCount) {
262-
Assert.assertTrue(Integer.parseInt(totalTransactionCount.getTotalTransactionCount().getTransactionCount()) >= 0);
263-
}
276+
client.getTotalTransactionCountAsync(
277+
new RespCallback<TotalTransactionCount>() {
278+
@Override
279+
public void onResponse(TotalTransactionCount totalTransactionCount) {
280+
Assert.assertTrue(
281+
Integer.parseInt(
282+
totalTransactionCount
283+
.getTotalTransactionCount()
284+
.getTransactionCount())
285+
>= 0);
286+
}
264287

265-
@Override
266-
public void onError(Response errorResponse) {
267-
System.out.println(errorResponse);
268-
}
269-
});
288+
@Override
289+
public void onError(Response errorResponse) {
290+
System.out.println(errorResponse);
291+
}
292+
});
270293

271294
// test getBlockNumber
272295
client.getBlockNumberAsync(
@@ -282,10 +305,13 @@ public void onError(Response errorResponse) {
282305
"getBlockNumberAsync failed: " + errorResponse.getErrorMessage());
283306
}
284307
});
308+
309+
client.stop();
310+
client.destroy();
285311
}
286312

287313
@Test
288-
public void testHelloWorldInSolidity() throws ConfigException, JniException, ContractException {
314+
public void testHelloWorldInSolidity() throws ConfigException, ContractException {
289315

290316
ConfigOption configOption = Config.load(configFile);
291317
Client client = Client.build(GROUP, configOption);
@@ -309,17 +335,19 @@ public void testHelloWorldInSolidity() throws ConfigException, JniException, Con
309335
helloWorld = HelloWorld.deploy(client, cryptoKeyPair);
310336
System.out.println("helloworld address :" + helloWorld.getContractAddress());
311337

312-
client.getABIAsync(helloWorld.getContractAddress(), new RespCallback<Abi>() {
313-
@Override
314-
public void onResponse(Abi abi) {
315-
Assert.assertEquals(HelloWorld.getABI(), abi.getABI());
316-
}
338+
client.getABIAsync(
339+
helloWorld.getContractAddress(),
340+
new RespCallback<Abi>() {
341+
@Override
342+
public void onResponse(Abi abi) {
343+
Assert.assertEquals(HelloWorld.getABI(), abi.getABI());
344+
}
317345

318-
@Override
319-
public void onError(Response errorResponse) {
320-
System.out.println(errorResponse);
321-
}
322-
});
346+
@Override
347+
public void onError(Response errorResponse) {
348+
System.out.println(errorResponse);
349+
}
350+
});
323351

324352
BlockNumber blockNumber = client.getBlockNumber();
325353
BcosBlock block1 = client.getBlockByNumber(blockNumber.getBlockNumber(), false, false);
@@ -334,7 +362,9 @@ public void onError(Response errorResponse) {
334362
String txHash = receipt.getTransactionHash();
335363
BcosTransaction transaction1 = client.getTransaction(txHash, false);
336364
BcosTransactionReceipt transactionReceipt = client.getTransactionReceipt(txHash, false);
337-
if (client.getChainCompatibilityVersion().compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj()) >= 0) {
365+
if (client.getChainCompatibilityVersion()
366+
.compareTo(EnumNodeVersion.BCOS_3_2_0.toVersionObj())
367+
>= 0) {
338368
Assert.assertEquals(extraData, receipt.getExtraData());
339369
Assert.assertEquals(extraData, transaction1.getResult().getExtraData());
340370
Assert.assertEquals(extraData, transactionReceipt.getResult().getExtraData());
@@ -368,6 +398,9 @@ public void onError(Response errorResponse) {
368398

369399
blockLimit = client.getBlockLimit();
370400
System.out.println("blockLimit:" + blockLimit);
401+
402+
client.stop();
403+
client.destroy();
371404
}
372405

373406
@Test
@@ -385,7 +418,8 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
385418
"set",
386419
Arrays.<Type>asList(new Utf8String("fisco hello")),
387420
Collections.<TypeReference<?>>emptyList());
388-
FunctionEncoderInterface functionEncoderInterface = new FunctionEncoder(client.getCryptoSuite());
421+
FunctionEncoderInterface functionEncoderInterface =
422+
new FunctionEncoder(client.getCryptoSuite());
389423
byte[] encode = functionEncoderInterface.encode(function);
390424
String input = Hex.toHexString(encode);
391425

@@ -410,7 +444,11 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
410444
String extraData = "extraData";
411445
String signedMessage =
412446
TransactionBuilderJniObj.createSignedTransaction(
413-
transactionData, transactionDataHashSignedData2, transactionDataHash, 0, extraData);
447+
transactionData,
448+
transactionDataHashSignedData2,
449+
transactionDataHash,
450+
0,
451+
extraData);
414452

415453
TransactionPusherService txPusher = new TransactionPusherService(client);
416454
TransactionReceipt receipt2 = txPusher.push(signedMessage);
@@ -421,10 +459,12 @@ public void testTransactionAssemble() throws ConfigException, JniException, Cont
421459
receipt2.setMessage(receiptMsg);
422460

423461
System.out.println(receipt2);
462+
client.stop();
463+
client.destroy();
424464
}
425465

426466
@Test
427-
public void testGetGroupList() throws ConfigException, JniException {
467+
public void testGetGroupList() throws ConfigException {
428468
ConfigOption configOption = Config.load(configFile);
429469

430470
System.out.println("configOption: " + configOption);
@@ -434,11 +474,13 @@ public void testGetGroupList() throws ConfigException, JniException {
434474
List<String> groupList = clientWithoutGroupId.getGroupList().getResult().getGroupList();
435475
System.out.println("getGroupList: " + groupList);
436476

437-
BcosSDK bcosSDK = new BcosSDK(configOption);
438477
for (String groupId : groupList) {
478+
BcosSDK bcosSDK = new BcosSDK(configOption);
439479
Client client = bcosSDK.getClient(groupId);
440480
System.out.println("build client, groupId: " + groupId);
441481
System.out.println("getBlockNumber, blk: " + client.getBlockNumber().getBlockNumber());
482+
client.stop();
483+
client.destroy();
442484
}
443485
}
444486
}

src/integration-test/java/org/fisco/bcos/sdk/v3/test/precompiled/PrecompiledTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public void test1ConsensusService() throws ConfigException, ContractException, J
151151
List<String> observerList4 = client.getObserverList().getResult();
152152
System.out.println("observerList4: " + observerList4);
153153
Assert.assertFalse(observerList4.contains(selectedNode.getNodeID()));
154+
155+
client.stop();
156+
client.destroy();
154157
}
155158

156159
@Test
@@ -175,6 +178,8 @@ public void test3SystemConfigService() throws ConfigException, ContractException
175178

176179
this.testSystemConfigService(client, systemConfigService, "tx_count_limit");
177180
this.testSystemConfigService(client, systemConfigService, "tx_gas_limit");
181+
client.stop();
182+
client.destroy();
178183
}
179184

180185
private void testSystemConfigService(
@@ -264,10 +269,12 @@ public void test5CRUDService() throws ConfigException, ContractException {
264269
result = tableCRUDService.select(tableName, "key1");
265270
Assert.assertTrue(result.isEmpty());
266271
System.out.println("testCRUDPrecompiled tableCRUDService.remove size : " + result.size());
272+
client.stop();
273+
client.destroy();
267274
}
268275

269276
@Test
270-
public void test51SyncCRUDService() throws ConfigException, ContractException, JniException {
277+
public void test51SyncCRUDService() throws ConfigException, ContractException {
271278

272279
ConfigOption configOption = Config.load(configFile);
273280
Client client = Client.build(GROUP, configOption);
@@ -328,6 +335,8 @@ public void test51SyncCRUDService() throws ConfigException, ContractException, J
328335
.getTransactionCount());
329336
System.out.println("orgTxCount: " + orgTxCount + ", currentTxCount:" + currentTxCount);
330337
Assert.assertTrue(currentTxCount.compareTo(orgTxCount.add(BigInteger.valueOf(300))) >= 0);
338+
client.stop();
339+
client.destroy();
331340
}
332341

333342
class FakeTransactionCallback implements PrecompiledCallback {
@@ -408,6 +417,8 @@ public void test52AsyncCRUDService()
408417
.getTransactionCount());
409418
System.out.println("orgTxCount: " + orgTxCount + ", currentTxCount:" + currentTxCount);
410419
Assert.assertTrue(currentTxCount.compareTo(orgTxCount.add(BigInteger.valueOf(300))) >= 0);
420+
client.stop();
421+
client.destroy();
411422
}
412423

413424
@Test
@@ -439,6 +450,8 @@ public void test6KVService() throws ConfigException, ContractException {
439450
// field value result + key result
440451
Assert.assertEquals(key1, "value1");
441452
System.out.println("kvTableService select result: " + key1);
453+
client.stop();
454+
client.destroy();
442455
}
443456

444457
@Test
@@ -483,5 +496,7 @@ public void test7BFSPrecompiled() throws ConfigException, ContractException {
483496
}
484497
}
485498
Assert.assertTrue(flag);
499+
client.stop();
500+
client.destroy();
486501
}
487502
}

0 commit comments

Comments
 (0)