use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method invokeCallbacksInvokesAllCallbacksFromQueue.
// Tests_SRS_AMQPSTRANSPORT_15_020: [The function shall invoke all the callbacks from the callback queue.]
@Test
public void invokeCallbacksInvokesAllCallbacksFromQueue() throws IOException {
final Integer context = 24;
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
mockIotHubCallbackPacket.getCallback();
result = mockIotHubEventCallback;
mockIotHubCallbackPacket.getStatus();
result = IotHubStatusCode.OK_EMPTY;
mockIotHubCallbackPacket.getContext();
result = context;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Queue<IotHubCallbackPacket> callbackList = new LinkedList<>();
callbackList.add(mockIotHubCallbackPacket);
callbackList.add(mockIotHubCallbackPacket);
Deencapsulation.setField(transport, "callbackList", callbackList);
transport.invokeCallbacks();
new Verifications() {
{
mockIotHubCallbackPacket.getStatus();
times = 2;
mockIotHubCallbackPacket.getCallback();
times = 2;
mockIotHubCallbackPacket.getCallback();
times = 2;
mockIotHubEventCallback.execute(IotHubStatusCode.OK_EMPTY, context);
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 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.AmqpsTransport 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.amqps.AmqpsTransport 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.AmqpsTransport 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;
}
};
}
Aggregations