use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method addMessageAddsToTransportQueue.
// Tests_SRS_AMQPSTRANSPORT_15_011: [The function shall add a packet containing the message, callback,
// and callback context to the queue of messages waiting to be sent.]
@Test
public <T extends Queue> void addMessageAddsToTransportQueue(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket) throws IOException {
final Queue mockQueue = new MockUp<T>() {
}.getMockInstance();
final Map<String, Object> context = new HashMap<>();
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.addMessage(mockMsg, mockCallback, context);
new VerificationsInOrder() {
{
new IotHubOutboundPacket(mockMsg, mockCallback, context);
mockQueue.add(mockPacket);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method messageSentReturnsIfThereAreNoMessagesInProgress.
// Tests_SRS_AMQPSTRANSPORT_15_029: [If the hash cannot be found in the list of keys for the messages in progress, the method returns.]
@Test
public void messageSentReturnsIfThereAreNoMessagesInProgress() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
transport.messageSent(1, true);
new Verifications() {
{
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, (IotHubEventCallback) any, any);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method isEmptyReturnsFalseIfWaitingListIsNotEmpty.
// Tests_SRS_AMQPSTRANSPORT_15_035: [The function shall return true if the waiting list,
// in progress list and callback list are all empty, and false otherwise.]
@Test
public void isEmptyReturnsFalseIfWaitingListIsNotEmpty() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
Queue<IotHubOutboundPacket> waitingMessages = new LinkedBlockingDeque<>();
waitingMessages.add(new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
Deencapsulation.setField(transport, "waitingMessages", waitingMessages);
Boolean isEmpty = transport.isEmpty();
Assert.assertFalse(isEmpty);
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method sendMessagesAddsToCallbackQueue.
// Tests_SRS_MQTTTRANSPORT_15_010: [For each message being sent, the function shall send the message
// and add the IoT Hub status code along with the callback and context to the callback list.]
@Test
public <T extends Queue> void sendMessagesAddsToCallbackQueue(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket, @Mocked final IotHubCallbackPacket mockCallbackPacket) throws IOException {
final Queue mockQueue = new MockUp<T>() {
}.getMockInstance();
final Map<String, Object> context = new HashMap<>();
new NonStrictExpectations() {
{
new MqttIotHubConnection(mockConfig);
result = mockConnection;
new IotHubOutboundPacket(mockMsg, mockCallback, context);
result = mockPacket;
mockPacket.getCallback();
result = mockCallback;
mockPacket.getContext();
result = context;
mockConnection.sendEvent((Message) any);
returns(IotHubStatusCode.OK_EMPTY, IotHubStatusCode.ERROR);
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, mockCallback, context);
result = mockCallbackPacket;
new IotHubCallbackPacket(IotHubStatusCode.ERROR, mockCallback, context);
result = mockCallbackPacket;
}
};
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.addMessage(mockMsg, mockCallback, context);
transport.addMessage(mockMsg, mockCallback, context);
transport.sendMessages();
new VerificationsInOrder() {
{
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, mockCallback, context);
mockQueue.add(mockCallbackPacket);
new IotHubCallbackPacket(IotHubStatusCode.ERROR, mockCallback, context);
mockQueue.add(mockCallbackPacket);
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.
the class MqttTransportTest method sendMessagesSendsAllMessages.
// Tests_SRS_MQTTTRANSPORT_15_009: [The function shall attempt to send every message
// on its waiting list, one at a time.]
@Test
public void sendMessagesSendsAllMessages(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket, @Mocked final MqttIotHubConnection mockConnection) throws IOException {
final Map<String, Object> context = new HashMap<>();
new NonStrictExpectations() {
{
new MqttIotHubConnection(mockConfig);
result = mockConnection;
new IotHubOutboundPacket(mockMsg, mockCallback, context);
result = mockPacket;
mockPacket.getMessage();
result = mockMsg;
}
};
MqttTransport transport = new MqttTransport(mockConfig);
transport.open();
transport.addMessage(mockMsg, mockCallback, context);
transport.addMessage(mockMsg, mockCallback, context);
transport.sendMessages();
final MqttIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.sendEvent(mockMsg);
times = 2;
}
};
}
Aggregations