Search in sources :

Example 26 with LifeSupport

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));
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) URI(java.net.URI) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Example 27 with LifeSupport

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();
    }
}
Also used : FreePorts(org.neo4j.cluster.FreePorts) Session(org.neo4j.cluster.FreePorts.Session) Cluster(org.neo4j.cluster.client.Cluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter)

Example 28 with LifeSupport

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));
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) URI(java.net.URI) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Example 29 with LifeSupport

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();
    }
}
Also used : MasterClient320(org.neo4j.kernel.ha.MasterClient320) Monitors(org.neo4j.kernel.monitoring.Monitors) IllegalProtocolVersionException(org.neo4j.com.IllegalProtocolVersionException) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) MasterClient214(org.neo4j.kernel.ha.MasterClient214) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Test(org.junit.Test)

Example 30 with LifeSupport

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);
}
Also used : LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport)

Aggregations

LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)51 Test (org.junit.Test)22 IOException (java.io.IOException)14 File (java.io.File)12 Monitors (org.neo4j.kernel.monitoring.Monitors)12 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)6 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)6 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)5 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)5 Monitor (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor)5 Dependencies (org.neo4j.kernel.impl.util.Dependencies)5 StorageEngine (org.neo4j.storageengine.api.StorageEngine)5 URI (java.net.URI)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Config (org.neo4j.kernel.configuration.Config)4 UnableToCopyStoreFromOldMasterException (org.neo4j.kernel.ha.store.UnableToCopyStoreFromOldMasterException)4 KernelContext (org.neo4j.kernel.impl.spi.KernelContext)4