Search in sources :

Example 6 with Election

use of org.neo4j.cluster.protocol.election.Election in project neo4j by neo4j.

the class HighAvailabilityModeSwitcherTest method shouldPerformForcedElections.

@Test
public void shouldPerformForcedElections() {
    // Given
    ClusterMemberAvailability memberAvailability = mock(ClusterMemberAvailability.class);
    Election election = mock(Election.class);
    HighAvailabilityModeSwitcher modeSwitcher = new HighAvailabilityModeSwitcher(mock(SwitchToSlaveCopyThenBranch.class), mock(SwitchToMaster.class), election, memberAvailability, mock(ClusterClient.class), storeSupplierMock(), mock(InstanceId.class), new ComponentSwitcherContainer(), neoStoreDataSourceSupplierMock(), NullLogService.getInstance());
    // When
    modeSwitcher.forceElections();
    // Then
    InOrder inOrder = inOrder(memberAvailability, election);
    inOrder.verify(memberAvailability).memberIsUnavailable(HighAvailabilityModeSwitcher.SLAVE);
    inOrder.verify(election).performRoleElections();
    inOrder.verifyNoMoreInteractions();
}
Also used : ClusterClient(org.neo4j.cluster.client.ClusterClient) SwitchToSlaveCopyThenBranch(org.neo4j.kernel.ha.cluster.SwitchToSlaveCopyThenBranch) InOrder(org.mockito.InOrder) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) SwitchToMaster(org.neo4j.kernel.ha.cluster.SwitchToMaster) Election(org.neo4j.cluster.protocol.election.Election) Test(org.junit.Test)

Example 7 with Election

use of org.neo4j.cluster.protocol.election.Election in project neo4j by neo4j.

the class HighAvailabilityModeSwitcherTest method shouldPerformForcedElectionsOnlyOnce.

@Test
public void shouldPerformForcedElectionsOnlyOnce() {
    // Given: HAMS
    ClusterMemberAvailability memberAvailability = mock(ClusterMemberAvailability.class);
    Election election = mock(Election.class);
    HighAvailabilityModeSwitcher modeSwitcher = new HighAvailabilityModeSwitcher(mock(SwitchToSlaveCopyThenBranch.class), mock(SwitchToMaster.class), election, memberAvailability, mock(ClusterClient.class), storeSupplierMock(), mock(InstanceId.class), new ComponentSwitcherContainer(), neoStoreDataSourceSupplierMock(), NullLogService.getInstance());
    // When: reelections are forced multiple times
    modeSwitcher.forceElections();
    modeSwitcher.forceElections();
    modeSwitcher.forceElections();
    // Then: instance sens out memberIsUnavailable and asks for elections and does this only once
    InOrder inOrder = inOrder(memberAvailability, election);
    inOrder.verify(memberAvailability).memberIsUnavailable(HighAvailabilityModeSwitcher.SLAVE);
    inOrder.verify(election).performRoleElections();
    inOrder.verifyNoMoreInteractions();
}
Also used : ClusterClient(org.neo4j.cluster.client.ClusterClient) SwitchToSlaveCopyThenBranch(org.neo4j.kernel.ha.cluster.SwitchToSlaveCopyThenBranch) InOrder(org.mockito.InOrder) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) SwitchToMaster(org.neo4j.kernel.ha.cluster.SwitchToMaster) Election(org.neo4j.cluster.protocol.election.Election) Test(org.junit.Test)

Aggregations

Election (org.neo4j.cluster.protocol.election.Election)7 Test (org.junit.Test)6 InstanceId (org.neo4j.cluster.InstanceId)6 ClusterClient (org.neo4j.cluster.client.ClusterClient)6 ClusterMemberAvailability (org.neo4j.cluster.member.ClusterMemberAvailability)6 SwitchToMaster (org.neo4j.kernel.ha.cluster.SwitchToMaster)5 SwitchToSlaveCopyThenBranch (org.neo4j.kernel.ha.cluster.SwitchToSlaveCopyThenBranch)5 InOrder (org.mockito.InOrder)3 HighAvailabilityMemberChangeEvent (org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent)3 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)3 URI (java.net.URI)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Before (org.junit.Before)1 ClusterMemberEvents (org.neo4j.cluster.member.ClusterMemberEvents)1