Search in sources :

Example 16 with AvailabilityGuard

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

the class LocalDatabaseTest method availabilityGuardRaisedBeforeDataSourceManagerIsStoppedForStoreCopy.

@Test
public void availabilityGuardRaisedBeforeDataSourceManagerIsStoppedForStoreCopy() throws Throwable {
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    DataSourceManager dataSourceManager = mock(DataSourceManager.class);
    LocalDatabase localDatabase = newLocalDatabase(guard, dataSourceManager);
    localDatabase.stopForStoreCopy();
    InOrder inOrder = inOrder(guard, dataSourceManager);
    // guard should be raised twice - once during construction and once during stop
    inOrder.verify(guard, times(2)).require(any());
    inOrder.verify(dataSourceManager).stop();
}
Also used : InOrder(org.mockito.InOrder) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) Test(org.junit.Test)

Example 17 with AvailabilityGuard

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

the class LocalDatabaseTest method availabilityGuardRaisedBeforeDataSourceManagerIsStopped.

@Test
public void availabilityGuardRaisedBeforeDataSourceManagerIsStopped() throws Throwable {
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    DataSourceManager dataSourceManager = mock(DataSourceManager.class);
    LocalDatabase localDatabase = newLocalDatabase(guard, dataSourceManager);
    localDatabase.stop();
    InOrder inOrder = inOrder(guard, dataSourceManager);
    // guard should be raised twice - once during construction and once during stop
    inOrder.verify(guard, times(2)).require(any());
    inOrder.verify(dataSourceManager).stop();
}
Also used : InOrder(org.mockito.InOrder) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) Test(org.junit.Test)

Example 18 with AvailabilityGuard

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

the class HighAvailabilityMemberStateMachineTest method whenInSlaveStateWith3MemberClusterLosingMasterShouldPutInPending.

@Test
public void whenInSlaveStateWith3MemberClusterLosingMasterShouldPutInPending() throws Throwable {
    // Given
    InstanceId me = new InstanceId(1);
    InstanceId master = new InstanceId(2);
    InstanceId otherSlave = new InstanceId(3);
    HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
    AvailabilityGuard guard = mock(AvailabilityGuard.class);
    ObservedClusterMembers members = mockClusterMembers(me, singletonList(otherSlave), singletonList(master));
    ClusterMemberEvents events = mock(ClusterMemberEvents.class);
    ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
    HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
    stateMachine.init();
    ClusterMemberListener memberListener = memberListenerContainer.get();
    HAStateChangeListener probe = new HAStateChangeListener();
    stateMachine.addHighAvailabilityMemberListener(probe);
    // Send it to MASTER
    memberListener.coordinatorIsElected(master);
    memberListener.memberIsAvailable(MASTER, master, URI.create("ha://whatever"), StoreId.DEFAULT);
    memberListener.memberIsAvailable(SLAVE, me, URI.create("ha://whatever3"), StoreId.DEFAULT);
    memberListener.memberIsAvailable(SLAVE, otherSlave, URI.create("ha://whatever2"), StoreId.DEFAULT);
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.SLAVE));
    // When
    memberListener.memberIsFailed(master);
    // Then
    assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
    assertThat(probe.instanceStops, is(false));
    assertThat(probe.instanceDetached, is(true));
    verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) ClusterMemberEvents(org.neo4j.cluster.member.ClusterMemberEvents) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberListener(org.neo4j.cluster.member.ClusterMemberListener) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AvailabilityRequirement(org.neo4j.kernel.AvailabilityGuard.AvailabilityRequirement) Test(org.junit.Test)

Example 19 with AvailabilityGuard

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

the class ReadReplicaReplicationIT method transactionIdTracker.

private TransactionIdTracker transactionIdTracker(GraphDatabaseAPI database) {
    TransactionIdStore transactionIdStore = database.getDependencyResolver().resolveDependency(TransactionIdStore.class);
    AvailabilityGuard availabilityGuard = database.getDependencyResolver().resolveDependency(AvailabilityGuard.class);
    return new TransactionIdTracker(transactionIdStore, availabilityGuard, Clock.systemUTC());
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) TransactionIdTracker(org.neo4j.kernel.api.txtracking.TransactionIdTracker)

Example 20 with AvailabilityGuard

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

the class SlaveLockManagerTest method setUp.

@Before
public void setUp() {
    requestContextFactory = new RequestContextFactory(1, singleton(mock(TransactionIdStore.class)));
    master = mock(Master.class);
    availabilityGuard = new AvailabilityGuard(Clocks.systemClock(), getInstance());
}
Also used : Master(org.neo4j.kernel.ha.com.master.Master) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) RequestContextFactory(org.neo4j.kernel.ha.com.RequestContextFactory) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Before(org.junit.Before)

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