36
36
import java .util .List ;
37
37
import java .util .Map ;
38
38
import java .util .Objects ;
39
+ import java .util .concurrent .ExecutorService ;
40
+ import java .util .concurrent .Executors ;
39
41
import javax .annotation .Nullable ;
40
42
import org .junit .jupiter .api .Assumptions ;
41
43
@@ -48,6 +50,7 @@ public class IntegrationTestEnv implements AutoCloseable {
48
50
public PublicKey operatorKey ;
49
51
public AccountId operatorId ;
50
52
public boolean isLocalNode = false ;
53
+ private static ExecutorService clientExecutor = Executors .newFixedThreadPool (Runtime .getRuntime ().availableProcessors ());
51
54
52
55
public IntegrationTestEnv () throws Exception {
53
56
this (0 );
@@ -104,7 +107,7 @@ private static Client createTestEnvClient() throws Exception {
104
107
network .put (LOCAL_CONSENSUS_NODE_ENDPOINT , LOCAL_CONSENSUS_NODE_ACCOUNT_ID );
105
108
106
109
return Client
107
- .forNetwork (network )
110
+ .forNetwork (network , clientExecutor )
108
111
.setMirrorNetwork (List .of (LOCAL_MIRROR_NODE_GRPC_ENDPOINT ));
109
112
} else if (!System .getProperty ("CONFIG_FILE" ).equals ("" )) {
110
113
try {
@@ -152,19 +155,23 @@ public void assumeNotLocalNode() throws Exception {
152
155
@ Override
153
156
public void close () throws Exception {
154
157
if (!operatorId .equals (originalClient .getOperatorAccountId ())) {
155
- var hbarsBalance = new AccountBalanceQuery ()
156
- .setAccountId (operatorId )
157
- .execute (originalClient )
158
- .hbars ;
159
- new TransferTransaction ()
160
- .addHbarTransfer (operatorId , hbarsBalance .negated ())
161
- .addHbarTransfer (Objects .requireNonNull (originalClient .getOperatorAccountId ()), hbarsBalance )
162
- .freezeWith (originalClient )
163
- .signWithOperator (client )
164
- .execute (originalClient );
165
- client .close ();
158
+ try {
159
+ var hbarsBalance = new AccountBalanceQuery ()
160
+ .setAccountId (operatorId )
161
+ .execute (originalClient )
162
+ .hbars ;
163
+ new TransferTransaction ()
164
+ .addHbarTransfer (operatorId , hbarsBalance .negated ())
165
+ .addHbarTransfer (Objects .requireNonNull (originalClient .getOperatorAccountId ()), hbarsBalance )
166
+ .freezeWith (originalClient )
167
+ .signWithOperator (client )
168
+ .execute (originalClient )
169
+ .getReceipt (originalClient );
170
+
171
+ } catch (Exception e ) {
172
+ client .close ();
173
+ }
166
174
}
167
-
168
175
originalClient .close ();
169
176
}
170
177
0 commit comments