Search in sources :

Example 21 with Context

use of com.aws.greengrass.dependency.Context 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());
    }
}
Also used : Context(com.aws.greengrass.dependency.Context) Topics(com.aws.greengrass.config.Topics) Configuration(com.aws.greengrass.config.Configuration) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) UpdateBehaviorTree(com.aws.greengrass.config.UpdateBehaviorTree) NucleusPaths(com.aws.greengrass.util.NucleusPaths) Logger(com.aws.greengrass.logging.api.Logger) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Test(org.junit.jupiter.api.Test)

Example 22 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.

the class MqttClientTest method GIVEN_publish_request_unsuccessfully_WHEN_spool_single_message_THEN_not_retry_if_have_retried_max_times.

@Test
void GIVEN_publish_request_unsuccessfully_WHEN_spool_single_message_THEN_not_retry_if_have_retried_max_times(ExtensionContext context) throws InterruptedException {
    ignoreExceptionOfType(context, ExecutionException.class);
    MqttClient client = spy(new MqttClient(deviceConfiguration, spool, true, (c) -> builder, executorService));
    long id = 1L;
    when(spool.popId()).thenReturn(id);
    PublishRequest request = PublishRequest.builder().topic("spool").payload("What's up".getBytes(StandardCharsets.UTF_8)).qos(QualityOfService.AT_LEAST_ONCE).build();
    SpoolMessage message = SpoolMessage.builder().id(id).request(request).build();
    message.getRetried().set(DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT);
    when(spool.getMessageById(id)).thenReturn(message);
    AwsIotMqttClient awsIotMqttClient = mock(AwsIotMqttClient.class);
    CompletableFuture<Integer> future = new CompletableFuture<>();
    future.completeExceptionally(new ExecutionException("exception", new Throwable()));
    when(awsIotMqttClient.publish(any(), any(), anyBoolean())).thenReturn(future);
    client.publishSingleSpoolerMessage(awsIotMqttClient);
    verify(awsIotMqttClient).publish(any(), any(), anyBoolean());
    verify(spool, never()).removeMessageById(anyLong());
    verify(spool, never()).addId(anyLong());
}
Also used : SpoolerStoreException(com.aws.greengrass.mqttclient.spool.SpoolerStoreException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Matchers.either(org.hamcrest.Matchers.either) DEVICE_PARAM_ROOT_CA_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TimeoutException(java.util.concurrent.TimeoutException) SpoolMessage(com.aws.greengrass.mqttclient.spool.SpoolMessage) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AwsIotMqttConnectionBuilder(software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder) TestUtils.asyncAssertOnConsumer(com.aws.greengrass.testcommons.testutilities.TestUtils.asyncAssertOnConsumer) DEVICE_PARAM_PRIVATE_KEY_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH) Configuration(com.aws.greengrass.config.Configuration) SpoolerStorageType(com.aws.greengrass.mqttclient.spool.SpoolerStorageType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT(com.aws.greengrass.mqttclient.MqttClient.DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT) MqttClientConnection(software.amazon.awssdk.crt.mqtt.MqttClientConnection) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) Mockito.doNothing(org.mockito.Mockito.doNothing) ExceptionLogProtector.ignoreExceptionOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionOfType) Pair(com.aws.greengrass.util.Pair) StandardCharsets(java.nio.charset.StandardCharsets) ChildChanged(com.aws.greengrass.config.ChildChanged) Test(org.junit.jupiter.api.Test) Topics(com.aws.greengrass.config.Topics) MqttMessage(software.amazon.awssdk.crt.mqtt.MqttMessage) List(java.util.List) DEVICE_PARAM_CERTIFICATE_FILE_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH) MAX_NUMBER_OF_FORWARD_SLASHES(com.aws.greengrass.mqttclient.MqttClient.MAX_NUMBER_OF_FORWARD_SLASHES) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DEVICE_PARAM_AWS_REGION(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) CompletableFuture(java.util.concurrent.CompletableFuture) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Mockito.lenient(org.mockito.Mockito.lenient) SpoolerConfig(com.aws.greengrass.mqttclient.spool.SpoolerConfig) MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES(com.aws.greengrass.mqttclient.MqttClient.MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES) Mockito.timeout(org.mockito.Mockito.timeout) ArgumentCaptor(org.mockito.ArgumentCaptor) QualityOfService(software.amazon.awssdk.crt.mqtt.QualityOfService) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Context(com.aws.greengrass.dependency.Context) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) DEVICE_PARAM_IOT_DATA_ENDPOINT(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT) DEVICE_MQTT_NAMESPACE(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_MQTT_NAMESPACE) Spool(com.aws.greengrass.mqttclient.spool.Spool) DEVICE_PARAM_THING_NAME(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ExceptionLogProtector.ignoreExceptionWithMessage(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionWithMessage) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) Mockito.never(org.mockito.Mockito.never) WhatHappened(com.aws.greengrass.config.WhatHappened) Collections(java.util.Collections) MAX_LENGTH_OF_TOPIC(com.aws.greengrass.mqttclient.MqttClient.MAX_LENGTH_OF_TOPIC) CompletableFuture(java.util.concurrent.CompletableFuture) SpoolMessage(com.aws.greengrass.mqttclient.spool.SpoolMessage) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 23 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.

the class MqttClientTest method GIVEN_add_message_to_spooler_throw_spooler_load_exception_WHEN_publish_THEN_return_future_complete_exceptionally.

@Test
void GIVEN_add_message_to_spooler_throw_spooler_load_exception_WHEN_publish_THEN_return_future_complete_exceptionally(ExtensionContext context) throws SpoolerStoreException, InterruptedException {
    MqttClient client = spy(new MqttClient(deviceConfiguration, spool, false, (c) -> builder, executorService));
    PublishRequest request = PublishRequest.builder().topic("spool").payload(new byte[10]).qos(QualityOfService.AT_LEAST_ONCE).build();
    when(spool.addMessage(any())).thenThrow(new SpoolerStoreException("spooler is full"));
    ignoreExceptionOfType(context, SpoolerStoreException.class);
    CompletableFuture<Integer> future = client.publish(request);
    assertTrue(future.isCompletedExceptionally());
    verify(spool, times(1)).addMessage(request);
    verify(spool, never()).getSpoolConfig();
}
Also used : SpoolerStoreException(com.aws.greengrass.mqttclient.spool.SpoolerStoreException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Matchers.either(org.hamcrest.Matchers.either) DEVICE_PARAM_ROOT_CA_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TimeoutException(java.util.concurrent.TimeoutException) SpoolMessage(com.aws.greengrass.mqttclient.spool.SpoolMessage) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AwsIotMqttConnectionBuilder(software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder) TestUtils.asyncAssertOnConsumer(com.aws.greengrass.testcommons.testutilities.TestUtils.asyncAssertOnConsumer) DEVICE_PARAM_PRIVATE_KEY_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH) Configuration(com.aws.greengrass.config.Configuration) SpoolerStorageType(com.aws.greengrass.mqttclient.spool.SpoolerStorageType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT(com.aws.greengrass.mqttclient.MqttClient.DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT) MqttClientConnection(software.amazon.awssdk.crt.mqtt.MqttClientConnection) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) Mockito.doNothing(org.mockito.Mockito.doNothing) ExceptionLogProtector.ignoreExceptionOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionOfType) Pair(com.aws.greengrass.util.Pair) StandardCharsets(java.nio.charset.StandardCharsets) ChildChanged(com.aws.greengrass.config.ChildChanged) Test(org.junit.jupiter.api.Test) Topics(com.aws.greengrass.config.Topics) MqttMessage(software.amazon.awssdk.crt.mqtt.MqttMessage) List(java.util.List) DEVICE_PARAM_CERTIFICATE_FILE_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH) MAX_NUMBER_OF_FORWARD_SLASHES(com.aws.greengrass.mqttclient.MqttClient.MAX_NUMBER_OF_FORWARD_SLASHES) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DEVICE_PARAM_AWS_REGION(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) CompletableFuture(java.util.concurrent.CompletableFuture) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Mockito.lenient(org.mockito.Mockito.lenient) SpoolerConfig(com.aws.greengrass.mqttclient.spool.SpoolerConfig) MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES(com.aws.greengrass.mqttclient.MqttClient.MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES) Mockito.timeout(org.mockito.Mockito.timeout) ArgumentCaptor(org.mockito.ArgumentCaptor) QualityOfService(software.amazon.awssdk.crt.mqtt.QualityOfService) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Context(com.aws.greengrass.dependency.Context) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) DEVICE_PARAM_IOT_DATA_ENDPOINT(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT) DEVICE_MQTT_NAMESPACE(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_MQTT_NAMESPACE) Spool(com.aws.greengrass.mqttclient.spool.Spool) DEVICE_PARAM_THING_NAME(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ExceptionLogProtector.ignoreExceptionWithMessage(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionWithMessage) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) Mockito.never(org.mockito.Mockito.never) WhatHappened(com.aws.greengrass.config.WhatHappened) Collections(java.util.Collections) MAX_LENGTH_OF_TOPIC(com.aws.greengrass.mqttclient.MqttClient.MAX_LENGTH_OF_TOPIC) SpoolerStoreException(com.aws.greengrass.mqttclient.spool.SpoolerStoreException) Test(org.junit.jupiter.api.Test)

Example 24 with Context

use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.

the class MqttClientTest method GIVEN_connection_resumed_WHEN_callback_THEN_start_spool_messages.

@Test
void GIVEN_connection_resumed_WHEN_callback_THEN_start_spool_messages(ExtensionContext context) throws InterruptedException {
    ignoreExceptionOfType(context, InterruptedException.class);
    ignoreExceptionWithMessage(context, "interrupted");
    // The mqttClient is initiated when connectivity is offline
    MqttClient client = spy(new MqttClient(deviceConfiguration, spool, false, (c) -> builder, executorService));
    Long id = 1L;
    PublishRequest request = PublishRequest.builder().topic("spool").payload("What's up".getBytes(StandardCharsets.UTF_8)).qos(QualityOfService.AT_LEAST_ONCE).build();
    SpoolMessage message = SpoolMessage.builder().id(id).request(request).build();
    when(spool.getMessageById(id)).thenReturn(message);
    // Throw an InterruptedException to break the while loop in the client.spoolMessages()
    when(spool.popId()).thenReturn(id).thenThrow(new InterruptedException("interrupted"));
    client.getCallbacks().onConnectionResumed(false);
    // Confirm the spooler was working
    verify(spool, times(1)).getMessageById(anyLong());
    verify(spool, times(2)).popId();
    SpoolerConfig config = SpoolerConfig.builder().spoolSizeInBytes(10L).storageType(SpoolerStorageType.Memory).keepQos0WhenOffline(false).build();
    when(spool.getSpoolConfig()).thenReturn(config);
    client.getCallbacks().onConnectionInterrupted(1);
    verify(spool).getSpoolConfig();
    verify(spool).popOutMessagesWithQosZero();
}
Also used : SpoolerStoreException(com.aws.greengrass.mqttclient.spool.SpoolerStoreException) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Matchers.either(org.hamcrest.Matchers.either) DEVICE_PARAM_ROOT_CA_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TimeoutException(java.util.concurrent.TimeoutException) SpoolMessage(com.aws.greengrass.mqttclient.spool.SpoolMessage) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AwsIotMqttConnectionBuilder(software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder) TestUtils.asyncAssertOnConsumer(com.aws.greengrass.testcommons.testutilities.TestUtils.asyncAssertOnConsumer) DEVICE_PARAM_PRIVATE_KEY_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH) Configuration(com.aws.greengrass.config.Configuration) SpoolerStorageType(com.aws.greengrass.mqttclient.spool.SpoolerStorageType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT(com.aws.greengrass.mqttclient.MqttClient.DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT) MqttClientConnection(software.amazon.awssdk.crt.mqtt.MqttClientConnection) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) Mockito.doNothing(org.mockito.Mockito.doNothing) ExceptionLogProtector.ignoreExceptionOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionOfType) Pair(com.aws.greengrass.util.Pair) StandardCharsets(java.nio.charset.StandardCharsets) ChildChanged(com.aws.greengrass.config.ChildChanged) Test(org.junit.jupiter.api.Test) Topics(com.aws.greengrass.config.Topics) MqttMessage(software.amazon.awssdk.crt.mqtt.MqttMessage) List(java.util.List) DEVICE_PARAM_CERTIFICATE_FILE_PATH(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH) MAX_NUMBER_OF_FORWARD_SLASHES(com.aws.greengrass.mqttclient.MqttClient.MAX_NUMBER_OF_FORWARD_SLASHES) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DEVICE_PARAM_AWS_REGION(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION) Matchers.is(org.hamcrest.Matchers.is) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) CompletableFuture(java.util.concurrent.CompletableFuture) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Mockito.lenient(org.mockito.Mockito.lenient) SpoolerConfig(com.aws.greengrass.mqttclient.spool.SpoolerConfig) MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES(com.aws.greengrass.mqttclient.MqttClient.MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES) Mockito.timeout(org.mockito.Mockito.timeout) ArgumentCaptor(org.mockito.ArgumentCaptor) QualityOfService(software.amazon.awssdk.crt.mqtt.QualityOfService) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Context(com.aws.greengrass.dependency.Context) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ExecutorService(java.util.concurrent.ExecutorService) DEVICE_PARAM_IOT_DATA_ENDPOINT(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT) DEVICE_MQTT_NAMESPACE(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_MQTT_NAMESPACE) Spool(com.aws.greengrass.mqttclient.spool.Spool) DEVICE_PARAM_THING_NAME(com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ExceptionLogProtector.ignoreExceptionWithMessage(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionWithMessage) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AfterEach(org.junit.jupiter.api.AfterEach) Mockito.never(org.mockito.Mockito.never) WhatHappened(com.aws.greengrass.config.WhatHappened) Collections(java.util.Collections) MAX_LENGTH_OF_TOPIC(com.aws.greengrass.mqttclient.MqttClient.MAX_LENGTH_OF_TOPIC) SpoolMessage(com.aws.greengrass.mqttclient.spool.SpoolMessage) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) SpoolerConfig(com.aws.greengrass.mqttclient.spool.SpoolerConfig) Test(org.junit.jupiter.api.Test)

Example 25 with Context

use of com.aws.greengrass.dependency.Context 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();
}
Also used : Context(com.aws.greengrass.dependency.Context) Configuration(com.aws.greengrass.config.Configuration) BeforeEach(org.junit.jupiter.api.BeforeEach)

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