Search in sources :

Example 1 with DatabaseAvailabilityGuard

use of org.neo4j.kernel.availability.DatabaseAvailabilityGuard in project neo4j by neo4j.

the class KernelTransactionsTest method setUp.

@BeforeEach
void setUp() throws Exception {
    databaseAvailabilityGuard = new DatabaseAvailabilityGuard(DEFAULT_DATABASE_ID, clock, NullLog.getInstance(), 0, mock(CompositeDatabaseAvailabilityGuard.class));
    databaseAvailabilityGuard.init();
    t2.init("T2-" + getClass().getName());
}
Also used : CompositeDatabaseAvailabilityGuard(org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard) DatabaseAvailabilityGuard(org.neo4j.kernel.availability.DatabaseAvailabilityGuard) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with DatabaseAvailabilityGuard

use of org.neo4j.kernel.availability.DatabaseAvailabilityGuard 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)

Aggregations

CompositeDatabaseAvailabilityGuard (org.neo4j.kernel.availability.CompositeDatabaseAvailabilityGuard)2 DatabaseAvailabilityGuard (org.neo4j.kernel.availability.DatabaseAvailabilityGuard)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 BookmarkWithPrefix (org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix)1 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)1 FakeClock (org.neo4j.time.FakeClock)1