Search in sources :

Example 36 with Context

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());
}
Also used : Context(com.aws.greengrass.dependency.Context) Path(java.nio.file.Path) Configuration(com.aws.greengrass.config.Configuration) KernelLifecycle(com.aws.greengrass.lifecyclemanager.KernelLifecycle) Topic(com.aws.greengrass.config.Topic) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Context (com.aws.greengrass.dependency.Context)36 Topics (com.aws.greengrass.config.Topics)24 Test (org.junit.jupiter.api.Test)21 Configuration (com.aws.greengrass.config.Configuration)19 BeforeEach (org.junit.jupiter.api.BeforeEach)15 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)15 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)14 IOException (java.io.IOException)8 ExecutorService (java.util.concurrent.ExecutorService)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 ChildChanged (com.aws.greengrass.config.ChildChanged)7 WhatHappened (com.aws.greengrass.config.WhatHappened)7 DEVICE_MQTT_NAMESPACE (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_MQTT_NAMESPACE)7 DEVICE_PARAM_AWS_REGION (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION)7 DEVICE_PARAM_CERTIFICATE_FILE_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH)7 DEVICE_PARAM_IOT_DATA_ENDPOINT (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT)7 DEVICE_PARAM_PRIVATE_KEY_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH)7 DEVICE_PARAM_ROOT_CA_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH)7 DEVICE_PARAM_THING_NAME (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME)7 DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT (com.aws.greengrass.mqttclient.MqttClient.DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT)7