25
25
import java .util .concurrent .ExecutorService ;
26
26
import java .util .concurrent .Executors ;
27
27
import java .util .concurrent .atomic .AtomicLong ;
28
+
28
29
import org .fisco .bcos .sdk .jni .common .JniException ;
29
30
import org .fisco .bcos .sdk .v3 .client .Client ;
30
31
import org .fisco .bcos .sdk .v3 .client .protocol .response .SealerList ;
45
46
import org .fisco .bcos .sdk .v3 .contract .precompiled .sysconfig .SystemConfigService ;
46
47
import org .fisco .bcos .sdk .v3 .crypto .keypair .CryptoKeyPair ;
47
48
import org .fisco .bcos .sdk .v3 .model .ConstantConfig ;
49
+ import org .fisco .bcos .sdk .v3 .model .EnumNodeVersion ;
48
50
import org .fisco .bcos .sdk .v3 .model .PrecompiledConstant ;
49
51
import org .fisco .bcos .sdk .v3 .model .PrecompiledRetCode ;
50
52
import org .fisco .bcos .sdk .v3 .model .RetCode ;
@@ -172,28 +174,35 @@ private void testSystemConfigService(
172
174
BigInteger queriedValue =
173
175
new BigInteger (client .getSystemConfigByKey (key ).getSystemConfig ().getValue ());
174
176
System .out .println ("queriedValue: " + queriedValue );
175
- Assert .assertTrue (queriedValue . equals ( updatedValue ) );
176
- Assert .assertTrue (queriedValue . equals ( value .add (BigInteger .valueOf (100 ) )));
177
+ Assert .assertEquals (queriedValue , updatedValue );
178
+ Assert .assertEquals (queriedValue , value .add (BigInteger .valueOf (100 )));
177
179
}
178
180
179
181
@ Test
180
- public void test5CRUDService () throws ConfigException , ContractException , JniException {
182
+ public void test5CRUDService () throws ConfigException , ContractException {
181
183
ConfigOption configOption = Config .load (configFile );
182
184
Client client = Client .build (GROUP , configOption );
183
185
184
186
CryptoKeyPair cryptoKeyPair = client .getCryptoSuite ().getCryptoKeyPair ();
185
187
TableCRUDService tableCRUDService = new TableCRUDService (client , cryptoKeyPair );
186
188
// create a user table
187
- String tableName = "test" + new Random (). nextInt ( 10000 );
189
+ String tableName = "test" + System . currentTimeMillis ( );
188
190
String key = "key" ;
189
191
List <String > valueFields = new ArrayList <>(5 );
190
192
for (int i = 0 ; i < 5 ; i ++) {
191
193
valueFields .add (i , "field" + i );
192
194
}
193
- RetCode code = tableCRUDService .createTable (tableName , Common .TableKeyOrder .valueOf (0 ), key , valueFields );
195
+ RetCode code ;
196
+ Map <String , List <String >> desc ;
197
+ if (client .getChainVersion ().compareTo (EnumNodeVersion .BCOS_3_2_0 .toVersionObj ()) >= 0 ) {
198
+ code = tableCRUDService .createTable (tableName , Common .TableKeyOrder .valueOf (0 ), key , valueFields );
199
+ desc = tableCRUDService .descWithKeyOrder (tableName );
200
+ } else {
201
+ code = tableCRUDService .createTable (tableName , key , valueFields );
202
+ desc = tableCRUDService .desc (tableName );
203
+ }
194
204
Assert .assertEquals (0 , code .getCode ());
195
205
// desc
196
- Map <String , List <String >> desc = tableCRUDService .descWithKeyOrder (tableName );
197
206
Assert .assertEquals (desc .get (PrecompiledConstant .VALUE_FIELD_NAME ), valueFields );
198
207
199
208
// insert
@@ -207,10 +216,19 @@ public void test5CRUDService() throws ConfigException, ContractException, JniExc
207
216
// select key
208
217
Map <String , String > result = tableCRUDService .select (tableName , "key1" );
209
218
210
- ConditionV320 condition = new ConditionV320 ();
211
- condition .EQ (key ,"990" );
212
- condition .setLimit (0 , 10 );
213
- List <Map <String , String >> select = tableCRUDService .select (tableName , condition );
219
+ if (client .getChainVersion ().compareTo (EnumNodeVersion .BCOS_3_2_0 .toVersionObj ()) >= 0 ) {
220
+ ConditionV320 condition = new ConditionV320 ();
221
+ condition .EQ (key , "key1" );
222
+ condition .setLimit (0 , 10 );
223
+ List <Map <String , String >> select = tableCRUDService .select (tableName , condition );
224
+ Assert .assertEquals (select .size (), 1 );
225
+ } else {
226
+ Condition condition = new Condition ();
227
+ condition .EQ ("key1" );
228
+ condition .setLimit (0 , 10 );
229
+ List <Map <String , String >> select = tableCRUDService .select (tableName , condition );
230
+ Assert .assertEquals (select .size (), 1 );
231
+ }
214
232
// field value result + key result
215
233
Assert .assertEquals (result .size (), valueFields .size () + 1 );
216
234
System .out .println ("tableCRUDService select result: " + result );
@@ -244,7 +262,12 @@ public void test51SyncCRUDService() throws ConfigException, ContractException, J
244
262
String tableName = "test_sync" + System .currentTimeMillis ();
245
263
List <String > valueFiled = new ArrayList <>();
246
264
valueFiled .add ("field" );
247
- RetCode retCode = crudService .createTable (tableName , Common .TableKeyOrder .valueOf (0 ), "key" , valueFiled );
265
+ RetCode retCode ;
266
+ if (client .getChainVersion ().compareTo (EnumNodeVersion .BCOS_3_2_0 .toVersionObj ()) >= 0 ) {
267
+ retCode = crudService .createTable (tableName , Common .TableKeyOrder .valueOf (0 ), "key" , valueFiled );
268
+ } else {
269
+ retCode = crudService .createTable (tableName , "key" , valueFiled );
270
+ }
248
271
System .out .println ("tableName" + tableName );
249
272
System .out .println (
250
273
"createResult: " + retCode .getCode () + ", message: " + retCode .getMessage ());
@@ -317,7 +340,11 @@ public void test52AsyncCRUDService()
317
340
List <String > valueFiled = new ArrayList <>();
318
341
valueFiled .add ("field" );
319
342
String key = "key" ;
320
- crudService .createTable (tableName , Common .TableKeyOrder .valueOf (0 ), key , valueFiled );
343
+ if (client .getChainVersion ().compareTo (EnumNodeVersion .BCOS_3_2_0 .toVersionObj ()) >= 0 ) {
344
+ crudService .createTable (tableName , Common .TableKeyOrder .valueOf (0 ), key , valueFiled );
345
+ } else {
346
+ crudService .createTable (tableName , key , valueFiled );
347
+ }
321
348
// create a thread pool to parallel insert and select
322
349
ExecutorService threadPool = Executors .newFixedThreadPool (50 );
323
350
BigInteger orgTxCount =
@@ -369,19 +396,24 @@ public void test52AsyncCRUDService()
369
396
}
370
397
371
398
@ Test
372
- public void test6KVService () throws ConfigException , ContractException , JniException {
399
+ public void test6KVService () throws ConfigException , ContractException {
373
400
ConfigOption configOption = Config .load (configFile );
374
401
Client client = Client .build (GROUP , configOption );
375
402
376
403
CryptoKeyPair cryptoKeyPair = client .getCryptoSuite ().getCryptoKeyPair ();
377
404
KVTableService kvTableService = new KVTableService (client , cryptoKeyPair );
378
405
// create a user table
379
- String tableName = "test" + ( int ) ( Math . random () * 1000 );
406
+ String tableName = "test" + System . currentTimeMillis ( );
380
407
String key = "key" ;
381
408
RetCode code = kvTableService .createTable (tableName , key , "field" );
382
409
Assert .assertEquals (0 , code .getCode ());
383
410
// desc
384
- Map <String , String > desc = kvTableService .descWithKeyOrder (tableName );
411
+ Map <String , String > desc ;
412
+ if (client .getChainVersion ().compareTo (EnumNodeVersion .BCOS_3_2_0 .toVersionObj ()) >= 0 ) {
413
+ desc = kvTableService .descWithKeyOrder (tableName );
414
+ } else {
415
+ desc = kvTableService .desc (tableName );
416
+ }
385
417
Assert .assertEquals (desc .get (PrecompiledConstant .VALUE_FIELD_NAME ), "field" );
386
418
387
419
// set
@@ -395,7 +427,7 @@ public void test6KVService() throws ConfigException, ContractException, JniExcep
395
427
}
396
428
397
429
@ Test
398
- public void test7BFSPrecompiled () throws ConfigException , ContractException , JniException {
430
+ public void test7BFSPrecompiled () throws ConfigException , ContractException {
399
431
400
432
ConfigOption configOption = Config .load (configFile );
401
433
Client client = Client .build (GROUP , configOption );
0 commit comments