Search in sources :

Example 1 with BookmarkWithPrefix

use of org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix in project neo4j by neo4j.

the class TransactionStateMachineV3SPITest method shouldNotCheckDatabaseIdInBookmark.

@Test
void shouldNotCheckDatabaseIdInBookmark() {
    // Given
    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));
    // When
    spi.beginTransaction(null, bookmarks, null, null, null, null);
    // Then
    verify(dbSpi).beginTransaction(any(), any(), any(), eq(bookmarks), any(), any(), any(), any());
}
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 2 with BookmarkWithPrefix

use of org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix in project neo4j by neo4j.

the class BoltV3TransportIT method shouldReturnUpdatedBookmarkAfterAutoCommitTransaction.

@ParameterizedTest(name = "{0}")
@MethodSource("argumentsProvider")
public void shouldReturnUpdatedBookmarkAfterAutoCommitTransaction(Class<? extends TransportConnection> connectionClass) throws Exception {
    init(connectionClass);
    negotiateBoltV3();
    // bookmark is expected to advance once the auto-commit transaction is committed
    long lastClosedTransactionId = getLastClosedTransactionId();
    String expectedBookmark = new BookmarkWithPrefix(lastClosedTransactionId + 1).toString();
    connection.send(util.chunk(new RunMessage("CREATE ()"), PullAllMessage.INSTANCE));
    assertThat(connection).satisfies(util.eventuallyReceives(msgSuccess(), msgSuccess(message -> assertThat(message).containsEntry("bookmark", expectedBookmark))));
}
Also used : BookmarkWithPrefix(org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with BookmarkWithPrefix

use of org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix 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 4 with BookmarkWithPrefix

use of org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix in project neo4j by neo4j.

the class DatabaseServiceBookmarkTest method throwsWhenTxAwaitDurationExpires.

@Test
void throwsWhenTxAwaitDurationExpires() {
    long lastClosedTransactionId = 100;
    TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
    var txAwaitDuration = Duration.ofSeconds(42);
    var clock = new FakeClock();
    var guard = new DatabaseAvailabilityGuard(DATABASE_ID, clock, NullLog.getInstance(), 0, mock(CompositeDatabaseAvailabilityGuard.class));
    var databaseAvailabilityGuard = spy(guard);
    when(databaseAvailabilityGuard.isAvailable()).then(invocation -> {
        // move clock forward on avery availability check
        // this check is executed on every tx id polling iteration
        clock.forward(1, SECONDS);
        return true;
    });
    var dbSpi = createDbSpi(txIdStore, txAwaitDuration, databaseAvailabilityGuard, clock);
    var resultFuture = executor.submit(() -> {
        begin(dbSpi, List.of(new BookmarkWithPrefix(lastClosedTransactionId + 42)));
        return null;
    });
    var e = assertThrows(ExecutionException.class, () -> resultFuture.get(20, SECONDS));
    assertThat(e.getCause()).isInstanceOf(TransactionIdTrackerException.class);
}
Also used : BookmarkWithPrefix(org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) CompositeDatabaseAvailabilityGuard(org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard) DatabaseAvailabilityGuard(org.neo4j.kernel.availability.DatabaseAvailabilityGuard) FakeClock(org.neo4j.time.FakeClock) CompositeDatabaseAvailabilityGuard(org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard) Test(org.junit.jupiter.api.Test)

Example 5 with BookmarkWithPrefix

use of org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix in project neo4j by neo4j.

the class DatabaseServiceBookmarkTest method doesNotWaitWhenTxIdUpToDate.

@Test
void doesNotWaitWhenTxIdUpToDate() throws Exception {
    long lastClosedTransactionId = 100;
    TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
    var dbSpi = createDbSpi(txIdStore, Duration.ofSeconds(1), Clocks.fakeClock());
    var resultFuture = executor.submit(() -> {
        begin(dbSpi, List.of(new BookmarkWithPrefix(lastClosedTransactionId - 42)));
        return null;
    });
    assertNull(resultFuture.get(20, SECONDS));
}
Also used : BookmarkWithPrefix(org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) Test(org.junit.jupiter.api.Test)

Aggregations

BookmarkWithPrefix (org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix)5 Test (org.junit.jupiter.api.Test)4 BoltChannel (org.neo4j.bolt.BoltChannel)2 Bookmark (org.neo4j.bolt.runtime.Bookmark)2 StatementProcessorReleaseManager (org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager)2 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)2 SystemNanoClock (org.neo4j.time.SystemNanoClock)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)1 CompositeDatabaseAvailabilityGuard (org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard)1 DatabaseAvailabilityGuard (org.neo4j.kernel.availability.DatabaseAvailabilityGuard)1 FakeClock (org.neo4j.time.FakeClock)1