use of com.aws.greengrass.config.CaseInsensitiveString in project aws-greengrass-nucleus by aws-greengrass.
the class FleetStatusServiceTest method GIVEN_MQTT_connection_interrupted_WHEN_connection_resumes_THEN_MQTT_Sent_with_periodic_triggered_fss_data.
@Test
void GIVEN_MQTT_connection_interrupted_WHEN_connection_resumes_THEN_MQTT_Sent_with_periodic_triggered_fss_data() throws InterruptedException, ServiceLoadException, IOException {
// Set up all the topics
Topics statusConfigTopics = Topics.of(context, FLEET_STATUS_CONFIG_TOPICS, null);
statusConfigTopics.createLeafChild(FLEET_STATUS_PERIODIC_PUBLISH_INTERVAL_SEC).withValue("3");
Topics allComponentToGroupsTopics = Topics.of(context, GROUP_TO_ROOT_COMPONENTS_TOPICS, null);
Topics groupsTopics = Topics.of(context, "MockService", allComponentToGroupsTopics);
Topics groupsTopics2 = Topics.of(context, "MockService2", allComponentToGroupsTopics);
Topic groupTopic1 = Topic.of(context, "arn:aws:greengrass:testRegion:12345:configuration:testGroup:12", true);
groupsTopics.children.put(new CaseInsensitiveString("MockService"), groupTopic1);
groupsTopics2.children.put(new CaseInsensitiveString("MockService2"), groupTopic1);
allComponentToGroupsTopics.children.put(new CaseInsensitiveString("MockService"), groupsTopics);
allComponentToGroupsTopics.children.put(new CaseInsensitiveString("MockService2"), groupsTopics2);
lenient().when(config.lookupTopics(COMPONENTS_TO_GROUPS_TOPICS)).thenReturn(allComponentToGroupsTopics);
// Set up all the mocks
when(mockDeploymentStatusKeeper.registerDeploymentStatusConsumer(any(), consumerArgumentCaptor.capture(), anyString())).thenReturn(true);
when(mockGreengrassService1.getName()).thenReturn("MockService");
when(mockGreengrassService1.getServiceConfig()).thenReturn(config);
when(mockGreengrassService1.getState()).thenReturn(State.RUNNING);
when(mockKernel.locate(DeploymentService.DEPLOYMENT_SERVICE_TOPICS)).thenReturn(mockDeploymentService);
when(mockKernel.locate("MockService")).thenReturn(mockGreengrassService1);
when(mockKernel.orderedDependencies()).thenReturn(Collections.singleton(mockGreengrassService1));
when(mockDeploymentService.getConfig()).thenReturn(config);
doNothing().when(context).addGlobalStateChangeListener(addGlobalStateChangeListenerArgumentCaptor.capture());
when(mockDeviceConfiguration.getStatusConfigurationTopics()).thenReturn(statusConfigTopics);
when(context.get(ScheduledExecutorService.class)).thenReturn(ses);
doNothing().when(mockMqttClient).addToCallbackEvents(mqttClientConnectionEventsArgumentCaptor.capture());
// Create the fleet status service instance
fleetStatusService = createFSS(3);
fleetStatusService.startup();
mqttClientConnectionEventsArgumentCaptor.getValue().onConnectionInterrupted(500);
TimeUnit.SECONDS.sleep(4);
mqttClientConnectionEventsArgumentCaptor.getValue().onConnectionResumed(false);
TimeUnit.SECONDS.sleep(1);
// Verify that an MQTT message with the components' status is uploaded.
verify(mockMqttClient, atLeast(1)).publish(publishRequestArgumentCaptor.capture());
PublishRequest publishRequest = publishRequestArgumentCaptor.getValue();
assertEquals(QualityOfService.AT_LEAST_ONCE, publishRequest.getQos());
assertEquals("$aws/things/testThing/greengrassv2/health/json", publishRequest.getTopic());
ObjectMapper mapper = new ObjectMapper();
FleetStatusDetails fleetStatusDetails = mapper.readValue(publishRequest.getPayload(), FleetStatusDetails.class);
assertEquals(VERSION, fleetStatusDetails.getGgcVersion());
assertEquals("testThing", fleetStatusDetails.getThing());
assertEquals(OverallStatus.HEALTHY, fleetStatusDetails.getOverallStatus());
assertEquals(1, fleetStatusDetails.getComponentStatusDetails().size());
assertEquals("MockService", fleetStatusDetails.getComponentStatusDetails().get(0).getComponentName());
assertNull(fleetStatusDetails.getComponentStatusDetails().get(0).getStatusDetails());
assertEquals(State.RUNNING, fleetStatusDetails.getComponentStatusDetails().get(0).getState());
assertEquals(Collections.singletonList("arn:aws:greengrass:testRegion:12345:configuration:testGroup:12"), fleetStatusDetails.getComponentStatusDetails().get(0).getFleetConfigArns());
}
Aggregations