Search in sources :

Example 1 with DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT

use of com.aws.greengrass.mqttclient.MqttClient.DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT 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)

Aggregations

ChildChanged (com.aws.greengrass.config.ChildChanged)1 Configuration (com.aws.greengrass.config.Configuration)1 Topics (com.aws.greengrass.config.Topics)1 WhatHappened (com.aws.greengrass.config.WhatHappened)1 Context (com.aws.greengrass.dependency.Context)1 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 DEVICE_MQTT_NAMESPACE (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_MQTT_NAMESPACE)1 DEVICE_PARAM_AWS_REGION (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_AWS_REGION)1 DEVICE_PARAM_CERTIFICATE_FILE_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_CERTIFICATE_FILE_PATH)1 DEVICE_PARAM_IOT_DATA_ENDPOINT (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_IOT_DATA_ENDPOINT)1 DEVICE_PARAM_PRIVATE_KEY_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_PRIVATE_KEY_PATH)1 DEVICE_PARAM_ROOT_CA_PATH (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_ROOT_CA_PATH)1 DEVICE_PARAM_THING_NAME (com.aws.greengrass.deployment.DeviceConfiguration.DEVICE_PARAM_THING_NAME)1 DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT (com.aws.greengrass.mqttclient.MqttClient.DEFAULT_MQTT_MAX_OF_PUBLISH_RETRY_COUNT)1 MAX_LENGTH_OF_TOPIC (com.aws.greengrass.mqttclient.MqttClient.MAX_LENGTH_OF_TOPIC)1 MAX_NUMBER_OF_FORWARD_SLASHES (com.aws.greengrass.mqttclient.MqttClient.MAX_NUMBER_OF_FORWARD_SLASHES)1 MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES (com.aws.greengrass.mqttclient.MqttClient.MQTT_MAX_LIMIT_OF_MESSAGE_SIZE_IN_BYTES)1 Spool (com.aws.greengrass.mqttclient.spool.Spool)1 SpoolMessage (com.aws.greengrass.mqttclient.spool.SpoolMessage)1 SpoolerConfig (com.aws.greengrass.mqttclient.spool.SpoolerConfig)1