Search in sources :

Example 1 with JobsResponseParser

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!");
}
Also used : JobStatus(com.microsoft.azure.sdk.iot.service.jobs.JobStatus) DeviceTestManager(tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) JobsResponseParser(com.microsoft.azure.sdk.iot.deps.serializer.JobsResponseParser) Before(org.junit.Before)

Aggregations

JobsResponseParser (com.microsoft.azure.sdk.iot.deps.serializer.JobsResponseParser)1 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)1 SqlQuery (com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery)1 JobStatus (com.microsoft.azure.sdk.iot.service.jobs.JobStatus)1 Before (org.junit.Before)1 DeviceTestManager (tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager)1