use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method isEmptyReturnsFalseIfCallbackListIsNotEmpty.
// 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 isEmptyReturnsFalseIfCallbackListIsNotEmpty() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
Queue<IotHubCallbackPacket> callbackList = new LinkedList<>();
callbackList.add(mockIotHubCallbackPacket);
Deencapsulation.setField(transport, "callbackList", callbackList);
Boolean isEmpty = transport.isEmpty();
Assert.assertFalse(isEmpty);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method messageSentBuffersPreviouslySentMessageIfNotSuccessfullyDelivered.
// Tests_SRS_AMQPSTRANSPORT_15_031: [If the message was not delivered successfully, it is buffered to be sent again.]
@Test
public void messageSentBuffersPreviouslySentMessageIfNotSuccessfullyDelivered() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
inProgressMessages.put(1, new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
inProgressMessages.put(2, new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
transport.messageSent(1, false);
new Verifications() {
{
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, (IotHubEventCallback) any, any);
times = 0;
}
};
Queue<IotHubOutboundPacket> waitingMessages = Deencapsulation.getField(transport, "waitingMessages");
Queue<IotHubCallbackPacket> callbackList = Deencapsulation.getField(transport, "callbackList");
Assert.assertTrue(inProgressMessages.size() == 1);
Assert.assertTrue(waitingMessages.size() == 1);
Assert.assertTrue(callbackList.size() == 0);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method addMessageFailsIfTransportNotOpened.
// Tests_SRS_AMQPSTRANSPORT_15_010: [If the AMQPS session is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void addMessageFailsIfTransportNotOpened(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback) throws IOException {
final Map<String, Object> context = new HashMap<>();
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.addMessage(mockMsg, mockCallback, context);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method isEmptyReturnsFalseIfInProgressMapIsNotEmpty.
// 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 isEmptyReturnsFalseIfInProgressMapIsNotEmpty() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
inProgressMessages.put(1, new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
Boolean isEmpty = transport.isEmpty();
Assert.assertFalse(isEmpty);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method sendMessagesAddsExpiredMessagesToCallbackListWithCorrectCode.
// Tests_SRS_AMQPSTRANSPORT_15_039: [If the message is expired, the function shall create a callback
// with the MESSAGE_EXPIRED status and add it to the callback list.]
@Test
public void sendMessagesAddsExpiredMessagesToCallbackListWithCorrectCode(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket) throws IOException {
final Map<String, Object> context = new HashMap<>();
final byte[] messageBytes = new byte[] { 1, 2 };
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
new IotHubOutboundPacket(mockMsg, mockCallback, context);
result = mockPacket;
mockPacket.getMessage();
result = mockMsg;
mockMsg.getBytes();
result = messageBytes;
mockMsg.isExpired();
returns(true, false);
mockConnection.sendMessage((org.apache.qpid.proton.message.Message) any);
result = 1;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.addMessage(mockMsg, mockCallback, context);
transport.addMessage(mockMsg, mockCallback, context);
transport.sendMessages();
Map<Integer, IotHubOutboundPacket> inProgressMessages = Deencapsulation.getField(transport, "inProgressMessages");
Assert.assertEquals(1, inProgressMessages.size());
Queue<IotHubOutboundPacket> waitingMessages = Deencapsulation.getField(transport, "waitingMessages");
Assert.assertEquals(0, waitingMessages.size());
Queue<IotHubCallbackPacket> callbackList = Deencapsulation.getField(transport, "callbackList");
Assert.assertEquals(1, callbackList.size());
new Verifications() {
{
new IotHubOutboundPacket(mockMsg, mockCallback, context);
times = 2;
mockPacket.getMessage();
times = 2;
mockConnection.sendMessage((org.apache.qpid.proton.message.Message) any);
times = 1;
new IotHubCallbackPacket(IotHubStatusCode.MESSAGE_EXPIRED, (IotHubEventCallback) any, any);
times = 1;
}
};
}
Aggregations