Search in sources :

Example 16 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 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);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) Test(org.junit.Test)

Example 17 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 handleMessageFailsIfTransportNeverOpened.

// Tests_SRS_AMQPSTRANSPORT_15_021: [If the transport is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void handleMessageFailsIfTransportNeverOpened() throws IOException {
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.handleMessage();
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) Test(org.junit.Test)

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

Example 19 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 messageSentReturnsIfThereAreNoMessagesInProgress.

// Tests_SRS_AMQPSTRANSPORT_15_029: [If the hash cannot be found in the list of keys for the messages in progress, the method returns.]
@Test
public void messageSentReturnsIfThereAreNoMessagesInProgress() throws IOException {
    new NonStrictExpectations() {

        {
            new AmqpsIotHubConnection(mockConfig, false);
            result = mockConnection;
        }
    };
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
    Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
    transport.messageSent(1, true);
    new Verifications() {

        {
            new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, (IotHubEventCallback) any, any);
            times = 0;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 20 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 addMessageWithResponseNotSupportedThrows.

// Tests_SRS_AMQPSTRANSPORT_21_040: [The function shall throws `UnsupportedOperationException`.]
@Test(expected = UnsupportedOperationException.class)
public void addMessageWithResponseNotSupportedThrows(@Mocked final Message mockMsg, @Mocked final IotHubResponseCallback mockCallback) throws IOException {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    // act
    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)

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