Search in sources :

Example 1 with NodeRunner

use of co.rsk.NodeRunner in project rskj by rsksmart.

the class StartBootstrap method runBootstrapNode.

static void runBootstrapNode(@Nonnull RskContext ctx, @Nonnull PreflightChecksUtils preflightChecks, @Nonnull Runtime runtime, @Nonnull NodeStopper nodeStopper) {
    try {
        // make preflight checks
        preflightChecks.runChecks();
        // subscribe to shutdown hook
        runtime.addShutdownHook(new Thread(ctx::close, "stopper"));
        // start node runner
        NodeRunner runner = ctx.getNodeRunner();
        runner.run();
    } catch (Exception e) {
        logger.error("Main thread of RSK bootstrap node crashed", e);
        ctx.close();
        nodeStopper.stop(1);
    }
}
Also used : NodeRunner(co.rsk.NodeRunner)

Example 2 with NodeRunner

use of co.rsk.NodeRunner in project rskj by rsksmart.

the class CliToolsTest method startBootstrap.

@Test
public void startBootstrap() throws Exception {
    // check thread setup
    Thread thread = new Thread(() -> {
    });
    StartBootstrap.setUpThread(thread);
    assertEquals("main", thread.getName());
    // check happy flow of bootstrap node start
    ArgumentCaptor<Thread> threadCaptor = ArgumentCaptor.forClass(Thread.class);
    NodeRunner runner = mock(NodeRunner.class);
    RskContext ctx = mock(RskContext.class);
    doReturn(runner).when(ctx).getNodeRunner();
    PreflightChecksUtils preflightChecks = mock(PreflightChecksUtils.class);
    Runtime runtime = mock(Runtime.class);
    NodeStopper nodeStopper = mock(NodeStopper.class);
    StartBootstrap.runBootstrapNode(ctx, preflightChecks, runtime, nodeStopper);
    verify(preflightChecks, times(1)).runChecks();
    verify(runner, times(1)).run();
    verify(runtime, times(1)).addShutdownHook(threadCaptor.capture());
    assertEquals("stopper", threadCaptor.getValue().getName());
    // check unhappy flow of bootstrap node start
    doThrow(new RuntimeException()).when(preflightChecks).runChecks();
    StartBootstrap.runBootstrapNode(ctx, preflightChecks, runtime, nodeStopper);
    verify(preflightChecks, times(2)).runChecks();
    verify(runner, times(1)).run();
    verify(runtime, times(1)).addShutdownHook(any());
    verify(ctx, times(1)).close();
    verify(nodeStopper, times(1)).stop(1);
}
Also used : RskContext(co.rsk.RskContext) NodeStopper(co.rsk.util.NodeStopper) NodeRunner(co.rsk.NodeRunner) PreflightChecksUtils(co.rsk.util.PreflightChecksUtils) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Aggregations

NodeRunner (co.rsk.NodeRunner)2 RskContext (co.rsk.RskContext)1 NodeStopper (co.rsk.util.NodeStopper)1 PreflightChecksUtils (co.rsk.util.PreflightChecksUtils)1 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)1 Test (org.junit.Test)1