Skip to content

Commit

Permalink
Adapt to breaking changes to SHOW DATABASES
Browse files Browse the repository at this point in the history
SHOW DATABASES has a couple of breaking changes in 5.x

* role is now simply 'primary' or 'secondary'
* writer is used to determine the leader
* error is now statusMessage
  • Loading branch information
mnd999 committed Aug 18, 2022
1 parent a267bb1 commit 46a1599
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions common/src/main/java/apoc/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,9 @@ public static boolean isWriteableInstance( GraphDatabaseAPI db )
{
var socketAddress = db.getDependencyResolver().resolveDependency( Config.class ).get( BoltConnector.advertised_address ).toString();
GraphDatabaseService systemDb = db.getDependencyResolver().resolveDependency( DatabaseManagementService.class ).database( SYSTEM_DATABASE_NAME );
String role = systemDb.executeTransactionally( "SHOW DATABASE $databaseName WHERE address = $socketAddress",
Map.of( "databaseName", db.databaseName(), "socketAddress", socketAddress ), result -> Iterators.single( result.columnAs( "role" ) ) );
return role.equalsIgnoreCase( "LEADER" ) || role.equalsIgnoreCase( "standalone" );
Boolean writer = systemDb.executeTransactionally( "SHOW DATABASE $databaseName WHERE address = $socketAddress",
Map.of( "databaseName", db.databaseName(), "socketAddress", socketAddress ), result -> Iterators.single( result.columnAs( "writer" ) ) );
return writer;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions extended/src/test/java/apoc/systemdb/SystemDbTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.neo4j.test.rule.ImpermanentDbmsRule;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -84,12 +83,12 @@ public void testGetGraph() throws Exception {

@Test
public void testExecute() {
TestUtil.testResult(db, "CALL apoc.systemdb.execute('SHOW DATABASES YIELD name, default, currentStatus, role, requestedStatus, error, address, aliases, access, home') YIELD row RETURN row", result -> {
TestUtil.testResult(db, "CALL apoc.systemdb.execute('SHOW DATABASES YIELD name, default, currentStatus, home') YIELD row RETURN row", result -> {
List<Map<String, Object>> rows = Iterators.asList(result.columnAs("row"));
// removed key "systemDefault"
org.hamcrest.MatcherAssert.assertThat(rows, Matchers.containsInAnyOrder(
MapUtil.map( "name", "system", "default", false, "currentStatus", "online", "role", "standalone", "requestedStatus", "online", "error", "", "address", "localhost:7687", "aliases", Collections.EMPTY_LIST, "access", "read-write", "home", false),
MapUtil.map("name", "neo4j", "default", true, "currentStatus", "online", "role", "standalone", "requestedStatus", "online", "error", "", "address", "localhost:7687", "aliases", Collections.EMPTY_LIST, "access", "read-write", "home", true)
MapUtil.map( "name", "system", "default", false, "currentStatus", "online", "home", false),
MapUtil.map("name", "neo4j", "default", true, "currentStatus", "online", "home", true)
));
});
}
Expand Down

0 comments on commit 46a1599

Please sign in to comment.