use of com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask in project azure-iot-sdk-java by Azure.
the class IotHubSendTaskTest method runInvokesAllCallbacks.
// Tests_SRS_IOTHUBSENDTASK_11_003: [The function shall invoke all callbacks on the transport's callback queue.]
@Test
public void runInvokesAllCallbacks() throws IOException, URISyntaxException {
IotHubSendTask sendTask = new IotHubSendTask(mockTransport);
sendTask.run();
new Verifications() {
{
mockTransport.invokeCallbacks();
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask in project azure-iot-sdk-java by Azure.
the class IotHubSendTaskTest method runDoesNotCrashFromThrowable.
// Tests_SRS_IOTHUBSENDTASK_11_008: [The function shall not crash because of any error or exception thrown by the transport.]
@Test
public void runDoesNotCrashFromThrowable() throws IOException, URISyntaxException {
new NonStrictExpectations() {
{
mockTransport.sendMessages();
result = new Throwable("Test that send does not crash.");
}
};
IotHubSendTask sendTask = new IotHubSendTask(mockTransport);
sendTask.run();
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask in project azure-iot-sdk-java by Azure.
the class DeviceIO method startWorkerThreads.
/**
* Handles logic common to all open functions.
*/
private void startWorkerThreads() {
// while startWorkerThreads should never be called when threads are already active, it doesn't hurt to double
// check that any previous thread pools have been shut down.
stopWorkerThreads();
log.info("Starting worker threads");
this.sendTask = new IotHubSendTask(this.transport);
this.receiveTask = new IotHubReceiveTask(this.transport);
this.sendTaskScheduler = Executors.newScheduledThreadPool(1);
this.receiveTaskScheduler = Executors.newScheduledThreadPool(1);
// Note that even though these threads are scheduled at a fixed interval, the sender/receiver threads will wait
// if no messages are available to process. These waiting threads will still count against the pool size defined above,
// so threads will not be needlessly scheduled during times when this SDK has no messages to process.
// the scheduler waits until each execution is finished before
// scheduling the next one, so executions of a given task
// will never overlap.
// Note that this is scheduleWithFixedDelay, not scheduleAtFixedRate. There is no reason to spawn a new
// send/receive thread until after the previous one has finished.
this.sendTaskScheduler.scheduleWithFixedDelay(this.sendTask, 0, sendPeriodInMilliseconds, TimeUnit.MILLISECONDS);
this.receiveTaskScheduler.scheduleWithFixedDelay(this.receiveTask, 0, receivePeriodInMilliseconds, TimeUnit.MILLISECONDS);
this.state = IotHubConnectionStatus.CONNECTED;
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask in project azure-iot-sdk-java by Azure.
the class IotHubSendTaskTest method runDoesNotCrashFromIoException.
// Tests_SRS_IOTHUBSENDTASK_11_005: [The function shall not crash because of an IOException thrown by the transport.]
@Test
public void runDoesNotCrashFromIoException() throws DeviceClientException {
new NonStrictExpectations() {
{
mockTransport.sendMessages();
result = new IOException();
}
};
IotHubSendTask sendTask = new IotHubSendTask(mockTransport);
sendTask.run();
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask in project azure-iot-sdk-java by Azure.
the class IotHubSendTaskTest method runDoesNotCrashFromThrowable.
// Tests_SRS_IOTHUBSENDTASK_11_008: [The function shall not crash because of any error or exception thrown by the transport.]
@Test
public void runDoesNotCrashFromThrowable() throws DeviceClientException {
new NonStrictExpectations() {
{
mockTransport.sendMessages();
result = new Throwable("Test that send does not crash.");
}
};
IotHubSendTask sendTask = new IotHubSendTask(mockTransport);
sendTask.run();
}
Aggregations