Search in sources :

Example 11 with AvailabilityGuard

use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.

the class LocalDatabaseTest method availabilityGuardRaisedOnStopForStoreCopy.

@Test
public void availabilityGuardRaisedOnStopForStoreCopy() throws Throwable {
    AvailabilityGuard guard = newAvailabilityGuard();
    assertTrue(guard.isAvailable());
    LocalDatabase localDatabase = newLocalDatabase(guard);
    assertFalse(guard.isAvailable());
    localDatabase.start();
    assertTrue(guard.isAvailable());
    localDatabase.stopForStoreCopy();
    assertDatabaseIsStoppedForStoreCopyAndUnavailable(guard);
}
Also used : AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Example 12 with AvailabilityGuard

use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.

the class TransactionStateMachineSPITest method throwsWhenTxAwaitDurationExpires.

@Test
public void throwsWhenTxAwaitDurationExpires() throws Exception {
    long lastClosedTransactionId = 100;
    TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
    Duration txAwaitDuration = Duration.ofSeconds(42);
    FakeClock clock = new FakeClock();
    AvailabilityGuard availabilityGuard = spy(new AvailabilityGuard(clock, NullLog.getInstance()));
    when(availabilityGuard.isAvailable()).then(invocation -> {
        boolean available = (boolean) invocation.callRealMethod();
        clock.forward(txAwaitDuration.getSeconds() + 1, SECONDS);
        return available;
    });
    TransactionStateMachineSPI txSpi = createTxSpi(txIdStore, txAwaitDuration, availabilityGuard, clock);
    Future<Void> result = otherThread.execute(state -> {
        txSpi.awaitUpToDate(lastClosedTransactionId + 42);
        return null;
    });
    try {
        result.get(20, SECONDS);
    } catch (Exception e) {
        assertThat(e, instanceOf(ExecutionException.class));
        assertThat(e.getCause(), instanceOf(TransactionFailureException.class));
    }
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) FakeClock(org.neo4j.time.FakeClock) Duration(java.time.Duration) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) ExecutionException(java.util.concurrent.ExecutionException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) Test(org.junit.Test)

Example 13 with AvailabilityGuard

use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.

the class LocalDatabaseTest method availabilityGuardRaisedOnCreation.

@Test
public void availabilityGuardRaisedOnCreation() throws Throwable {
    AvailabilityGuard guard = newAvailabilityGuard();
    assertTrue(guard.isAvailable());
    LocalDatabase localDatabase = newLocalDatabase(guard);
    assertNotNull(localDatabase);
    assertDatabaseIsStoppedAndUnavailable(guard);
}
Also used : AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Example 14 with AvailabilityGuard

use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.

the class LocalDatabaseTest method availabilityGuardDroppedOnStart.

@Test
public void availabilityGuardDroppedOnStart() throws Throwable {
    AvailabilityGuard guard = newAvailabilityGuard();
    assertTrue(guard.isAvailable());
    LocalDatabase localDatabase = newLocalDatabase(guard);
    assertFalse(guard.isAvailable());
    localDatabase.start();
    assertTrue(guard.isAvailable());
}
Also used : AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Example 15 with AvailabilityGuard

use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.

the class LocalDatabaseTest method availabilityGuardRaisedOnStop.

@Test
public void availabilityGuardRaisedOnStop() throws Throwable {
    AvailabilityGuard guard = newAvailabilityGuard();
    assertTrue(guard.isAvailable());
    LocalDatabase localDatabase = newLocalDatabase(guard);
    assertFalse(guard.isAvailable());
    localDatabase.start();
    assertTrue(guard.isAvailable());
    localDatabase.stop();
    assertDatabaseIsStoppedAndUnavailable(guard);
}
Also used : AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Test(org.junit.Test)

Aggregations

AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)21 Test (org.junit.Test)15 InstanceId (org.neo4j.cluster.InstanceId)8 ObservedClusterMembers (org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers)8 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)7 ClusterMemberListener (org.neo4j.cluster.member.ClusterMemberListener)7 AvailabilityRequirement (org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement)5 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)5 Master (org.neo4j.kernel.ha.com.master.Master)4 Before (org.junit.Before)3 InOrder (org.mockito.InOrder)2 DependencyResolver (org.neo4j.graphdb.DependencyResolver)2 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)2 RequestContextFactory (org.neo4j.kernel.ha.com.RequestContextFactory)2 DataSourceManager (org.neo4j.kernel.impl.transaction.state.DataSourceManager)2 Monitors (org.neo4j.kernel.monitoring.Monitors)2 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Duration (java.time.Duration)1