Search in sources :

Example 16 with IotHubOutboundPacket

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

Example 17 with IotHubOutboundPacket

use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket 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 18 with IotHubOutboundPacket

use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.

the class AmqpsTransportTest method isEmptyReturnsFalseIfWaitingListIsNotEmpty.

// 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 isEmptyReturnsFalseIfWaitingListIsNotEmpty() throws IOException {
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    Queue<IotHubOutboundPacket> waitingMessages = new LinkedBlockingDeque<>();
    waitingMessages.add(new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
    Deencapsulation.setField(transport, "waitingMessages", waitingMessages);
    Boolean isEmpty = transport.isEmpty();
    Assert.assertFalse(isEmpty);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) 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) Test(org.junit.Test)

Example 19 with IotHubOutboundPacket

use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method sendMessagesAddsToCallbackQueue.

// Tests_SRS_MQTTTRANSPORT_15_010: [For each message being sent, the function shall send the message
// and add the IoT Hub status code along with the callback and context to the callback list.]
@Test
public <T extends Queue> void sendMessagesAddsToCallbackQueue(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket, @Mocked final IotHubCallbackPacket mockCallbackPacket) throws IOException {
    final Queue mockQueue = new MockUp<T>() {
    }.getMockInstance();
    final Map<String, Object> context = new HashMap<>();
    new NonStrictExpectations() {

        {
            new MqttIotHubConnection(mockConfig);
            result = mockConnection;
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            result = mockPacket;
            mockPacket.getCallback();
            result = mockCallback;
            mockPacket.getContext();
            result = context;
            mockConnection.sendEvent((Message) any);
            returns(IotHubStatusCode.OK_EMPTY, IotHubStatusCode.ERROR);
            new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, mockCallback, context);
            result = mockCallbackPacket;
            new IotHubCallbackPacket(IotHubStatusCode.ERROR, mockCallback, context);
            result = mockCallbackPacket;
        }
    };
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    transport.addMessage(mockMsg, mockCallback, context);
    transport.sendMessages();
    new VerificationsInOrder() {

        {
            new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, mockCallback, context);
            mockQueue.add(mockCallbackPacket);
            new IotHubCallbackPacket(IotHubStatusCode.ERROR, mockCallback, context);
            mockQueue.add(mockCallbackPacket);
        }
    };
}
Also used : HashMap(java.util.HashMap) IotHubCallbackPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket) MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Queue(java.util.Queue) Test(org.junit.Test)

Example 20 with IotHubOutboundPacket

use of com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket in project azure-iot-sdk-java by Azure.

the class MqttTransportTest method sendMessagesSendsAllMessages.

// Tests_SRS_MQTTTRANSPORT_15_009: [The function shall attempt to send every message
// on its waiting list, one at a time.]
@Test
public void sendMessagesSendsAllMessages(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket, @Mocked final MqttIotHubConnection mockConnection) throws IOException {
    final Map<String, Object> context = new HashMap<>();
    new NonStrictExpectations() {

        {
            new MqttIotHubConnection(mockConfig);
            result = mockConnection;
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            result = mockPacket;
            mockPacket.getMessage();
            result = mockMsg;
        }
    };
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    transport.addMessage(mockMsg, mockCallback, context);
    transport.sendMessages();
    final MqttIotHubConnection expectedConnection = mockConnection;
    new Verifications() {

        {
            expectedConnection.sendEvent(mockMsg);
            times = 2;
        }
    };
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) HashMap(java.util.HashMap) MqttTransport(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Test(org.junit.Test)

Aggregations

IotHubOutboundPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket)37 Test (org.junit.Test)25 HashMap (java.util.HashMap)17 AmqpsTransport (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport)15 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)14 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)12 IotHubCallbackPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket)10 AmqpsMessage (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage)5 Queue (java.util.Queue)5 MqttTransport (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttTransport)4 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)3 IotHubEventCallback (com.microsoft.azure.sdk.iot.device.IotHubEventCallback)2 IotHubResponseCallback (com.microsoft.azure.sdk.iot.device.IotHubResponseCallback)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)2 Message (com.microsoft.azure.sdk.iot.device.Message)1 Map (java.util.Map)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 SizeLimitExceededException (javax.naming.SizeLimitExceededException)1 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)1