use of org.neo4j.driver.SessionConfig in project neo4j by neo4j.
the class BoltStateHandlerTest method shouldKeepOneBookmarkPerDatabase.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void shouldKeepOneBookmarkPerDatabase() throws CommandException {
ConnectionConfig config = new ConnectionConfig("bolt", "", -1, "", "", Encryption.DEFAULT, "database1");
Bookmark db1Bookmark = InternalBookmark.parse("db1");
Bookmark db2Bookmark = InternalBookmark.parse("db2");
// A couple of these mock calls are now redundant with what is called in stubResultSummaryInAnOpenSession
Result resultMock = mock(Result.class);
Session db1SessionMock = mock(Session.class);
when(db1SessionMock.isOpen()).thenReturn(true);
when(db1SessionMock.lastBookmark()).thenReturn(db1Bookmark);
when(db1SessionMock.run("CALL db.ping()")).thenReturn(resultMock);
Session db2SessionMock = mock(Session.class);
when(db2SessionMock.isOpen()).thenReturn(true);
when(db2SessionMock.lastBookmark()).thenReturn(db2Bookmark);
when(db2SessionMock.run("CALL db.ping()")).thenReturn(resultMock);
Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, db1SessionMock, "Neo4j/9.4.1-ALPHA", "database1");
when(driverMock.session(any())).thenAnswer(arg -> {
SessionConfig sc = (SessionConfig) arg.getArguments()[0];
switch(sc.database().get()) {
case "database1":
return db1SessionMock;
case "database2":
return db2SessionMock;
default:
return null;
}
});
BoltStateHandler handler = new OfflineBoltStateHandler(driverMock);
// When
handler.connect(config);
// Then no bookmark yet for db1
verify(driverMock).session(SessionConfig.builder().withDefaultAccessMode(AccessMode.WRITE).withDatabase("database1").build());
// When
handler.setActiveDatabase("database2");
// Then no bookmark yet for db2
verify(driverMock).session(SessionConfig.builder().withDefaultAccessMode(AccessMode.WRITE).withDatabase("database2").build());
// When
handler.setActiveDatabase("database1");
// Then use bookmark for db1
verify(driverMock).session(SessionConfig.builder().withDefaultAccessMode(AccessMode.WRITE).withDatabase("database1").withBookmarks(db1Bookmark).build());
// When
handler.setActiveDatabase("database2");
// Then use bookmark for db2
verify(driverMock).session(SessionConfig.builder().withDefaultAccessMode(AccessMode.WRITE).withDatabase("database2").withBookmarks(db2Bookmark).build());
}
Aggregations