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();
}
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);
}
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);
}
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();
}
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);
}
Aggregations