diff --git a/servicetests/tests/JobsExecution/main.cpp b/servicetests/tests/JobsExecution/main.cpp index 8333f22e8..c98807cd7 100644 --- a/servicetests/tests/JobsExecution/main.cpp +++ b/servicetests/tests/JobsExecution/main.cpp @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) { fprintf(stdout, "starting the jobs execution programm\n"); - std::this_thread::sleep_for(std::chrono::seconds(10)); + //std::this_thread::sleep_for(std::chrono::seconds(10)); /************************ Setup ****************************/ // Do the global initialization for the API @@ -79,6 +79,7 @@ int main(int argc, char *argv[]) } // Create Mqtt5Client std::shared_ptr client5; + IotJobsClient *jobsClient; if (cmdData.input_mqtt_version == 5UL) { // Create the MQTT5 builder and populate it with data from cmdData. @@ -122,6 +123,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "MQTT5 Connection failed to start"); exit(-1); } + jobsClient = new IotJobsClient(client5); } else if (cmdData.input_mqtt_version == 3UL) { @@ -188,6 +190,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "MQTT Connection failed with error %s\n", ErrorDebugString(connection->LastError())); exit(-1); } + jobsClient = new IotJobsClient(connection); } else { @@ -198,12 +201,10 @@ int main(int argc, char *argv[]) delete builder; /************************ Run the sample ****************************/ - if (connectionCompletedPromise.get_future().get()) { - IotJobsClient jobsClient(connection); - getAvailableJobs(cmdData.input_thingName, jobsClient); + getAvailableJobs(cmdData.input_thingName, *jobsClient); for (auto jobid : availableJobs) { DescribeJobExecutionSubscriptionRequest describeJobExecutionSubscriptionRequest; @@ -235,7 +236,7 @@ int main(int argc, char *argv[]) } }; - jobsClient.SubscribeToDescribeJobExecutionAccepted( + jobsClient->SubscribeToDescribeJobExecutionAccepted( describeJobExecutionSubscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, subscriptionHandler, @@ -261,7 +262,7 @@ int main(int argc, char *argv[]) } }; - jobsClient.SubscribeToDescribeJobExecutionRejected( + jobsClient->SubscribeToDescribeJobExecutionRejected( describeJobExecutionSubscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler); subAckedPromise.get_future().wait(); @@ -281,7 +282,7 @@ int main(int argc, char *argv[]) publishDescribeJobExeCompletedPromise.set_value(); }; - jobsClient.PublishDescribeJobExecution( + jobsClient->PublishDescribeJobExecution( std::move(describeJobExecutionRequest), AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler); publishDescribeJobExeCompletedPromise.get_future().wait(); @@ -312,7 +313,7 @@ int main(int argc, char *argv[]) StartNextPendingJobExecutionSubscriptionRequest subscriptionRequest; subscriptionRequest.ThingName = cmdData.input_thingName; subAckedPromise = std::promise(); - jobsClient.SubscribeToStartNextPendingJobExecutionAccepted( + jobsClient->SubscribeToStartNextPendingJobExecutionAccepted( subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, OnSubscribeToStartNextPendingJobExecutionAcceptedResponse, @@ -321,7 +322,7 @@ int main(int argc, char *argv[]) subAckedPromise.get_future().wait(); subAckedPromise = std::promise(); - jobsClient.SubscribeToStartNextPendingJobExecutionRejected( + jobsClient->SubscribeToStartNextPendingJobExecutionRejected( subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler); subAckedPromise.get_future().wait(); @@ -331,7 +332,7 @@ int main(int argc, char *argv[]) publishRequest.StepTimeoutInMinutes = 15L; publishDescribeJobExeCompletedPromise = std::promise(); - jobsClient.PublishStartNextPendingJobExecution( + jobsClient->PublishStartNextPendingJobExecution( publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler); pendingExecutionPromise.get_future().wait(); @@ -355,7 +356,7 @@ int main(int argc, char *argv[]) subscriptionRequest.JobId = currentJobId; subAckedPromise = std::promise(); - jobsClient.SubscribeToUpdateJobExecutionAccepted( + jobsClient->SubscribeToUpdateJobExecutionAccepted( subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, OnSubscribeToUpdateJobExecutionAcceptedResponse, @@ -363,7 +364,7 @@ int main(int argc, char *argv[]) subAckedPromise.get_future().wait(); subAckedPromise = std::promise(); - jobsClient.SubscribeToUpdateJobExecutionRejected( + jobsClient->SubscribeToUpdateJobExecutionRejected( subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler); subAckedPromise.get_future().wait(); @@ -374,7 +375,7 @@ int main(int argc, char *argv[]) publishRequest.ExecutionNumber = currentExecutionNumber; publishRequest.Status = JobStatus::IN_PROGRESS; publishRequest.ExpectedVersion = currentVersionNumber++; - jobsClient.PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler); + jobsClient->PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler); pendingExecutionPromise.get_future().wait(); } @@ -399,12 +400,12 @@ int main(int argc, char *argv[]) pendingExecutionPromise.set_value(); }; subAckedPromise = std::promise(); - jobsClient.SubscribeToUpdateJobExecutionAccepted( + jobsClient->SubscribeToUpdateJobExecutionAccepted( subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, subscribeHandler, subAckHandler); subAckedPromise.get_future().wait(); subAckedPromise = std::promise(); - jobsClient.SubscribeToUpdateJobExecutionRejected( + jobsClient->SubscribeToUpdateJobExecutionRejected( subscriptionRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, failureHandler, subAckHandler); subAckedPromise.get_future().wait(); @@ -416,7 +417,7 @@ int main(int argc, char *argv[]) publishRequest.ExpectedVersion = currentVersionNumber++; publishDescribeJobExeCompletedPromise = std::promise(); - jobsClient.PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler); + jobsClient->PublishUpdateJobExecution(publishRequest, AWS_MQTT_QOS_AT_LEAST_ONCE, publishHandler); pendingExecutionPromise.get_future().wait(); } @@ -462,15 +463,23 @@ void getAvailableJobs(Aws::Crt::String thingName, IotJobsClient &jobsClient) { fprintf(stderr, "Error %d occurred\n", ioErr); } - for (JobExecutionSummary job : response->InProgressJobs.value()) - { - availableJobs.push_back(job.JobId.value()); - fprintf(stderr, "In Progress jobs %s\n", job.JobId->c_str()); - } - for (JobExecutionSummary job : response->QueuedJobs.value()) - { - availableJobs.push_back(job.JobId.value()); - fprintf(stderr, "Queued jobs %s\n", job.JobId->c_str()); + if (response) { + if (response->InProgressJobs.has_value()) + { + for (JobExecutionSummary job : response->InProgressJobs.value()) + { + availableJobs.push_back(job.JobId.value()); + fprintf(stderr, "In Progress jobs %s\n", job.JobId->c_str()); + } + } + if (response->QueuedJobs.has_value()) + { + for (JobExecutionSummary job : response->QueuedJobs.value()) + { + availableJobs.push_back(job.JobId.value()); + fprintf(stderr, "Queued jobs %s\n", job.JobId->c_str()); + } + } } getResponse.set_value(); };