use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class LifecycleTest method GIVEN_config_updated_THEN_service_is_restarted_with_new_config.
@Test
void GIVEN_config_updated_THEN_service_is_restarted_with_new_config() throws Exception {
Configuration config = new Configuration(context);
Topics testServiceTopics = config.getRoot().createInteriorChild(GreengrassService.SERVICES_NAMESPACE_TOPIC).createInteriorChild("testService");
TestService testService = new TestService(testServiceTopics);
testServiceTopics.subscribe((child, newVal) -> {
testService.requestRestart();
});
String newConfigString = "{\n" + " \"services\":{\n" + " \"testService\": {\n" + " \"lifecycle\": {\n" + " \"startup\": {\n" + " \"timeout\": 7\n" + " },\n" + " \"shutdown\": {\n" + " \"timeout\": 8\n" + " }\n" + " },\n" + " \"dependencies\": []" + " }\n" + " }\n" + "}";
Map<String, Object> newConfig = objectMapper.readValue(newConfigString, Map.class);
AtomicBoolean configUnderUpdate = new AtomicBoolean(false);
CountDownLatch configUpdateFinished = new CountDownLatch(1);
testService.setStartupRunnable(() -> {
if (configUnderUpdate.get()) {
assertEquals(newConfig, config.toPOJO());
configUnderUpdate.set(false);
configUpdateFinished.countDown();
}
testService.reportState(State.RUNNING);
});
// init lifecycle
testService.postInject();
testService.requestStart();
assertThat(testService::getState, eventuallyEval(is(State.RUNNING)));
// merge in new config
configUnderUpdate.set(true);
config.updateMap(newConfig, new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, Integer.MAX_VALUE));
assertTrue(configUpdateFinished.await(2, TimeUnit.SECONDS), "updated config:" + config.toPOJO().toString());
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class LogManagerHelperTest method loggers_created_before_or_after_log_level_change_get_the_correct_level.
@Test
void loggers_created_before_or_after_log_level_change_get_the_correct_level() throws IOException {
try (Context context = new Context()) {
Configuration config = new Configuration(context);
Topics logTopics = config.lookupTopics(SERVICES_NAMESPACE_TOPIC, DEFAULT_NUCLEUS_COMPONENT_NAME, CONFIGURATION_CONFIG_KEY, NUCLEUS_CONFIG_LOGGING_TOPICS);
when(kernel.getConfig()).thenReturn(config);
lenient().when(kernel.getNucleusPaths()).thenReturn(mock(NucleusPaths.class));
when(mockGreengrassService.getServiceName()).thenReturn("MockService3");
Logger logger1 = LogManagerHelper.getComponentLogger(mockGreengrassService);
assertFalse(logger1.isDebugEnabled());
new DeviceConfiguration(kernel);
context.runOnPublishQueueAndWait(() -> logTopics.updateFromMap(Utils.immutableMap("level", "DEBUG"), new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.REPLACE, System.currentTimeMillis())));
context.waitForPublishQueueToClear();
when(mockGreengrassService.getServiceName()).thenReturn("MockService4");
Logger logger2 = LogManagerHelper.getComponentLogger(mockGreengrassService);
assertTrue(logger2.isDebugEnabled());
assertTrue(logger1.isDebugEnabled());
}
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentStatusKeeperTest method setup.
@BeforeEach
void setup() {
context = new Context();
Configuration config = new Configuration(context);
when(deploymentService.getRuntimeConfig()).thenReturn(config.lookupTopics(GreengrassService.SERVICES_NAMESPACE_TOPIC, DeploymentService.DEPLOYMENT_SERVICE_TOPICS, GreengrassService.RUNTIME_STORE_NAMESPACE_TOPIC));
deploymentStatusKeeper = new DeploymentStatusKeeper();
deploymentStatusKeeper.setDeploymentService(deploymentService);
processedDeployments = deploymentStatusKeeper.getProcessedDeployments();
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class MergeTest method testSomeMethod.
@Test
void testSomeMethod() throws Exception {
try (Context context = new Context()) {
Configuration c = new Configuration(context);
c.read(Kernel.class.getResource("config.yaml"), false);
Configuration b = new Configuration(context).copyFrom(c);
assertEquals(c.getRoot(), b.getRoot());
}
}
use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.
the class KernelConfigResolverTest method setupMocks.
@BeforeEach
void setupMocks() throws IOException {
path = Paths.get("Artifacts", TEST_INPUT_PACKAGE_A);
lenient().when(nucleusPaths.artifactPath(any())).thenReturn(path.toAbsolutePath());
config = new Configuration(new Context());
lenient().when(kernel.getConfig()).thenReturn(config);
lenient().when(deviceConfiguration.getNucleusComponentName()).thenReturn(DEFAULT_NUCLEUS_COMPONENT_NAME);
lenient().when(deviceConfiguration.getThingName()).thenReturn(config.lookup("thingname").withValue(THE_THINGNAME));
}
Aggregations