Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests using dbms.listTransactions() #1244

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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