Skip to content

Commit

Permalink
Update tests using dbms.listTransactions() (#1244)
Browse files Browse the repository at this point in the history
Starting from 4.4 tests use `SHOW TRANSACTIONS`.
  • Loading branch information
injectives authored Jun 9, 2022
1 parent fa8b2a3 commit 7818086
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Object> 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<String, Object> receivedMetadata = result.single().get("metaData").asMap();

assertEquals(metadata, receivedMetadata);
Expand All @@ -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<Map<String, Object>> metadataFuture = driver.asyncSession()
.runAsync("CALL dbms.listTransactions()", config)
.runAsync(showTxMetadata, config)
.thenCompose(ResultCursor::singleAsync)
.thenApply(record -> record.get("metaData").asMap());

Expand Down Expand Up @@ -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<Record> 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<Map<String, Object>> metadataFuture =
singleFuture.thenApply(record -> record.get("metaData").asMap());
Expand All @@ -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<String, Object> receivedMetadata = single.get("metaData").asMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Object> metadata = new HashMap<>();
Expand Down Expand Up @@ -166,7 +176,7 @@ private static void verifyValidException(Exception error) {

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

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

0 comments on commit 7818086

Please sign in to comment.