use of com.aws.greengrass.lifecyclemanager.GreengrassService.RUNTIME_STORE_NAMESPACE_TOPIC in project aws-greengrass-nucleus by aws-greengrass.
the class MqttReconnectTest method GIVEN_new_deployment_while_device_online_WHEN_mqtt_disconnects_and_reconnects_THEN_job_executes_successfully.
// GG_NEEDS_REVIEW: TODO: Fix flaky test https://sim.amazon.com/issues/P40525318
@Disabled
@Timeout(value = 10, unit = TimeUnit.MINUTES)
@Test
void GIVEN_new_deployment_while_device_online_WHEN_mqtt_disconnects_and_reconnects_THEN_job_executes_successfully(ExtensionContext context) throws Exception {
ignoreExceptionUltimateCauseOfType(context, MqttException.class);
ignoreExceptionUltimateCauseOfType(context, TimeoutException.class);
ignoreExceptionWithMessage(context, "No valid versions were found for this package based on provided requirement");
CountDownLatch jobInProgress = new CountDownLatch(1);
CountDownLatch jobCompleted = new CountDownLatch(1);
CountDownLatch connectionInterrupted = new CountDownLatch(1);
// Create Job
CreateDeploymentRequest createDeploymentRequest = CreateDeploymentRequest.builder().components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build())).build();
CreateDeploymentResponse result = draftAndCreateDeployment(createDeploymentRequest);
String jobId = result.iotJobId();
// Subscribe to persisted deployment status
Topics deploymentServiceTopics = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS);
Topics processedDeployments = deploymentServiceTopics.lookupTopics(RUNTIME_STORE_NAMESPACE_TOPIC, PROCESSED_DEPLOYMENTS_TOPICS);
processedDeployments.subscribe((whatHappened, newValue) -> {
if (!(newValue instanceof Topic)) {
return;
}
if (newValue.childOf(DEPLOYMENT_STATUS_KEY_NAME)) {
newValue = newValue.parent;
} else {
return;
}
Map<String, Object> deploymentDetails = ((Topics) newValue).toPOJO();
if (!deploymentDetails.get(DEPLOYMENT_ID_KEY_NAME).toString().equals(jobId)) {
return;
}
String status = deploymentDetails.get(DEPLOYMENT_STATUS_KEY_NAME).toString();
if (JobStatus.IN_PROGRESS.toString().equals(status)) {
jobInProgress.countDown();
} else if (jobInProgress.getCount() <= 0 && JobStatus.SUCCEEDED.toString().equals(status)) {
jobCompleted.countDown();
}
});
kernel.launch();
assertTrue(jobInProgress.await(2, TimeUnit.MINUTES));
NetworkUtils networkUtils = NetworkUtils.getByPlatform();
Consumer<GreengrassLogMessage> logListener = m -> {
String message = m.getMessage();
if (UPDATE_DEPLOYMENT_STATUS_MQTT_ERROR_LOG.equals(message) && m.getCause().getCause() instanceof MqttException || UPDATE_DEPLOYMENT_STATUS_TIMEOUT_ERROR_LOG.equals(message)) {
connectionInterrupted.countDown();
}
};
try {
Slf4jLogAdapter.addGlobalListener(logListener);
networkUtils.disconnectMqtt();
// Wait for the deployment to finish offline
assertTrue(jobCompleted.await(5, TimeUnit.MINUTES));
assertTrue(connectionInterrupted.await(2, TimeUnit.MINUTES));
} finally {
networkUtils.recoverMqtt();
Slf4jLogAdapter.removeGlobalListener(logListener);
}
// Wait for DNS Cache to expire
Thread.sleep(DNS_CACHE_TTL.plus(Duration.ofSeconds(1)).toMillis());
// Wait for the IoT job to be updated and marked as successful
// The reason for making the timeout as 7 min is because it has been observed that if the update job status was
// invoked just before the connection recovers it can block the call for total timeout of 5 mins,
// without successfully updating the status of the job in cloud. After this timeout expires the status will
// be updated again as part of the onConnectionResumed callback. Additional 2 mins are for this status
// to get updated
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, jobId, thingInfo.getThingName(), Duration.ofMinutes(7), s -> s.equals(JobExecutionStatus.SUCCEEDED));
}
Aggregations