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);
}
};
}
Aggregations