use of org.neo4j.bolt.runtime.Bookmark in project neo4j by neo4j.
the class TransactionStateMachineV4SPITest method shouldCheckDatabaseIdInBookmark.
@Test
void shouldCheckDatabaseIdInBookmark() {
// Given
var dbSpi = mock(BoltGraphDatabaseServiceSPI.class);
var databaseId = databaseIdRepository.getRaw("molly");
when(dbSpi.getNamedDatabaseId()).thenReturn(databaseId);
var spi = new TransactionStateMachineV4SPI(dbSpi, mock(BoltChannel.class), mock(SystemNanoClock.class), mock(StatementProcessorReleaseManager.class));
var bookmarks = List.<Bookmark>of(new BookmarkWithDatabaseId(42, databaseId));
// When
spi.beginTransaction(null, bookmarks, null, null, null, null);
// Then
verify(dbSpi).beginTransaction(any(), any(), any(), eq(bookmarks), any(), any(), any(), any());
}
use of org.neo4j.bolt.runtime.Bookmark in project neo4j by neo4j.
the class TransactionStateMachineV3SPITest method shouldFailWhenGivenMultipleBookmarks.
@Test
void shouldFailWhenGivenMultipleBookmarks() {
var dbSpi = mock(BoltGraphDatabaseServiceSPI.class);
var spi = new TestAbstractTransactionStateMachineSPI(dbSpi, mock(BoltChannel.class), mock(SystemNanoClock.class), mock(StatementProcessorReleaseManager.class));
var bookmarks = List.<Bookmark>of(new BookmarkWithPrefix(42L), new BookmarkWithPrefix(4242L));
assertThrows(IllegalArgumentException.class, () -> spi.beginTransaction(null, bookmarks, null, null, null, null));
}
use of org.neo4j.bolt.runtime.Bookmark in project neo4j by neo4j.
the class BookmarksParserV4 method parseBookmarks.
private List<Bookmark> parseBookmarks(ListValue bookmarks) throws BookmarkParsingException {
var maxSystemDbTxId = ABSENT_BOOKMARK_ID;
NamedDatabaseId userDbId = null;
var maxUserDbTxId = ABSENT_BOOKMARK_ID;
List<String> customBookmarkStrings = new ArrayList<>();
for (var bookmark : bookmarks) {
if (bookmark != Values.NO_VALUE) {
var bookmarkString = toBookmarkString(bookmark);
if (customBookmarkFormatParser.isCustomBookmark(bookmarkString)) {
customBookmarkStrings.add(bookmarkString);
} else {
var parsedBookmark = parse(bookmarkString);
if (NAMED_SYSTEM_DATABASE_ID.equals(parsedBookmark.namedDatabaseId)) {
maxSystemDbTxId = Math.max(maxSystemDbTxId, parsedBookmark.txId);
} else {
if (userDbId == null) {
userDbId = parsedBookmark.namedDatabaseId;
} else {
assertSameDatabaseId(userDbId, parsedBookmark.namedDatabaseId, bookmarks);
}
maxUserDbTxId = Math.max(maxUserDbTxId, parsedBookmark.txId);
}
}
}
}
if (customBookmarkStrings.isEmpty()) {
return buildBookmarks(NAMED_SYSTEM_DATABASE_ID, maxSystemDbTxId, userDbId, maxUserDbTxId);
}
List<Bookmark> customBookmarks;
try {
customBookmarks = customBookmarkFormatParser.parse(customBookmarkStrings);
} catch (Exception e) {
throw BookmarkParsingException.newInvalidBookmarkError("Parsing of supplied bookmarks failed with message: " + e.getMessage(), e);
}
if (maxSystemDbTxId != ABSENT_BOOKMARK_ID) {
customBookmarks.add(new BookmarkWithDatabaseId(maxSystemDbTxId, NAMED_SYSTEM_DATABASE_ID));
}
if (maxUserDbTxId != ABSENT_BOOKMARK_ID) {
customBookmarks.add(new BookmarkWithDatabaseId(maxUserDbTxId, userDbId));
}
return customBookmarks;
}
Aggregations