use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.
the class ConfigStoreIPCEventStreamAgentTest method setup.
@BeforeEach
public void setup() {
configuration = new Configuration(new Context());
Topics root = configuration.getRoot();
root.lookup(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_A, CONFIGURATION_CONFIG_KEY, TEST_CONFIG_KEY_1).withNewerValue(100, TEST_CONFIG_KEY_1_INITIAL_VALUE);
root.lookup(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_A, CONFIGURATION_CONFIG_KEY, TEST_CONFIG_KEY_2).withNewerValue(100, TEST_CONFIG_KEY_2_INITIAL_VALUE);
root.lookupTopics(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_B);
root.lookup(SERVICES_NAMESPACE_TOPIC, TEST_COMPONENT_B, CONFIGURATION_CONFIG_KEY, TEST_CONFIG_KEY_3).withNewerValue(100, TEST_CONFIG_KEY_3_INITIAL_VALUE);
configuration.context.waitForPublishQueueToClear();
lenient().when(kernel.getConfig()).thenReturn(configuration);
when(mockContext.getContinuation()).thenReturn(mockServerConnectionContinuation);
when(mockContext.getAuthenticationData()).thenReturn(mockAuthenticationData);
lenient().when(mockContext2.getContinuation()).thenReturn(mock(ServerConnectionContinuation.class));
lenient().when(mockContext2.getAuthenticationData()).thenReturn(mockAuthenticationData2);
agent = new ConfigStoreIPCEventStreamAgent();
agent.setKernel(kernel);
}
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_add_id_back_to_spooler_if_will_retry.
@Test
void GIVEN_publish_request_unsuccessfully_WHEN_spool_single_message_THEN_add_id_back_to_spooler_if_will_retry(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();
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).addId(anyLong());
}
use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.
the class MqttClientTest method GIVEN_incoming_message_WHEN_received_and_subscriber_throws_THEN_still_calls_remaining_subscriptions.
@Test
void GIVEN_incoming_message_WHEN_received_and_subscriber_throws_THEN_still_calls_remaining_subscriptions(ExtensionContext context) throws ExecutionException, InterruptedException, TimeoutException {
ignoreExceptionWithMessage(context, "Uncaught!");
MqttClient client = spy(new MqttClient(deviceConfiguration, (c) -> builder, ses, executorService));
AwsIotMqttClient mockIndividual = mock(AwsIotMqttClient.class);
when(mockIndividual.subscribe(any(), any())).thenReturn(CompletableFuture.completedFuture(0));
when(client.getNewMqttClient()).thenReturn(mockIndividual);
assertFalse(client.connected());
client.subscribe(SubscribeRequest.builder().topic("A/B/+").callback((m) -> {
throw new RuntimeException("Uncaught!");
}).build());
Pair<CompletableFuture<Void>, Consumer<MqttMessage>> abc = asyncAssertOnConsumer((m) -> {
assertEquals("A/B/C", m.getTopic());
});
client.subscribe(SubscribeRequest.builder().topic("A/B/C").callback(abc.getRight()).build());
Consumer<MqttMessage> handler = client.getMessageHandlerForClient(mockIndividual);
handler.accept(new MqttMessage("A/B/C", new byte[0]));
abc.getLeft().get(0, TimeUnit.SECONDS);
}
use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.
the class MqttClientTest method GIVEN_publish_request_execution_exception_WHEN_spool_message_THEN_continue_spooling_message.
@Test
void GIVEN_publish_request_execution_exception_WHEN_spool_message_THEN_continue_spooling_message(ExtensionContext context) throws InterruptedException {
ignoreExceptionOfType(context, ExecutionException.class);
ignoreExceptionOfType(context, InterruptedException.class);
MqttClient client = spy(new MqttClient(deviceConfiguration, spool, true, (c) -> builder, executorService));
client.setMqttOnline(true);
long id = 1L;
when(spool.popId()).thenReturn(id).thenReturn(id).thenThrow(InterruptedException.class);
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);
AwsIotMqttClient awsIotMqttClient = mock(AwsIotMqttClient.class);
when(client.getNewMqttClient()).thenReturn(awsIotMqttClient);
when(awsIotMqttClient.connect()).thenReturn(CompletableFuture.completedFuture(true));
CompletableFuture<Integer> future = new CompletableFuture<>();
future.completeExceptionally(new ExecutionException("exception", new Throwable()));
when(awsIotMqttClient.publish(any(), any(), anyBoolean())).thenReturn(future);
client.runSpooler();
verify(client).runSpooler();
verify(awsIotMqttClient, times(2)).publish(any(), any(), anyBoolean());
verify(spool, times(2)).getMessageById(anyLong());
verify(spool, never()).removeMessageById(anyLong());
// The 3rd call is to trigger Interrupted Exception and exit the loop
verify(spool, times(3)).popId();
verify(client, times(3)).publishSingleSpoolerMessage(awsIotMqttClient);
}
use of com.aws.greengrass.dependency.Context in project aws-greengrass-nucleus by aws-greengrass.
the class MqttClientTest method GIVEN_spool_pop_id_interrupted_WHEN_spool_message_THEN_stop_spooling_message.
@Test
void GIVEN_spool_pop_id_interrupted_WHEN_spool_message_THEN_stop_spooling_message(ExtensionContext context) throws InterruptedException {
ignoreExceptionOfType(context, InterruptedException.class);
MqttClient client = spy(new MqttClient(deviceConfiguration, spool, true, (c) -> builder, executorService));
client.setMqttOnline(true);
long id = 1L;
when(spool.popId()).thenReturn(id).thenThrow(InterruptedException.class);
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);
AwsIotMqttClient awsIotMqttClient = mock(AwsIotMqttClient.class);
when(client.getNewMqttClient()).thenReturn(awsIotMqttClient);
when(awsIotMqttClient.connect()).thenReturn(CompletableFuture.completedFuture(true));
when(client.getNewMqttClient()).thenReturn(awsIotMqttClient);
when(awsIotMqttClient.publish(any(), any(), anyBoolean())).thenReturn(CompletableFuture.completedFuture(0));
client.runSpooler();
verify(client).runSpooler();
verify(awsIotMqttClient).publish(any(), any(), anyBoolean());
verify(spool).getMessageById(anyLong());
verify(spool).removeMessageById(anyLong());
// The 3rd call is to trigger Interrupted Exception and exit the loop
verify(spool, times(2)).popId();
verify(client, times(2)).publishSingleSpoolerMessage(awsIotMqttClient);
}
Aggregations