use of com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket in project azure-iot-sdk-java by Azure.
the class MqttTransport method invokeCallbacks.
/**
* Invokes the callbacks for all completed requests.
*
* @throws IllegalStateException if the transport has not been opened or is closed.
*/
public void invokeCallbacks() throws IllegalStateException {
synchronized (sendMessagesLock) {
// the function shall throw an IllegalStateException.]
if (this.state == State.CLOSED) {
throw new IllegalStateException("MQTT transport is closed.");
}
// Codes_SRS_MQTTTRANSPORT_15_013: [The function shall invoke all callbacks on the callback queue.]
while (!this.callbackList.isEmpty()) {
// Codes_SRS_MQTTTRANSPORT_15_015: [If an exception is thrown during the callback,
// the function shall drop the callback from the queue.]
IotHubCallbackPacket packet = this.callbackList.remove();
IotHubStatusCode status = packet.getStatus();
IotHubEventCallback callback = packet.getCallback();
Object context = packet.getContext();
callback.execute(status, context);
}
}
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket in project azure-iot-sdk-java by Azure.
the class IotHubCallbackPacketTest method getResponseCallbackReturnsNull.
// Tests_SRS_IOTHUBCALLBACKPACKET_11_001: [The constructor shall save the status, eventCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_21_007: [The constructor shall set message and responseCallback as null.]
@Test
public void getResponseCallbackReturnsNull() {
final IotHubStatusCode status = IotHubStatusCode.HUB_OR_DEVICE_ID_NOT_FOUND;
final Map<String, Object> context = new HashMap<>();
IotHubCallbackPacket packet = new IotHubCallbackPacket(status, mockEventCallback, context);
IotHubResponseCallback testCallback = packet.getResponseCallback();
ResponseMessage testMessage = packet.getResponseMessage();
assertNull(testCallback);
assertNull(testMessage);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket in project azure-iot-sdk-java by Azure.
the class IotHubCallbackPacketTest method getStatusReturnsStatus.
// Tests_SRS_IOTHUBCALLBACKPACKET_11_001: [The constructor shall save the status, eventCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_11_002: [The function shall return the status given in the constructor.]
@Test
public void getStatusReturnsStatus() {
final IotHubStatusCode status = IotHubStatusCode.BAD_FORMAT;
final Map<String, Object> context = new HashMap<>();
IotHubCallbackPacket packet = new IotHubCallbackPacket(status, mockEventCallback, context);
IotHubStatusCode testStatus = packet.getStatus();
final IotHubStatusCode expectedStatus = status;
assertThat(testStatus, is(expectedStatus));
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket in project azure-iot-sdk-java by Azure.
the class IotHubCallbackPacketTest method getResponseCallbackReturnsCallback.
// Tests_SRS_IOTHUBCALLBACKPACKET_21_006: [The constructor shall save the responseMessage, responseCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_21_005: [The getResponseCallback shall return the responseCallback given in the constructor.]
@Test
public void getResponseCallbackReturnsCallback() {
// arrange
final Map<String, Object> context = new HashMap<>();
// act
IotHubCallbackPacket packet = new IotHubCallbackPacket(mockMessage, mockResponseCallback, context);
// assert
IotHubResponseCallback testCallback = packet.getResponseCallback();
assertThat(testCallback, is(mockResponseCallback));
ResponseMessage testMessage = packet.getResponseMessage();
assertThat(testMessage, is(mockMessage));
Map<String, Object> testContext = (Map<String, Object>) packet.getContext();
Set<Map.Entry<String, Object>> testEntrySet = testContext.entrySet();
final Set<Map.Entry<String, Object>> expectedEntrySet = context.entrySet();
assertThat(testEntrySet, everyItem(isIn(expectedEntrySet)));
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket in project azure-iot-sdk-java by Azure.
the class IotHubCallbackPacketTest method getEventCallbackReturnsCallback.
// Tests_SRS_IOTHUBCALLBACKPACKET_11_001: [The constructor shall save the status, eventCallback, and callback context.]
// Tests_SRS_IOTHUBCALLBACKPACKET_11_003: [The function shall return the eventCallback given in the constructor.]
@Test
public void getEventCallbackReturnsCallback() {
final IotHubStatusCode status = IotHubStatusCode.HUB_OR_DEVICE_ID_NOT_FOUND;
final Map<String, Object> context = new HashMap<>();
IotHubCallbackPacket packet = new IotHubCallbackPacket(status, mockEventCallback, context);
IotHubEventCallback testCallback = packet.getCallback();
assertThat(testCallback, is(mockEventCallback));
}
Aggregations