use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.
the class KernelTest method GIVEN_kernel_running_WHEN_truncate_tlog_and_shutdown_THEN_tlog_consistent_with_config.
@SuppressWarnings("PMD.CloseResource")
@Test
void GIVEN_kernel_running_WHEN_truncate_tlog_and_shutdown_THEN_tlog_consistent_with_config() throws Exception {
kernel.parseArgs().launch();
Configuration config = kernel.getConfig();
Context context = kernel.getContext();
Path configPath = tempRootDir.resolve("config");
Topic testTopic = config.lookup("testTopic").withValue("initial");
KernelLifecycle kernelLifecycle = context.get(KernelLifecycle.class);
context.runOnPublishQueueAndWait(() -> {
// make truncate run by setting a small limit
kernelLifecycle.getTlog().withMaxEntries(1);
testTopic.withValue("triggering truncate");
// immediately queue a task to increase max size to prevent repeated truncation
context.runOnPublishQueue(() -> kernelLifecycle.getTlog().withMaxEntries(10000));
});
// wait for things to complete
CountDownLatch startupCdl = new CountDownLatch(1);
context.addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals("main") && newState.equals(State.FINISHED)) {
startupCdl.countDown();
}
});
startupCdl.await(30, TimeUnit.SECONDS);
// shutdown to stop config/tlog changes
kernel.shutdown();
Configuration tlogConfig = ConfigurationReader.createFromTLog(context, configPath.resolve("config.tlog"));
assertEquals("triggering truncate", tlogConfig.find("testTopic").getOnce());
// data type may be different when recreating tlog
// using this to coerce to string for comparison
assertEqualsDeepMap(config.toPOJO(), tlogConfig.toPOJO());
}
Aggregations