42
42
import java .util .List ;
43
43
import java .util .Map ;
44
44
import java .util .concurrent .CompletionStage ;
45
+ import org .junit .jupiter .api .BeforeEach ;
45
46
import org .junit .jupiter .api .Test ;
46
47
import org .junit .jupiter .api .extension .RegisterExtension ;
47
48
import org .neo4j .driver .Bookmark ;
@@ -73,18 +74,26 @@ class SessionBoltV3IT {
73
74
@ RegisterExtension
74
75
static final DriverExtension driver = new DriverExtension ();
75
76
77
+ private static String showTxMetadata ;
78
+
79
+ @ BeforeEach
80
+ void beforeAll () {
81
+ showTxMetadata = driver .isNeo4j43OrEarlier ()
82
+ ? "CALL dbms.listTransactions() YIELD metaData"
83
+ : "SHOW TRANSACTIONS YIELD metaData" ;
84
+ }
85
+
76
86
@ Test
77
87
void shouldSetTransactionMetadata () {
78
88
Map <String , Object > metadata = new HashMap <>();
79
89
metadata .put ("a" , "hello world" );
80
90
metadata .put ("b" , LocalDate .now ());
81
- metadata .put ("c" , asList (true , false , true ));
91
+ metadata .put ("c" , driver . isNeo4j43OrEarlier () ? asList (true , false , true ) : false );
82
92
83
93
TransactionConfig config =
84
94
TransactionConfig .builder ().withMetadata (metadata ).build ();
85
95
86
- // call listTransactions procedure that should list itself with the specified metadata
87
- Result result = driver .session ().run ("CALL dbms.listTransactions()" , config );
96
+ Result result = driver .session ().run (showTxMetadata , config );
88
97
Map <String , Object > receivedMetadata = result .single ().get ("metaData" ).asMap ();
89
98
90
99
assertEquals (metadata , receivedMetadata );
@@ -99,9 +108,8 @@ void shouldSetTransactionMetadataAsync() {
99
108
TransactionConfig config =
100
109
TransactionConfig .builder ().withMetadata (metadata ).build ();
101
110
102
- // call listTransactions procedure that should list itself with the specified metadata
103
111
CompletionStage <Map <String , Object >> metadataFuture = driver .asyncSession ()
104
- .runAsync ("CALL dbms.listTransactions()" , config )
112
+ .runAsync (showTxMetadata , config )
105
113
.thenCompose (ResultCursor ::singleAsync )
106
114
.thenApply (record -> record .get ("metaData" ).asMap ());
107
115
@@ -309,14 +317,11 @@ private static void testTransactionMetadataWithAsyncTransactionFunctions(boolean
309
317
TransactionConfig config =
310
318
TransactionConfig .builder ().withMetadata (metadata ).build ();
311
319
312
- // call listTransactions procedure that should list itself with the specified metadata
313
320
CompletionStage <Record > singleFuture = read
314
321
? asyncSession .readTransactionAsync (
315
- tx -> tx .runAsync ("CALL dbms.listTransactions()" ).thenCompose (ResultCursor ::singleAsync ),
316
- config )
322
+ tx -> tx .runAsync (showTxMetadata ).thenCompose (ResultCursor ::singleAsync ), config )
317
323
: asyncSession .writeTransactionAsync (
318
- tx -> tx .runAsync ("CALL dbms.listTransactions()" ).thenCompose (ResultCursor ::singleAsync ),
319
- config );
324
+ tx -> tx .runAsync (showTxMetadata ).thenCompose (ResultCursor ::singleAsync ), config );
320
325
321
326
CompletionStage <Map <String , Object >> metadataFuture =
322
327
singleFuture .thenApply (record -> record .get ("metaData" ).asMap ());
@@ -334,12 +339,9 @@ private static void testTransactionMetadataWithTransactionFunctions(boolean read
334
339
TransactionConfig config =
335
340
TransactionConfig .builder ().withMetadata (metadata ).build ();
336
341
337
- // call listTransactions procedure that should list itself with the specified metadata
338
342
Record single = read
339
- ? session .readTransaction (
340
- tx -> tx .run ("CALL dbms.listTransactions()" ).single (), config )
341
- : session .writeTransaction (
342
- tx -> tx .run ("CALL dbms.listTransactions()" ).single (), config );
343
+ ? session .readTransaction (tx -> tx .run (showTxMetadata ).single (), config )
344
+ : session .writeTransaction (tx -> tx .run (showTxMetadata ).single (), config );
343
345
344
346
Map <String , Object > receivedMetadata = single .get ("metaData" ).asMap ();
345
347
0 commit comments