use of org.neo4j.com.ComException in project neo4j by neo4j.
the class HighAvailabilityModeSwitcherTest method shouldRecognizeNewMasterIfNewMasterBecameAvailableDuringSwitch.
@Test
public void shouldRecognizeNewMasterIfNewMasterBecameAvailableDuringSwitch() throws Throwable {
// When messages coming in the following ordering, the slave should detect that the master id has changed
// M1: Get masterIsAvailable for instance 1 at PENDING state, changing PENDING -> TO_SLAVE
// M2: Get masterIsAvailable for instance 2 at TO_SLAVE state, changing TO_SLAVE -> TO_SLAVE
// Given
final CountDownLatch firstMasterAvailableHandled = new CountDownLatch(1);
final CountDownLatch secondMasterAvailableComes = new CountDownLatch(1);
final CountDownLatch secondMasterAvailableHandled = new CountDownLatch(1);
SwitchToSlaveCopyThenBranch switchToSlave = mock(SwitchToSlaveCopyThenBranch.class);
HighAvailabilityModeSwitcher modeSwitcher = new HighAvailabilityModeSwitcher(switchToSlave, mock(SwitchToMaster.class), mock(Election.class), mock(ClusterMemberAvailability.class), mock(ClusterClient.class), mock(Supplier.class), new InstanceId(4), new ComponentSwitcherContainer(), neoStoreDataSourceSupplierMock(), NullLogService.getInstance()) {
@Override
ScheduledExecutorService createExecutor() {
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
final ExecutorService realExecutor = Executors.newSingleThreadExecutor();
when(executor.submit(any(Runnable.class))).thenAnswer((Answer<Future<?>>) invocation -> realExecutor.submit((Runnable) () -> ((Runnable) invocation.getArguments()[0]).run()));
when(executor.schedule(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenAnswer((Answer<Future<?>>) invocation -> {
realExecutor.submit((Callable<Void>) () -> {
firstMasterAvailableHandled.countDown();
secondMasterAvailableComes.await();
((Runnable) invocation.getArguments()[0]).run();
secondMasterAvailableHandled.countDown();
return null;
});
return mock(ScheduledFuture.class);
});
return executor;
}
};
modeSwitcher.init();
modeSwitcher.start();
modeSwitcher.listeningAt(URI.create("ha://server3?serverId=3"));
// When
// masterIsAvailable for instance 1
URI uri1 = URI.create("ha://server1");
// The first masterIsAvailable should fail so that the slave instance stops at TO_SLAVE state
doThrow(new ComException("Fail to switch to slave and reschedule to retry")).when(switchToSlave).switchToSlave(any(LifeSupport.class), any(URI.class), eq(uri1), any(CancellationRequest.class));
modeSwitcher.masterIsAvailable(new HighAvailabilityMemberChangeEvent(PENDING, TO_SLAVE, new InstanceId(1), uri1));
// wait until the first masterIsAvailable triggers the exception handling
firstMasterAvailableHandled.await();
verify(switchToSlave).switchToSlave(any(LifeSupport.class), any(URI.class), eq(uri1), any(CancellationRequest.class));
// masterIsAvailable for instance 2
URI uri2 = URI.create("ha://server2");
modeSwitcher.masterIsAvailable(new HighAvailabilityMemberChangeEvent(TO_SLAVE, TO_SLAVE, new InstanceId(2), uri2));
secondMasterAvailableComes.countDown();
// wait until switchToSlave method is invoked again
secondMasterAvailableHandled.await();
// Then
// switchToSlave should be retried with new master id
verify(switchToSlave).switchToSlave(any(LifeSupport.class), any(URI.class), eq(uri2), any(CancellationRequest.class));
}
use of org.neo4j.com.ComException in project neo4j by neo4j.
the class SlaveLocksClientTest method acquireExclusiveMustThrowIfMasterThrows.
@Test(expected = DistributedLockFailureException.class)
public void acquireExclusiveMustThrowIfMasterThrows() throws Exception {
whenMasterAcquireExclusive().thenThrow(new ComException());
client.acquireExclusive(LockTracer.NONE, NODE, 1);
}
use of org.neo4j.com.ComException in project neo4j by neo4j.
the class SlaveLocksClientTest method closeMustThrowIfMasterThrows.
@Test(expected = DistributedLockFailureException.class)
public void closeMustThrowIfMasterThrows() throws Exception {
when(master.endLockSession(any(RequestContext.class), anyBoolean())).thenThrow(new ComException());
// initialise
client.acquireExclusive(LockTracer.NONE, NODE, 1);
client.close();
}
use of org.neo4j.com.ComException in project neo4j by neo4j.
the class SlaveLocksClientTest method stopDoesNotThrowWhenMasterCommunicationThrowsComException.
@Test
public void stopDoesNotThrowWhenMasterCommunicationThrowsComException() {
ComException error = new ComException("Communication failure");
when(master.endLockSession(any(RequestContext.class), anyBoolean())).thenThrow(error);
client.stop();
logProvider.assertExactly(inLog(SlaveLocksClient.class).warn(equalTo("Unable to stop lock session on master"), CoreMatchers.<Throwable>instanceOf(DistributedLockFailureException.class)));
}
use of org.neo4j.com.ComException in project neo4j by neo4j.
the class BackupTool method executeBackup.
BackupOutcome executeBackup(HostnamePort hostnamePort, File to, ConsistencyCheck consistencyCheck, Config config, long timeout, boolean forensics) throws ToolFailureException {
try {
systemOut.println("Performing backup from '" + hostnamePort + "'");
String host = hostnamePort.getHost();
int port = hostnamePort.getPort();
BackupOutcome outcome = backupService.doIncrementalBackupOrFallbackToFull(host, port, to, consistencyCheck, config, timeout, forensics);
systemOut.println("Done");
return outcome;
} catch (UnexpectedStoreVersionException e) {
throw new ToolFailureException(e.getMessage(), e);
} catch (MismatchingStoreIdException e) {
throw new ToolFailureException(String.format(MISMATCHED_STORE_ID, e.getExpected(), e.getEncountered()));
} catch (ComException e) {
throw new ToolFailureException("Couldn't connect to '" + hostnamePort + "'", e);
} catch (IncrementalBackupNotPossibleException e) {
throw new ToolFailureException(e.getMessage(), e);
}
}
Aggregations