use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method onLinkInitSend.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_043: [If the link is the Sender link, the event handler shall create a new Target (Proton) object using the sender endpoint address member variable.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_044: [If the link is the Sender link, the event handler shall set its target to the created Target (Proton) object.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_14_045: [If the link is the Sender link, the event handler shall set the SenderSettleMode to UNSETTLED.]
@Test
public void onLinkInitSend() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
mockEvent.getLink();
result = mockSender;
mockSender.getName();
result = "sender";
new Target();
result = mockTarget;
mockTarget.setAddress(anyString);
mockSender.setTarget(mockTarget);
mockSender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
}
};
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
connection.onLinkInit(mockEvent);
new Verifications() {
{
mockEvent.getLink();
times = 1;
mockSender.getName();
times = 1;
new Target();
times = 1;
mockTarget.setAddress(anyString);
times = 1;
mockSender.setTarget((org.apache.qpid.proton.amqp.transport.Target) any);
times = 1;
mockSender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method sendMessagesAddsSentMessagesToInProgressMap.
// Tests_SRS_AMQPSTRANSPORT_15_016: [If the sent message hash is valid, it shall be added to the in progress map.]
@Test
public void sendMessagesAddsSentMessagesToInProgressMap(@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, 2);
}
};
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(2, inProgressMessages.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.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method openFailsIfConnectionIsNotOpenedInTime.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_011: [If any exception is thrown while attempting to trigger
// the reactor, the function shall close the connection and throw an IOException.]
@Test(expected = IOException.class)
public void openFailsIfConnectionIsNotOpenedInTime() throws Exception {
baseExpectations();
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
Deencapsulation.setField(connection, "openLock", mockOpenLock);
new NonStrictExpectations() {
{
mockOpenLock.waitLock(anyLong);
result = new InterruptedException();
}
};
connection.open();
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method onDeliverySend.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_038: [If this link is the Sender link and the event type is DELIVERY, the event handler shall get the Delivery (Proton) object from the event.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_039: [The event handler shall note the remote delivery state and use it and the Delivery (Proton) hash code to inform the AmqpsIotHubConnection of the message receipt.]
@Test
public void onDeliverySend() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
mockEvent.getLink();
result = mockReceiver;
mockReceiver.getName();
result = "sender";
mockEvent.getType();
result = Event.Type.DELIVERY;
mockEvent.getDelivery();
result = mockDelivery;
mockDelivery.getRemoteState();
result = Accepted.getInstance();
mockServerListener.messageSent(anyInt, true);
}
};
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
connection.addListener(mockServerListener);
connection.onDelivery(mockEvent);
new Verifications() {
{
mockEvent.getLink();
times = 1;
mockReceiver.getName();
times = 1;
mockEvent.getType();
times = 1;
mockEvent.getDelivery();
times = 1;
mockDelivery.getRemoteState();
times = 1;
mockServerListener.messageSent(mockDelivery.hashCode(), true);
times = 1;
mockDelivery.free();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method sendMessagesSkipsMessagesWithNullBody.
// Tests_SRS_AMQPSTRANSPORT_15_015: [The function shall skip messages with null or empty body.]
@Test
public void sendMessagesSkipsMessagesWithNullBody(@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 = null;
}
};
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;
}
};
}
Aggregations