Search in sources :

Example 6 with ClusterMemberAvailability

use of org.neo4j.cluster.member.ClusterMemberAvailability in project neo4j by neo4j.

the class HighAvailabilityModeSwitcherTest method shouldAllowForcedElectionsAfterModeSwitch.

@Test
public void shouldAllowForcedElectionsAfterModeSwitch() throws Throwable {
    // Given
    SwitchToSlaveCopyThenBranch switchToSlave = mock(SwitchToSlaveCopyThenBranch.class);
    when(switchToSlave.switchToSlave(any(LifeSupport.class), any(URI.class), any(URI.class), any(CancellationRequest.class))).thenReturn(URI.create("http://localhost"));
    ClusterMemberAvailability memberAvailability = mock(ClusterMemberAvailability.class);
    Election election = mock(Election.class);
    final CountDownLatch modeSwitchHappened = new CountDownLatch(1);
    HighAvailabilityModeSwitcher modeSwitcher = new HighAvailabilityModeSwitcher(switchToSlave, mock(SwitchToMaster.class), election, memberAvailability, mock(ClusterClient.class), storeSupplierMock(), mock(InstanceId.class), new ComponentSwitcherContainer(), neoStoreDataSourceSupplierMock(), NullLogService.getInstance()) {

        @Override
        ScheduledExecutorService createExecutor() {
            ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
            doAnswer(invocation -> {
                ((Runnable) invocation.getArguments()[0]).run();
                modeSwitchHappened.countDown();
                return mock(Future.class);
            }).when(executor).submit(any(Runnable.class));
            return executor;
        }
    };
    modeSwitcher.init();
    modeSwitcher.start();
    modeSwitcher.forceElections();
    reset(memberAvailability, election);
    // When
    modeSwitcher.masterIsAvailable(new HighAvailabilityMemberChangeEvent(PENDING, TO_SLAVE, mock(InstanceId.class), URI.create("http://localhost:9090?serverId=42")));
    modeSwitchHappened.await();
    modeSwitcher.forceElections();
    // Then
    InOrder inOrder = inOrder(memberAvailability, election);
    inOrder.verify(memberAvailability).memberIsUnavailable(HighAvailabilityModeSwitcher.SLAVE);
    inOrder.verify(election).performRoleElections();
    inOrder.verifyNoMoreInteractions();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InOrder(org.mockito.InOrder) InstanceId(org.neo4j.cluster.InstanceId) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) Election(org.neo4j.cluster.protocol.election.Election) ClusterClient(org.neo4j.cluster.client.ClusterClient) SwitchToSlaveCopyThenBranch(org.neo4j.kernel.ha.cluster.SwitchToSlaveCopyThenBranch) HighAvailabilityMemberChangeEvent(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SwitchToMaster(org.neo4j.kernel.ha.cluster.SwitchToMaster) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Example 7 with ClusterMemberAvailability

use of org.neo4j.cluster.member.ClusterMemberAvailability in project neo4j by neo4j.

the class HighAvailabilityModeSwitcherTest method shouldSwitchToSlaveForNullMasterAndBeSilentWhenMovingToDetached.

@Test
public void shouldSwitchToSlaveForNullMasterAndBeSilentWhenMovingToDetached() throws Throwable {
    // Given
    SwitchToSlaveCopyThenBranch sts = mock(SwitchToSlaveCopyThenBranch.class);
    SwitchToMaster stm = mock(SwitchToMaster.class);
    Election election = mock(Election.class);
    ClusterMemberAvailability cma = mock(ClusterMemberAvailability.class);
    InstanceId instanceId = new InstanceId(14);
    ComponentSwitcher componentSwitcher = mock(ComponentSwitcher.class);
    HighAvailabilityModeSwitcher theSwitcher = new HighAvailabilityModeSwitcher(sts, stm, election, cma, mock(ClusterClient.class), storeSupplierMock(), instanceId, componentSwitcher, neoStoreDataSourceSupplierMock(), NullLogService.getInstance());
    // When
    theSwitcher.init();
    theSwitcher.start();
    theSwitcher.instanceDetached(new HighAvailabilityMemberChangeEvent(HighAvailabilityMemberState.MASTER, HighAvailabilityMemberState.PENDING, null, null));
    // Then
    verify(componentSwitcher).switchToSlave();
    verifyZeroInteractions(cma);
}
Also used : ClusterClient(org.neo4j.cluster.client.ClusterClient) SwitchToSlaveCopyThenBranch(org.neo4j.kernel.ha.cluster.SwitchToSlaveCopyThenBranch) InstanceId(org.neo4j.cluster.InstanceId) HighAvailabilityMemberChangeEvent(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent) 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 8 with ClusterMemberAvailability

use of org.neo4j.cluster.member.ClusterMemberAvailability in project neo4j by neo4j.

the class HighAvailabilityModeSwitcherTest method shouldBroadcastMasterIsAvailableIfMasterAndReceiveMasterIsElected.

@Test
public void shouldBroadcastMasterIsAvailableIfMasterAndReceiveMasterIsElected() throws Exception {
    // Given
    ClusterMemberAvailability availability = mock(ClusterMemberAvailability.class);
    HighAvailabilityModeSwitcher toTest = createModeSwitcher(availability);
    // When
    toTest.masterIsElected(new HighAvailabilityMemberChangeEvent(HighAvailabilityMemberState.MASTER, HighAvailabilityMemberState.MASTER, new InstanceId(2), URI.create("ha://someone")));
    // Then
    /*
           * The second argument to memberIsAvailable below is null because it has not been set yet. This would require
           * a switch to master which we don't do here.
           */
    verify(availability).memberIsAvailable(HighAvailabilityModeSwitcher.MASTER, null, StoreId.DEFAULT);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HighAvailabilityMemberChangeEvent(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) Test(org.junit.Test)

Example 9 with ClusterMemberAvailability

use of org.neo4j.cluster.member.ClusterMemberAvailability 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 10 with ClusterMemberAvailability

use of org.neo4j.cluster.member.ClusterMemberAvailability in project neo4j by neo4j.

the class HighAvailabilityModeSwitcherTest method shouldBroadcastSlaveIsAvailableIfSlaveAndReceivesMasterIsAvailable.

@Test
public void shouldBroadcastSlaveIsAvailableIfSlaveAndReceivesMasterIsAvailable() throws Exception {
    // Given
    ClusterMemberAvailability availability = mock(ClusterMemberAvailability.class);
    HighAvailabilityModeSwitcher toTest = createModeSwitcher(availability);
    // When
    toTest.masterIsAvailable(new HighAvailabilityMemberChangeEvent(HighAvailabilityMemberState.SLAVE, HighAvailabilityMemberState.SLAVE, new InstanceId(2), URI.create("ha://someone")));
    // Then
    /*
           * The second argument to memberIsAvailable below is null because it has not been set yet. This would require
           * a switch to master which we don't do here.
           */
    verify(availability).memberIsAvailable(HighAvailabilityModeSwitcher.SLAVE, null, StoreId.DEFAULT);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) HighAvailabilityMemberChangeEvent(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) Test(org.junit.Test)

Aggregations

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