use of com.aws.greengrass.mqttclient.spool.SpoolerConfig in project aws-greengrass-nucleus by aws-greengrass.
the class MqttClientTest method GIVEN_keep_qos_0_when_offline_is_false_and_mqtt_is_offline_WHEN_publish_THEN_future_complete_exceptionally.
@Test
void GIVEN_keep_qos_0_when_offline_is_false_and_mqtt_is_offline_WHEN_publish_THEN_future_complete_exceptionally() throws InterruptedException, SpoolerStoreException {
MqttClient client = spy(new MqttClient(deviceConfiguration, spool, false, (c) -> builder, executorService));
PublishRequest request = PublishRequest.builder().topic("spool").payload(new byte[0]).qos(QualityOfService.AT_MOST_ONCE).build();
SpoolerConfig config = SpoolerConfig.builder().keepQos0WhenOffline(false).spoolSizeInBytes(25L).storageType(SpoolerStorageType.Memory).build();
when(spool.getSpoolConfig()).thenReturn(config);
CompletableFuture<Integer> future = client.publish(request);
assertTrue(future.isCompletedExceptionally());
verify(spool, never()).addMessage(request);
}
use of com.aws.greengrass.mqttclient.spool.SpoolerConfig 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();
}
use of com.aws.greengrass.mqttclient.spool.SpoolerConfig in project aws-greengrass-nucleus by aws-greengrass.
the class MqttClientTest method GIVEN_connection_interrupted_WHEN_callback_THEN_drop_messages_if_required.
@Test
void GIVEN_connection_interrupted_WHEN_callback_THEN_drop_messages_if_required() {
// The mqttClient is initiated when connectivity is offline
MqttClient client = spy(new MqttClient(deviceConfiguration, spool, false, (c) -> builder, executorService));
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();
}
Aggregations