use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method scheduleUpdateTwinThrowOnJobClientFail.
/* Tests_SRS_JOB_21_011: [If the Iothub reported fail as result of the scheduleUpdateTwin, the scheduleUpdateTwin shall throws IotHubException.] */
@Test(expected = IotHubException.class)
public void scheduleUpdateTwinThrowOnJobClientFail() throws IOException, IotHubException {
// arrange
final String queryCondition = "validQueryCondition";
final DeviceTwinDevice deviceTwin = mockedDeviceTwinDevice;
final Date now = new Date();
final long maxExecutionTimeInSeconds = 100;
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.scheduleUpdateTwin((String) any, queryCondition, deviceTwin, now, maxExecutionTimeInSeconds);
result = mockedJobResult;
mockedJobResult.getJobStatus();
result = JobStatus.failed;
times = 1;
}
};
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
Deencapsulation.invoke(job, "scheduleUpdateTwin", new Class[] { String.class, DeviceTwinDevice.class, Date.class, Long.class }, queryCondition, deviceTwin, now, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method scheduleDeviceMethodInvokeJobClient.
/* Tests_SRS_JOB_21_015: [The scheduleDeviceMethod shall invoke the scheduleDeviceMethod in the JobClient class with the received parameters.] */
@Test
public void scheduleDeviceMethodInvokeJobClient() throws IOException, IotHubException {
// arrange
final String queryCondition = "validQueryCondition";
final String methodName = "validMethodName";
final String payload = "validPayload";
final Date now = new Date();
final long maxExecutionTimeInSeconds = 100;
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.scheduleDeviceMethod((String) any, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
result = mockedJobResult;
times = 1;
mockedJobResult.getJobStatus();
result = JobStatus.enqueued;
}
};
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
Deencapsulation.invoke(job, "scheduleDeviceMethod", new Class[] { String.class, String.class, Long.class, Long.class, Object.class, Date.class, Long.class }, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method cancelThrowOnInvokeJobClient.
/* Tests_SRS_JOB_21_021: [If cancelJob failed, the cancel shall throws IOException. Threw by the cancelJob.] */
@Test(expected = IOException.class)
public void cancelThrowOnInvokeJobClient() throws IOException, IotHubException {
// arrange
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.cancelJob((String) any);
result = new IOException();
times = 1;
}
};
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
job.cancel();
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class JobTest method getThrowOnInvokeJobClient.
/* Tests_SRS_JOB_21_019: [If getJob failed, the get shall throws IOException. Threw by the getJob.] */
@Test(expected = IOException.class)
public void getThrowOnInvokeJobClient() throws IOException, IotHubException {
// arrange
final String connectionString = "validConnectionString";
// assert
new NonStrictExpectations() {
{
JobClient.createFromConnectionString(connectionString);
result = mockedJobClient;
mockedJobClient.getJob((String) any);
result = new IOException();
times = 1;
}
};
Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
// act
job.get();
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.
the class DeviceMethodSample method scheduleInvokeMethod.
private static void scheduleInvokeMethod(DeviceMethod methodClient) throws IotHubException, IOException, InterruptedException {
// query condition that defines the list of device to invoke
String queryCondition = "DeviceId IN ['" + deviceId + "']";
// date when the invoke shall be executed
// 10 seconds in the future.
Date invokeDateInFuture = new Date(new Date().getTime() + ADD_10_SECONDS_IN_MILLISECONDS);
System.out.println("Schedule invoke method on the Device in 10 seconds");
Job job = methodClient.scheduleDeviceMethod(queryCondition, methodName, responseTimeout, connectTimeout, payload, invokeDateInFuture, MAX_EXECUTION_TIME_IN_SECONDS);
System.out.println("Wait for job completed...");
JobResult jobResult = job.get();
while (jobResult.getJobStatus() != JobStatus.completed) {
Thread.sleep(GIVE_100_MILLISECONDS_TO_IOTHUB);
jobResult = job.get();
}
System.out.println("job completed");
}
Aggregations