use of com.microsoft.azure.sdk.iot.deps.serializer.JobsResponseParser in project azure-iot-sdk-java by Azure.
the class JobClientTests method cleanToStart.
@Before
public void cleanToStart() throws IOException, IotHubException {
for (DeviceTestManager device : devices) {
device.clearStatistics();
}
log.info("Waiting for all previously scheduled jobs to finish...");
long startTime = System.currentTimeMillis();
Query activeJobsQuery = jobClient.queryDeviceJob("SELECT * FROM devices.jobs");
while (activeJobsQuery.hasNext()) {
JobsResponseParser job = JobsResponseParser.createFromJson(activeJobsQuery.next().toString());
JobStatus jobStatus = jobClient.getJob(job.getJobId()).getJobStatus();
while (jobStatus.equals(JobStatus.enqueued) || jobStatus.equals(JobStatus.queued) || jobStatus.equals(JobStatus.running) || jobStatus.equals(JobStatus.scheduled)) {
try {
Thread.sleep(500);
jobStatus = jobClient.getJob(job.getJobId()).getJobStatus();
} catch (InterruptedException e) {
fail("Unexpected interrupted exception occurred");
}
if (System.currentTimeMillis() - startTime > MAX_TIME_WAIT_FOR_PREVIOUSLY_SCHEDULED_JOBS_TO_FINISH_IN_MILLIS) {
fail("Waited too long for previously scheduled jobs to finish");
}
}
}
log.info("Done waiting for jobs to finish!");
}
Aggregations