use of org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent in project neo4j by neo4j.
the class UpdatePullingTransactionObligationFulfillerTest method shouldUpdateTransactionIdStoreCorrectly.
@Test
public void shouldUpdateTransactionIdStoreCorrectly() throws Throwable {
// Given
TransactionIdStore store1 = mock(TransactionIdStore.class);
TransactionIdStore store2 = mock(TransactionIdStore.class);
@SuppressWarnings("unchecked") Supplier<TransactionIdStore> supplier = mock(Supplier.class);
when(supplier.get()).thenReturn(store1, store2);
doAnswer(invocation -> {
((HighAvailabilityMemberListener) invocation.getArguments()[0]).slaveIsAvailable(new HighAvailabilityMemberChangeEvent(null, null, serverId, null));
return null;
}).when(machine).addHighAvailabilityMemberListener(any(HighAvailabilityMemberListener.class));
doAnswer(invocation -> {
((HighAvailabilityMemberListener) invocation.getArguments()[0]).instanceStops(new HighAvailabilityMemberChangeEvent(null, null, serverId, null));
return null;
}).when(machine).removeHighAvailabilityMemberListener(any(HighAvailabilityMemberListener.class));
UpdatePullingTransactionObligationFulfiller fulfiller = new UpdatePullingTransactionObligationFulfiller(updatePuller, machine, serverId, supplier);
// When
fulfiller.start();
fulfiller.fulfill(1);
fulfiller.stop();
fulfiller.fulfill(2);
fulfiller.start();
fulfiller.fulfill(3);
fulfiller.stop();
fulfiller.fulfill(4);
// Then
verify(store1, times(1)).getLastClosedTransactionId();
verify(store2, times(1)).getLastClosedTransactionId();
}
use of org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent 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.kernel.ha.cluster.HighAvailabilityMemberChangeEvent 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.kernel.ha.cluster.HighAvailabilityMemberChangeEvent 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.kernel.ha.cluster.HighAvailabilityMemberChangeEvent 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