use of co.rsk.util.PreflightChecksUtils in project rskj by rsksmart.
the class StartBootstrap method main.
public static void main(String[] args) {
setUpThread(Thread.currentThread());
RskContext ctx = new BootstrapRskContext(args);
PreflightChecksUtils preflightChecks = new PreflightChecksUtils(ctx);
Runtime runtime = Runtime.getRuntime();
NodeStopper nodeStopper = System::exit;
runBootstrapNode(ctx, preflightChecks, runtime, nodeStopper);
}
use of co.rsk.util.PreflightChecksUtils in project rskj by rsksmart.
the class StartTest method nodeIsNotRunning_WhenRunNodeAndPreflightCheckSucceeds_ThenNodeRunnerShouldRunWithShutdownHookAdded.
@Test
public void nodeIsNotRunning_WhenRunNodeAndPreflightCheckSucceeds_ThenNodeRunnerShouldRunWithShutdownHookAdded() throws Exception {
Runtime runtime = mock(Runtime.class);
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);
Start.runNode(runtime, preflightChecks, ctx);
verify(preflightChecks, times(1)).runChecks();
verify(runner, times(1)).run();
verify(runtime, times(1)).addShutdownHook(threadCaptor.capture());
Thread stopperThread = threadCaptor.getValue();
assertEquals("stopper", stopperThread.getName());
verify(ctx, never()).close();
// noinspection CallToThreadRun
stopperThread.run();
verify(ctx, times(1)).close();
}
use of co.rsk.util.PreflightChecksUtils in project rskj by rsksmart.
the class StartTest method nodeIsNotRunning_WhenRunNodeAndPreflightCheckFails_ThenNodeRunnerShouldNotRun.
@Test
public void nodeIsNotRunning_WhenRunNodeAndPreflightCheckFails_ThenNodeRunnerShouldNotRun() throws Exception {
Runtime runtime = mock(Runtime.class);
NodeRunner runner = mock(NodeRunner.class);
RskContext ctx = mock(RskContext.class);
doReturn(runner).when(ctx).getNodeRunner();
PreflightChecksUtils preflightChecks = mock(PreflightChecksUtils.class);
doThrow(new PreflightCheckException("test")).when(preflightChecks).runChecks();
try {
Start.runNode(runtime, preflightChecks, ctx);
fail("runNode should throw an exception");
} catch (PreflightCheckException e) {
assertEquals("test", e.getMessage());
verify(preflightChecks, times(1)).runChecks();
verify(runner, never()).run();
verify(runtime, never()).addShutdownHook(any());
}
}
use of co.rsk.util.PreflightChecksUtils in project rskj by rsksmart.
the class Start method main.
public static void main(String[] args) {
setUpThread(Thread.currentThread());
RskContext ctx = null;
try {
ctx = new RskContext(args);
runNode(Runtime.getRuntime(), new PreflightChecksUtils(ctx), ctx);
} catch (Exception e) {
logger.error("The RSK node main thread failed, closing program", e);
if (ctx != null) {
ctx.close();
}
System.exit(1);
}
}
use of co.rsk.util.PreflightChecksUtils 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