Search in sources :

Example 6 with IotHubSendTask

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();
        }
    };
}
Also used : IotHubSendTask(com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 7 with IotHubSendTask

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();
}
Also used : IotHubSendTask(com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 8 with IotHubSendTask

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;
}
Also used : IotHubSendTask(com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask) IotHubReceiveTask(com.microsoft.azure.sdk.iot.device.transport.IotHubReceiveTask)

Example 9 with IotHubSendTask

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();
}
Also used : IotHubSendTask(com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask) IOException(java.io.IOException) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 10 with IotHubSendTask

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();
}
Also used : IotHubSendTask(com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

IotHubSendTask (com.microsoft.azure.sdk.iot.device.transport.IotHubSendTask)10 Test (org.junit.Test)8 NonStrictExpectations (mockit.NonStrictExpectations)6 Verifications (mockit.Verifications)4 IOException (java.io.IOException)3 IotHubReceiveTask (com.microsoft.azure.sdk.iot.device.transport.IotHubReceiveTask)2 Expectations (mockit.Expectations)2