Skip to content

Commit 67637b4

Browse files
committed
Update tests using dbms.listTransactions()
Starting from 4.4 tests use `SHOW TRANSACTIONS`.
1 parent fa8b2a3 commit 67637b4

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

driver/src/test/java/org/neo4j/driver/integration/SessionBoltV3IT.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.List;
4343
import java.util.Map;
4444
import java.util.concurrent.CompletionStage;
45+
import org.junit.jupiter.api.BeforeEach;
4546
import org.junit.jupiter.api.Test;
4647
import org.junit.jupiter.api.extension.RegisterExtension;
4748
import org.neo4j.driver.Bookmark;
@@ -73,18 +74,27 @@ class SessionBoltV3IT {
7374
@RegisterExtension
7475
static final DriverExtension driver = new DriverExtension();
7576

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+
7686
@Test
7787
void shouldSetTransactionMetadata() {
7888
Map<String, Object> metadata = new HashMap<>();
7989
metadata.put("a", "hello world");
8090
metadata.put("b", LocalDate.now());
81-
metadata.put("c", asList(true, false, true));
91+
metadata.put("c", driver.isNeo4j43OrEarlier() ? asList(true, false, true) : false);
8292

8393
TransactionConfig config =
8494
TransactionConfig.builder().withMetadata(metadata).build();
8595

8696
// call listTransactions procedure that should list itself with the specified metadata
87-
Result result = driver.session().run("CALL dbms.listTransactions()", config);
97+
Result result = driver.session().run(showTxMetadata, config);
8898
Map<String, Object> receivedMetadata = result.single().get("metaData").asMap();
8999

90100
assertEquals(metadata, receivedMetadata);
@@ -101,7 +111,7 @@ void shouldSetTransactionMetadataAsync() {
101111

102112
// call listTransactions procedure that should list itself with the specified metadata
103113
CompletionStage<Map<String, Object>> metadataFuture = driver.asyncSession()
104-
.runAsync("CALL dbms.listTransactions()", config)
114+
.runAsync(showTxMetadata, config)
105115
.thenCompose(ResultCursor::singleAsync)
106116
.thenApply(record -> record.get("metaData").asMap());
107117

@@ -312,11 +322,9 @@ private static void testTransactionMetadataWithAsyncTransactionFunctions(boolean
312322
// call listTransactions procedure that should list itself with the specified metadata
313323
CompletionStage<Record> singleFuture = read
314324
? asyncSession.readTransactionAsync(
315-
tx -> tx.runAsync("CALL dbms.listTransactions()").thenCompose(ResultCursor::singleAsync),
316-
config)
325+
tx -> tx.runAsync(showTxMetadata).thenCompose(ResultCursor::singleAsync), config)
317326
: asyncSession.writeTransactionAsync(
318-
tx -> tx.runAsync("CALL dbms.listTransactions()").thenCompose(ResultCursor::singleAsync),
319-
config);
327+
tx -> tx.runAsync(showTxMetadata).thenCompose(ResultCursor::singleAsync), config);
320328

321329
CompletionStage<Map<String, Object>> metadataFuture =
322330
singleFuture.thenApply(record -> record.get("metaData").asMap());
@@ -336,10 +344,8 @@ private static void testTransactionMetadataWithTransactionFunctions(boolean read
336344

337345
// call listTransactions procedure that should list itself with the specified metadata
338346
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);
347+
? session.readTransaction(tx -> tx.run(showTxMetadata).single(), config)
348+
: session.writeTransaction(tx -> tx.run(showTxMetadata).single(), config);
343349

344350
Map<String, Object> receivedMetadata = single.get("metaData").asMap();
345351

driver/src/test/java/org/neo4j/driver/integration/TransactionBoltV3IT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.HashMap;
3434
import java.util.Map;
3535
import java.util.concurrent.CompletionStage;
36+
import org.junit.jupiter.api.BeforeEach;
3637
import org.junit.jupiter.api.Test;
3738
import org.junit.jupiter.api.extension.RegisterExtension;
3839
import org.neo4j.driver.Result;
@@ -55,6 +56,15 @@ class TransactionBoltV3IT {
5556
@RegisterExtension
5657
static final DriverExtension driver = new DriverExtension();
5758

59+
private static String showTxMetadata;
60+
61+
@BeforeEach
62+
void beforeAll() {
63+
showTxMetadata = driver.isNeo4j43OrEarlier()
64+
? "CALL dbms.listTransactions() YIELD metaData"
65+
: "SHOW TRANSACTIONS YIELD metaData";
66+
}
67+
5868
@Test
5969
void shouldSetTransactionMetadata() {
6070
Map<String, Object> metadata = new HashMap<>();
@@ -166,7 +176,7 @@ private static void verifyValidException(Exception error) {
166176

167177
private static void verifyTransactionMetadata(Map<String, Object> metadata) {
168178
try (Session session = driver.driver().session()) {
169-
Result result = session.run("CALL dbms.listTransactions()");
179+
Result result = session.run(showTxMetadata);
170180

171181
Map<String, Object> receivedMetadata = result.list().stream()
172182
.map(record -> record.get("metaData"))

0 commit comments

Comments
 (0)