use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class SwitchToSlaveBranchThenCopyTest method updatesPulledAndPullingScheduledOnSwitchToSlave.
@Test
public void updatesPulledAndPullingScheduledOnSwitchToSlave() throws Throwable {
SwitchToSlaveBranchThenCopy switchToSlave = newSwitchToSlaveSpy();
when(fs.fileExists(any(File.class))).thenReturn(true);
JobScheduler jobScheduler = mock(JobScheduler.class);
LifeSupport communicationLife = mock(LifeSupport.class);
URI localhost = getLocalhostUri();
final UpdatePullerScheduler pullerScheduler = new UpdatePullerScheduler(jobScheduler, NullLogProvider.getInstance(), updatePuller, 10L);
when(pullerFactory.createUpdatePullerScheduler(updatePuller)).thenReturn(pullerScheduler);
// emulate lifecycle start call on scheduler
doAnswer(invocationOnMock -> {
pullerScheduler.init();
return null;
}).when(communicationLife).start();
switchToSlave.switchToSlave(communicationLife, localhost, localhost, mock(CancellationRequest.class));
verify(updatePuller).tryPullUpdates();
verify(communicationLife).add(pullerScheduler);
verify(jobScheduler).scheduleRecurring(eq(JobScheduler.Groups.pullUpdates), any(Runnable.class), eq(10L), eq(10L), eq(TimeUnit.MILLISECONDS));
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class ClusterManager method start.
@Override
public void start() throws Throwable {
FreePorts.Session session = PORTS.newSession();
Cluster cluster = clustersProvider.apply(session);
life = new LifeSupport();
life.add(new LifecycleAdapter() {
@Override
public void shutdown() throws Throwable {
session.close();
}
});
// Started so instances added here will be started immediately, and in case of exceptions they can be
// shutdown() or stop()ped properly
life.start();
managedCluster = new ManagedCluster(cluster, session);
life.add(managedCluster);
availabilityChecks.forEach(managedCluster::await);
if (initialDatasetCreator != null) {
initialDatasetCreator.receive(managedCluster.getMaster());
managedCluster.sync();
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranchTest method updatesPulledAndPullingScheduledOnSwitchToSlave.
@Test
public void updatesPulledAndPullingScheduledOnSwitchToSlave() throws Throwable {
SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy();
when(fs.fileExists(any(File.class))).thenReturn(true);
JobScheduler jobScheduler = mock(JobScheduler.class);
LifeSupport communicationLife = mock(LifeSupport.class);
URI localhost = getLocalhostUri();
final UpdatePullerScheduler pullerScheduler = new UpdatePullerScheduler(jobScheduler, NullLogProvider.getInstance(), updatePuller, 10L);
when(pullerFactory.createUpdatePullerScheduler(updatePuller)).thenReturn(pullerScheduler);
// emulate lifecycle start call on scheduler
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
pullerScheduler.init();
return null;
}
}).when(communicationLife).start();
switchToSlave.switchToSlave(communicationLife, localhost, localhost, mock(CancellationRequest.class));
verify(updatePuller).tryPullUpdates();
verify(communicationLife).add(pullerScheduler);
verify(jobScheduler).scheduleRecurring(eq(JobScheduler.Groups.pullUpdates), any(Runnable.class), eq(10L), eq(10L), eq(TimeUnit.MILLISECONDS));
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class MasterClientResolverTest method shouldResolveMasterClientFactory.
@Test
public void shouldResolveMasterClientFactory() throws Exception {
// Given
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
MasterClientResolver resolver = new MasterClientResolver(NullLogProvider.getInstance(), ResponseUnpacker.NO_OP_RESPONSE_UNPACKER, mock(InvalidEpochExceptionHandler.class), 1, 1, 1, 1024, Suppliers.singleton(logEntryReader));
LifeSupport life = new LifeSupport();
try {
life.start();
MasterClient masterClient1 = resolver.instantiate("cluster://localhost", 44, null, new Monitors(), StoreId.DEFAULT, life);
assertThat(masterClient1, instanceOf(MasterClient320.class));
} finally {
life.shutdown();
}
IllegalProtocolVersionException illegalProtocolVersionException = new IllegalProtocolVersionException(MasterClient214.PROTOCOL_VERSION.getApplicationProtocol(), MasterClient310.PROTOCOL_VERSION.getApplicationProtocol(), "Protocol is too modern");
// When
resolver.handle(illegalProtocolVersionException);
// Then
life = new LifeSupport();
try {
life.start();
MasterClient masterClient2 = resolver.instantiate("cluster://localhost", 55, null, new Monitors(), StoreId.DEFAULT, life);
assertThat(masterClient2, instanceOf(MasterClient214.class));
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class DataSourceManager method init.
@Override
public void init() throws Throwable {
life = new LifeSupport();
life.add(dataSource);
}
Aggregations