Search in sources :

Example 21 with CaseInsensitiveString

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());
}
Also used : Topics(com.aws.greengrass.config.Topics) Topic(com.aws.greengrass.config.Topic) PublishRequest(com.aws.greengrass.mqttclient.PublishRequest) CaseInsensitiveString(com.aws.greengrass.config.CaseInsensitiveString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

CaseInsensitiveString (com.aws.greengrass.config.CaseInsensitiveString)21 Topics (com.aws.greengrass.config.Topics)14 Topic (com.aws.greengrass.config.Topic)13 Test (org.junit.jupiter.api.Test)12 HashMap (java.util.HashMap)8 PublishRequest (com.aws.greengrass.mqttclient.PublishRequest)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Map (java.util.Map)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Node (com.aws.greengrass.config.Node)3 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)3 HashSet (java.util.HashSet)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ServiceProviderConflictException (com.aws.greengrass.security.exceptions.ServiceProviderConflictException)2 ComponentType (com.amazon.aws.iot.greengrass.component.common.ComponentType)1 DependencyProperties (com.amazon.aws.iot.greengrass.component.common.DependencyProperties)1 DependencyType (com.amazon.aws.iot.greengrass.component.common.DependencyType)1 SerializerFactory.getRecipeSerializer (com.amazon.aws.iot.greengrass.component.common.SerializerFactory.getRecipeSerializer)1 ComponentStore (com.aws.greengrass.componentmanager.ComponentStore)1 KernelConfigResolver (com.aws.greengrass.componentmanager.KernelConfigResolver)1