use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method messageSentRemovesSuccessfullyDeliveredMessageFromInProgressMap.
// Tests_SRS_AMQPSTRANSPORT_15_030: [If the message was successfully delivered,
// its callback is added to the list of callbacks to be executed.]
@Test
public void messageSentRemovesSuccessfullyDeliveredMessageFromInProgressMap() 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, true);
new Verifications() {
{
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, (IotHubEventCallback) any, any);
times = 1;
}
};
Queue<IotHubOutboundPacket> waitingMessages = Deencapsulation.getField(transport, "waitingMessages");
Queue<IotHubCallbackPacket> callbackList = Deencapsulation.getField(transport, "callbackList");
Assert.assertTrue(inProgressMessages.size() == 1);
Assert.assertTrue(waitingMessages.size() == 0);
Assert.assertTrue(callbackList.size() == 1);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method closeClosesAmqpsConnection.
// Tests_SRS_AMQPSTRANSPORT_15_008: [The function shall close an AMQPS connection with the IoT Hub given in the configuration.]
@Test
public void closeClosesAmqpsConnection() throws IOException, InterruptedException {
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.close();
final AmqpsIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.close();
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method handleMessageReturnsIfConfigIsNull.
// Tests_SRS_AMQPSTRANSPORT_15_024: [If no message was received from IotHub, the function shall return.]
@Test
public void handleMessageReturnsIfConfigIsNull() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
mockConfig.getMessageCallback();
result = mockMessageCallback;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
transport.handleMessage();
Queue<AmqpsMessage> receivedMessages = Deencapsulation.getField(transport, "receivedMessages");
Assert.assertEquals(0, receivedMessages.size());
new Verifications() {
{
mockMessageCallback.execute((Message) any, any);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method handleMessagePutsMessageBackIntoQueueIfCannotSendResultBackToServer.
// Tests_SRS_AMQPSTRANSPORT_15_028: [If the result could not be sent to IoTHub, the message shall be put back in the received messages queue to be processed again.]
// Tests_SRS_AMQPSTRANSPORT_15_028: [If the result could not be sent to IoTHub, the message shall be put back in the received messages queue to be processed again.]
@Test
public void handleMessagePutsMessageBackIntoQueueIfCannotSendResultBackToServer() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
mockConfig.getMessageCallback();
result = mockMessageCallback;
mockMessageCallback.execute((Message) any, any);
result = IotHubMessageResult.COMPLETE;
mockConnection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.COMPLETE);
result = false;
}
};
new MockUp<AmqpsTransport>() {
@Mock
Message protonMessageToIoTHubMessage(MessageImpl protonMessage) {
return new Message();
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Queue<AmqpsMessage> receivedMessages = new LinkedBlockingQueue<>();
receivedMessages.add(mockAmqpsMessage);
receivedMessages.add(mockAmqpsMessage);
Deencapsulation.setField(transport, "receivedMessages", receivedMessages);
transport.handleMessage();
Queue<AmqpsMessage> receivedTransportMessages = Deencapsulation.getField(transport, "receivedMessages");
Assert.assertTrue(receivedTransportMessages.size() == 2);
new Verifications() {
{
mockMessageCallback.execute((Message) any, any);
times = 1;
mockConnection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.COMPLETE);
times = 1;
}
};
Assert.assertTrue(receivedTransportMessages.size() == 2);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method handleMessageClearsReceivedMessagesListIfNoCallbackIsDefined.
// Tests_SRS_AMQPSTRANSPORT_15_025: [If no callback is defined, the list of received messages is cleared.]
@Test
public void handleMessageClearsReceivedMessagesListIfNoCallbackIsDefined() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
mockConfig.getMessageCallback();
result = null;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Queue<AmqpsMessage> receivedMessages = new LinkedBlockingQueue<>();
receivedMessages.add(mockAmqpsMessage);
receivedMessages.add(mockAmqpsMessage);
Deencapsulation.setField(transport, "receivedMessages", receivedMessages);
transport.handleMessage();
Queue<AmqpsMessage> receivedTransportMessages = Deencapsulation.getField(transport, "receivedMessages");
Assert.assertTrue(receivedTransportMessages.size() == 0);
}
Aggregations