Search in sources :

Example 6 with Bookmark

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());
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) SystemNanoClock(org.neo4j.time.SystemNanoClock) Bookmark(org.neo4j.bolt.runtime.Bookmark) BoltChannel(org.neo4j.bolt.BoltChannel) BookmarkWithDatabaseId(org.neo4j.bolt.v4.runtime.bookmarking.BookmarkWithDatabaseId) Test(org.junit.jupiter.api.Test)

Example 7 with Bookmark

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));
}
Also used : BookmarkWithPrefix(org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix) StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) SystemNanoClock(org.neo4j.time.SystemNanoClock) Bookmark(org.neo4j.bolt.runtime.Bookmark) BoltChannel(org.neo4j.bolt.BoltChannel) Test(org.junit.jupiter.api.Test)

Example 8 with Bookmark

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;
}
Also used : Bookmark(org.neo4j.bolt.runtime.Bookmark) ArrayList(java.util.ArrayList) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) BoltIOException(org.neo4j.bolt.messaging.BoltIOException)

Aggregations

Bookmark (org.neo4j.bolt.runtime.Bookmark)8 Test (org.junit.jupiter.api.Test)3 BoltChannel (org.neo4j.bolt.BoltChannel)3 StatementProcessorReleaseManager (org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager)3 SystemNanoClock (org.neo4j.time.SystemNanoClock)3 StatementProcessor (org.neo4j.bolt.runtime.statemachine.StatementProcessor)2 BookmarkWithPrefix (org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix)2 ArrayList (java.util.ArrayList)1 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)1 BookmarkWithDatabaseId (org.neo4j.bolt.v4.runtime.bookmarking.BookmarkWithDatabaseId)1 NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)1