Search in sources :

Example 26 with MqttTransport

use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method invokeCallbacksDropsFailedCallback.

// Tests_SRS_MQTTTRANSPORT_15_015: [If an exception is thrown during the callback,
// the function shall drop the callback from the queue.]
@Test
public void invokeCallbacksDropsFailedCallback(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubCallbackPacket mockCallbackPacket) throws IOException {
    final Map<String, Object> context = new HashMap<>();
    new NonStrictExpectations() {

        {
            new MqttIotHubConnection(mockConfig);
            result = mockConnection;
            mockCallbackPacket.getStatus();
            result = IotHubStatusCode.OK_EMPTY;
            mockCallbackPacket.getCallback();
            result = mockCallback;
            mockCallbackPacket.getContext();
            result = context;
            mockCallback.execute(IotHubStatusCode.OK_EMPTY, context);
            result = new IllegalStateException();
            result = null;
        }
    };
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    transport.sendMessages();
    try {
        transport.invokeCallbacks();
        throw new AssertionFailedError();
    } catch (IllegalStateException e) {
        transport.invokeCallbacks();
    }
    final IotHubEventCallback expectedCallback = mockCallback;
    final Map<String, Object> expectedContext = context;
    new VerificationsInOrder() {

        {
            expectedCallback.execute(IotHubStatusCode.OK_EMPTY, expectedContext);
        }
    };
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) HashMap(java.util.HashMap) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Aggregations

MqttTransport (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport)26 Test (org.junit.Test)26 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)12 HashMap (java.util.HashMap)12 IotHubOutboundPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket)4 Queue (java.util.Queue)3 IotHubCallbackPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket)1 Field (java.lang.reflect.Field)1 AssertionFailedError (junit.framework.AssertionFailedError)1