use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method sendMessagesAddsNotSentMessagesToInProgressMap.
// Tests_SRS_AMQPSTRANSPORT_15_017: [If the sent message hash is not valid, it shall be buffered to be sent in a subsequent attempt.]
@Test
public void sendMessagesAddsNotSentMessagesToInProgressMap(@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;
mockConnection.sendMessage((org.apache.qpid.proton.message.Message) any);
returns(1, -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(1, waitingMessages.size());
new Verifications() {
{
new IotHubOutboundPacket(mockMsg, mockCallback, context);
times = 2;
mockPacket.getMessage();
times = 2;
mockConnection.sendMessage((org.apache.qpid.proton.message.Message) any);
times = 2;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method invokeCallbacksFailsIfTransportNotOpen.
// Tests_SRS_AMQPSTRANSPORT_15_019: [If the transport closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void invokeCallbacksFailsIfTransportNotOpen() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.invokeCallbacks();
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method openDoesNothingIfAlreadyOpened.
// Tests_SRS_AMQPSTRANSPORT_15_003: [If an AMQPS connection is already open, the function shall do nothing.]
@Test
public void openDoesNothingIfAlreadyOpened() throws IOException, InterruptedException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.open();
final AmqpsIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.open();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method sendMessagesSkipsMessagesWithEmptyBody.
// Tests_SRS_AMQPSTRANSPORT_15_015: [The function shall skip messages with null or empty body.]
@Test
public void sendMessagesSkipsMessagesWithEmptyBody(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket) throws IOException {
final Map<String, Object> context = new HashMap<>();
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
new IotHubOutboundPacket(mockMsg, mockCallback, context);
result = mockPacket;
mockPacket.getMessage();
result = mockMsg;
mockMsg.getBytes();
result = new byte[0];
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.addMessage(mockMsg, mockCallback, context);
transport.addMessage(mockMsg, mockCallback, context);
transport.sendMessages();
new Verifications() {
{
mockConnection.sendMessage((org.apache.qpid.proton.message.Message) any);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method sendMessagesFailsIfTransportNeverOpened.
// Tests_SRS_AMQPSTRANSPORT_15_012: [If the AMQPS session is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void sendMessagesFailsIfTransportNeverOpened() throws IOException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.sendMessages();
}
Aggregations