Search in sources :

Example 21 with IotHubOutboundPacket

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

the class MqttTransportTest method addMessageAddsToTransportQueue.

// Tests_SRS_MQTTTRANSPORT_15_001: [The constructor shall initialize an empty transport queue
// for adding messages to be sent as a batch.]
// Tests_SRS_MQTTTRANSPORT_15_007: [The function shall add a packet containing the message,
// callback, and callback context to the transport queue.]
@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<>();
    MqttTransport transport = new MqttTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    new VerificationsInOrder() {

        {
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            mockQueue.add(mockPacket);
        }
    };
}
Also used : HashMap(java.util.HashMap) 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 22 with IotHubOutboundPacket

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

the class HttpsTransportTest method addMessageAddsToTransportQueue.

// Tests_SRS_HTTPSTRANSPORT_11_003: [The function shall add a packet containing the message, callback, and callback context to the transport queue.]
@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<>();
    HttpsTransport transport = new HttpsTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    new VerificationsInOrder() {

        {
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            mockQueue.add(mockPacket);
        }
    };
}
Also used : HashMap(java.util.HashMap) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Queue(java.util.Queue) Test(org.junit.Test)

Example 23 with IotHubOutboundPacket

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

the class HttpsTransportTest method addMessageWithResponseAddsToTransportQueue.

// Tests_SRS_HTTPSTRANSPORT_21_017: [The function shall add a packet containing the message, callback, and callback context to the transport queue.]
@Test
public <T extends Queue> void addMessageWithResponseAddsToTransportQueue(@Mocked final Message mockMsg, @Mocked final IotHubResponseCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket) throws IOException {
    final Queue mockQueue = new MockUp<T>() {
    }.getMockInstance();
    final Map<String, Object> context = new HashMap<>();
    HttpsTransport transport = new HttpsTransport(mockConfig);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    new VerificationsInOrder() {

        {
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            mockQueue.add(mockPacket);
        }
    };
}
Also used : HashMap(java.util.HashMap) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Queue(java.util.Queue) Test(org.junit.Test)

Example 24 with IotHubOutboundPacket

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

the class MqttTransportTest method closeClosesMqttsConnectionAndRemovePendingMessages.

// Tests_SRS_MQTTTRANSPORT_15_005: [The function shall close the MQTT connection with the IoT Hub given in the configuration.]
// Tests_SRS_MQTTTRANSPORT_99_020: [The method shall remove all the messages which are in progress or waiting to be sent and add them to the callback list.]
// Tests_SRS_MQTTTRANSPORT_99_021: [The method shall invoke the callback list]
@Test
public void closeClosesMqttsConnectionAndRemovePendingMessages(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockedPacket) throws IOException, InterruptedException {
    final MqttTransport transport = new MqttTransport(mockConfig);
    final MqttIotHubConnection expectedConnection = mockConnection;
    new NonStrictExpectations() {

        {
            mockedPacket.getMessage();
            result = mockMsg;
            mockMsg.getBytes();
            result = "AnyData".getBytes();
        }
    };
    transport.open();
    transport.addMessage(mockMsg, mockCallback, null);
    transport.close();
    Queue<IotHubOutboundPacket> actualWaitingMessages = Deencapsulation.getField(transport, "waitingList");
    assertEquals(actualWaitingMessages.size(), 0);
    new Verifications() {

        {
            mockCallback.execute((IotHubStatusCode) any, any);
            times = 1;
            expectedConnection.close();
            minTimes = 1;
        }
    };
}
Also used : 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) Test(org.junit.Test)

Example 25 with IotHubOutboundPacket

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

the class AmqpsTransportTest method closeClosesAmqpsConnectionAndRemovePendingMessages.

// Tests_SRS_AMQPSTRANSPORT_15_008: [The function shall close an AMQPS connection with the IoT Hub given in the configuration.]
// Tests_SRS_AMQPSTRANSPORT_99_036: [The method shall remove all the messages which are in progress or waiting to be sent and add them to the callback list.]
// Tests_SRS_AMQPSTRANSPORT_99_037: [The method shall invoke all the callbacks.]
@Test
public void closeClosesAmqpsConnectionAndRemovePendingMessages(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockedPacket) throws IOException, InterruptedException {
    final AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    final AmqpsIotHubConnection expectedConnection = mockConnection;
    new NonStrictExpectations() {

        {
            mockedPacket.getMessage();
            result = mockMsg;
            mockMsg.getBytes();
            result = "AnyData".getBytes();
        }
    };
    transport.open();
    transport.addMessage(mockMsg, mockCallback, null);
    transport.close();
    Queue<IotHubOutboundPacket> actualWaitingMessages = Deencapsulation.getField(transport, "waitingMessages");
    Map<Integer, IotHubOutboundPacket> actualInProgressMessages = Deencapsulation.getField(transport, "inProgressMessages");
    assertEquals(actualWaitingMessages.size(), 0);
    assertEquals(actualInProgressMessages.size(), 0);
    new Verifications() {

        {
            mockCallback.execute((IotHubStatusCode) any, any);
            times = 1;
            expectedConnection.close();
            minTimes = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) 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