Search in sources :

Example 1 with PreflightChecksUtils

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);
}
Also used : RskContext(co.rsk.RskContext) NodeStopper(co.rsk.util.NodeStopper) PreflightChecksUtils(co.rsk.util.PreflightChecksUtils)

Example 2 with PreflightChecksUtils

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();
}
Also used : PreflightChecksUtils(co.rsk.util.PreflightChecksUtils) Test(org.junit.Test)

Example 3 with PreflightChecksUtils

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());
    }
}
Also used : PreflightCheckException(co.rsk.util.PreflightCheckException) PreflightChecksUtils(co.rsk.util.PreflightChecksUtils) Test(org.junit.Test)

Example 4 with PreflightChecksUtils

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);
    }
}
Also used : PreflightChecksUtils(co.rsk.util.PreflightChecksUtils)

Example 5 with PreflightChecksUtils

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

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