From 8aed5069eaebe93c6828b589d013b0fd556353fc Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Thu, 9 Jun 2022 10:56:31 +0100 Subject: [PATCH] Update tests using dbms.listTransactions() Starting from 4.4 tests use `SHOW TRANSACTIONS`. --- .../driver/integration/SessionBoltV3IT.java | 32 ++++++++++--------- .../integration/TransactionBoltV3IT.java | 12 ++++++- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/driver/src/test/java/org/neo4j/driver/integration/SessionBoltV3IT.java b/driver/src/test/java/org/neo4j/driver/integration/SessionBoltV3IT.java index 6388da523d..c6d9388d49 100644 --- a/driver/src/test/java/org/neo4j/driver/integration/SessionBoltV3IT.java +++ b/driver/src/test/java/org/neo4j/driver/integration/SessionBoltV3IT.java @@ -42,6 +42,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletionStage; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.neo4j.driver.Bookmark; @@ -73,18 +74,26 @@ class SessionBoltV3IT { @RegisterExtension static final DriverExtension driver = new DriverExtension(); + private static String showTxMetadata; + + @BeforeEach + void beforeAll() { + showTxMetadata = driver.isNeo4j43OrEarlier() + ? "CALL dbms.listTransactions() YIELD metaData" + : "SHOW TRANSACTIONS YIELD metaData"; + } + @Test void shouldSetTransactionMetadata() { Map metadata = new HashMap<>(); metadata.put("a", "hello world"); metadata.put("b", LocalDate.now()); - metadata.put("c", asList(true, false, true)); + metadata.put("c", driver.isNeo4j43OrEarlier() ? asList(true, false, true) : false); TransactionConfig config = TransactionConfig.builder().withMetadata(metadata).build(); - // call listTransactions procedure that should list itself with the specified metadata - Result result = driver.session().run("CALL dbms.listTransactions()", config); + Result result = driver.session().run(showTxMetadata, config); Map receivedMetadata = result.single().get("metaData").asMap(); assertEquals(metadata, receivedMetadata); @@ -99,9 +108,8 @@ void shouldSetTransactionMetadataAsync() { TransactionConfig config = TransactionConfig.builder().withMetadata(metadata).build(); - // call listTransactions procedure that should list itself with the specified metadata CompletionStage> metadataFuture = driver.asyncSession() - .runAsync("CALL dbms.listTransactions()", config) + .runAsync(showTxMetadata, config) .thenCompose(ResultCursor::singleAsync) .thenApply(record -> record.get("metaData").asMap()); @@ -309,14 +317,11 @@ private static void testTransactionMetadataWithAsyncTransactionFunctions(boolean TransactionConfig config = TransactionConfig.builder().withMetadata(metadata).build(); - // call listTransactions procedure that should list itself with the specified metadata CompletionStage singleFuture = read ? asyncSession.readTransactionAsync( - tx -> tx.runAsync("CALL dbms.listTransactions()").thenCompose(ResultCursor::singleAsync), - config) + tx -> tx.runAsync(showTxMetadata).thenCompose(ResultCursor::singleAsync), config) : asyncSession.writeTransactionAsync( - tx -> tx.runAsync("CALL dbms.listTransactions()").thenCompose(ResultCursor::singleAsync), - config); + tx -> tx.runAsync(showTxMetadata).thenCompose(ResultCursor::singleAsync), config); CompletionStage> metadataFuture = singleFuture.thenApply(record -> record.get("metaData").asMap()); @@ -334,12 +339,9 @@ private static void testTransactionMetadataWithTransactionFunctions(boolean read TransactionConfig config = TransactionConfig.builder().withMetadata(metadata).build(); - // call listTransactions procedure that should list itself with the specified metadata Record single = read - ? session.readTransaction( - tx -> tx.run("CALL dbms.listTransactions()").single(), config) - : session.writeTransaction( - tx -> tx.run("CALL dbms.listTransactions()").single(), config); + ? session.readTransaction(tx -> tx.run(showTxMetadata).single(), config) + : session.writeTransaction(tx -> tx.run(showTxMetadata).single(), config); Map receivedMetadata = single.get("metaData").asMap(); diff --git a/driver/src/test/java/org/neo4j/driver/integration/TransactionBoltV3IT.java b/driver/src/test/java/org/neo4j/driver/integration/TransactionBoltV3IT.java index 7625de9d95..827dbd596d 100644 --- a/driver/src/test/java/org/neo4j/driver/integration/TransactionBoltV3IT.java +++ b/driver/src/test/java/org/neo4j/driver/integration/TransactionBoltV3IT.java @@ -33,6 +33,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletionStage; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.neo4j.driver.Result; @@ -55,6 +56,15 @@ class TransactionBoltV3IT { @RegisterExtension static final DriverExtension driver = new DriverExtension(); + private static String showTxMetadata; + + @BeforeEach + void beforeAll() { + showTxMetadata = driver.isNeo4j43OrEarlier() + ? "CALL dbms.listTransactions() YIELD metaData" + : "SHOW TRANSACTIONS YIELD metaData"; + } + @Test void shouldSetTransactionMetadata() { Map metadata = new HashMap<>(); @@ -166,7 +176,7 @@ private static void verifyValidException(Exception error) { private static void verifyTransactionMetadata(Map metadata) { try (Session session = driver.driver().session()) { - Result result = session.run("CALL dbms.listTransactions()"); + Result result = session.run(showTxMetadata); Map receivedMetadata = result.list().stream() .map(record -> record.get("metaData"))