Search in sources :

Example 1 with AmqpsTransport

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);
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with AmqpsTransport

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);
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 3 with AmqpsTransport

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);
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with AmqpsTransport

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);
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 5 with AmqpsTransport

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;
        }
    };
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Test(org.junit.Test)

Aggregations

AmqpsTransport (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport)42 Test (org.junit.Test)42 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)25 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)16 IotHubOutboundPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket)15 HashMap (java.util.HashMap)11 AmqpsMessage (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage)10 IotHubCallbackPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 State (com.microsoft.azure.sdk.iot.device.transport.State)3 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)3 LinkedList (java.util.LinkedList)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 Queue (java.util.Queue)1 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)1