Search in sources :

Example 11 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel in project aws-greengrass-nucleus by aws-greengrass.

the class GenericExternalServiceIntegTest method beforeEach.

@BeforeEach
void beforeEach() {
    kernel = new Kernel();
    NoOpPathOwnershipHandler.register(kernel);
}
Also used : Kernel(com.aws.greengrass.lifecyclemanager.Kernel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel in project aws-greengrass-nucleus by aws-greengrass.

the class KernelRestartTest method GIVEN_kernel_shuts_down_WHEN_kernel_restarts_with_a_new_config_THEN_it_should_start_with_the_new_config.

@Test
void GIVEN_kernel_shuts_down_WHEN_kernel_restarts_with_a_new_config_THEN_it_should_start_with_the_new_config() throws Exception {
    // GIVEN
    kernel = new Kernel();
    ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, this.getClass().getResource("kernel_restart_initial_config.yaml"));
    kernel.launch();
    assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_1")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_2")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_2").getConfig().find("setenv", "key1").getOnce(), is(equalTo("value1")));
    kernel.shutdown();
    // WHEN
    // start Nucleus with parseArgs input so previous config tlog will be ignored.
    kernel = new Kernel();
    kernel.parseArgs("-i", this.getClass().getResource("kernel_restart_new_config.yaml").toString());
    kernel.launch();
    // THEN
    assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    // service 3 is added
    assertThat(kernel.locate("service_3")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    // service 2's setenv is updated
    assertThat(kernel.locate("service_2")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_2").getConfig().find("setenv", "key1").getOnce(), is(equalTo("new_value1")));
    // service 1 is removed
    assertThrows(ServiceLoadException.class, () -> kernel.locate("service_1"), "actual kernel config: " + kernel.getConfig().toPOJO());
}
Also used : Kernel(com.aws.greengrass.lifecyclemanager.Kernel) Test(org.junit.jupiter.api.Test)

Example 13 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel in project aws-greengrass-nucleus by aws-greengrass.

the class KernelRestartTest method GIVEN_kernel_shuts_down_WHEN_kernel_restarts_with_same_root_dir_THEN_it_should_get_back_to_prev_state.

@Test
void GIVEN_kernel_shuts_down_WHEN_kernel_restarts_with_same_root_dir_THEN_it_should_get_back_to_prev_state() throws Exception {
    // GIVEN
    kernel = new Kernel();
    ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, this.getClass().getResource("kernel_restart_initial_config.yaml"));
    kernel.launch();
    assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_1")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_2")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_2").getConfig().find("setenv", "key1").getOnce(), is(equalTo("value1")));
    kernel.shutdown();
    // WHEN
    kernel = new Kernel();
    kernel.parseArgs().launch();
    // THEN
    assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_1")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_2")::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    assertThat(kernel.locate("service_2").getConfig().find("setenv", "key1").getOnce(), is(equalTo("value1")));
}
Also used : Kernel(com.aws.greengrass.lifecyclemanager.Kernel) Test(org.junit.jupiter.api.Test)

Example 14 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel in project aws-greengrass-nucleus by aws-greengrass.

the class KernelRestartTest method GIVEN_kernel_launch_cleanly_and_shutdown_WHEN_kernel_restarts_with_same_root_dir_THEN_it_is_successful.

@Test
void GIVEN_kernel_launch_cleanly_and_shutdown_WHEN_kernel_restarts_with_same_root_dir_THEN_it_is_successful() {
    // note that this test is mainly to verify system plugins restart fine with tlog
    // GIVEN
    kernel = new Kernel();
    kernel.parseArgs();
    kernel.launch();
    assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
    kernel.shutdown();
    // WHEN
    kernel = new Kernel();
    kernel.parseArgs().launch();
    // THEN
    assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED), TIMEOUT));
}
Also used : Kernel(com.aws.greengrass.lifecyclemanager.Kernel) Test(org.junit.jupiter.api.Test)

Example 15 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel in project aws-greengrass-nucleus by aws-greengrass.

the class KernelShutdownTest method beforeEach.

@BeforeEach
void beforeEach() throws Exception {
    kernel = new Kernel();
    ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, getClass().getResource("long_running_services.yaml"));
    kernel.launch();
}
Also used : Kernel(com.aws.greengrass.lifecyclemanager.Kernel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Kernel (com.aws.greengrass.lifecyclemanager.Kernel)49 CountDownLatch (java.util.concurrent.CountDownLatch)22 BeforeEach (org.junit.jupiter.api.BeforeEach)22 Test (org.junit.jupiter.api.Test)22 HashMap (java.util.HashMap)13 IOException (java.io.IOException)12 DeploymentConfigMerger (com.aws.greengrass.deployment.DeploymentConfigMerger)11 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)11 Map (java.util.Map)11 List (java.util.List)10 TimeUnit (java.util.concurrent.TimeUnit)10 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 State (com.aws.greengrass.dependency.State)9 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)9 BaseITCase (com.aws.greengrass.integrationtests.BaseITCase)9 ConfigPlatformResolver (com.aws.greengrass.integrationtests.util.ConfigPlatformResolver)9 TestUtils (com.aws.greengrass.testcommons.testutilities.TestUtils)9 Coerce (com.aws.greengrass.util.Coerce)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 LogManager (com.aws.greengrass.logging.impl.LogManager)8