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);
}
}
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);
}
Aggregations