Search in sources :

Example 46 with AmqpsIotHubConnection

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

the class AmqpsIotHubConnectionTest method onLinkInitSend.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_043: [If the link is the Sender link, the event handler shall create a new Target (Proton) object using the sender endpoint address member variable.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_044: [If the link is the Sender link, the event handler shall set its target to the created Target (Proton) object.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_14_045: [If the link is the Sender link, the event handler shall set the SenderSettleMode to UNSETTLED.]
@Test
public void onLinkInitSend() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockEvent.getLink();
            result = mockSender;
            mockSender.getName();
            result = "sender";
            new Target();
            result = mockTarget;
            mockTarget.setAddress(anyString);
            mockSender.setTarget(mockTarget);
            mockSender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    connection.onLinkInit(mockEvent);
    new Verifications() {

        {
            mockEvent.getLink();
            times = 1;
            mockSender.getName();
            times = 1;
            new Target();
            times = 1;
            mockTarget.setAddress(anyString);
            times = 1;
            mockSender.setTarget((org.apache.qpid.proton.amqp.transport.Target) any);
            times = 1;
            mockSender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) Target(org.apache.qpid.proton.amqp.messaging.Target) Test(org.junit.Test)

Example 47 with AmqpsIotHubConnection

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

the class AmqpsTransportTest method sendMessagesAddsSentMessagesToInProgressMap.

// Tests_SRS_AMQPSTRANSPORT_15_016: [If the sent message hash is valid, it shall be added to the in progress map.]
@Test
public void sendMessagesAddsSentMessagesToInProgressMap(@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;
            mockConnection.sendMessage((org.apache.qpid.proton.message.Message) any);
            returns(1, 2);
        }
    };
    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(2, inProgressMessages.size());
    new Verifications() {

        {
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            times = 2;
            mockPacket.getMessage();
            times = 2;
            mockConnection.sendMessage((org.apache.qpid.proton.message.Message) any);
            times = 2;
        }
    };
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Test(org.junit.Test)

Example 48 with AmqpsIotHubConnection

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

the class AmqpsIotHubConnectionTest method openFailsIfConnectionIsNotOpenedInTime.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_011: [If any exception is thrown while attempting to trigger
// the reactor, the function shall close the connection and throw an IOException.]
@Test(expected = IOException.class)
public void openFailsIfConnectionIsNotOpenedInTime() throws Exception {
    baseExpectations();
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "openLock", mockOpenLock);
    new NonStrictExpectations() {

        {
            mockOpenLock.waitLock(anyLong);
            result = new InterruptedException();
        }
    };
    connection.open();
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) Test(org.junit.Test)

Example 49 with AmqpsIotHubConnection

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

the class AmqpsIotHubConnectionTest method onDeliverySend.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_038: [If this link is the Sender link and the event type is DELIVERY, the event handler shall get the Delivery (Proton) object from the event.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_039: [The event handler shall note the remote delivery state and use it and the Delivery (Proton) hash code to inform the AmqpsIotHubConnection of the message receipt.]
@Test
public void onDeliverySend() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockEvent.getLink();
            result = mockReceiver;
            mockReceiver.getName();
            result = "sender";
            mockEvent.getType();
            result = Event.Type.DELIVERY;
            mockEvent.getDelivery();
            result = mockDelivery;
            mockDelivery.getRemoteState();
            result = Accepted.getInstance();
            mockServerListener.messageSent(anyInt, true);
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    connection.addListener(mockServerListener);
    connection.onDelivery(mockEvent);
    new Verifications() {

        {
            mockEvent.getLink();
            times = 1;
            mockReceiver.getName();
            times = 1;
            mockEvent.getType();
            times = 1;
            mockEvent.getDelivery();
            times = 1;
            mockDelivery.getRemoteState();
            times = 1;
            mockServerListener.messageSent(mockDelivery.hashCode(), true);
            times = 1;
            mockDelivery.free();
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) Test(org.junit.Test)

Example 50 with AmqpsIotHubConnection

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

the class AmqpsTransportTest method sendMessagesSkipsMessagesWithNullBody.

// Tests_SRS_AMQPSTRANSPORT_15_015: [The function shall skip messages with null or empty body.]
@Test
public void sendMessagesSkipsMessagesWithNullBody(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback, @Mocked final IotHubOutboundPacket mockPacket) throws IOException {
    final Map<String, Object> context = new HashMap<>();
    new NonStrictExpectations() {

        {
            new AmqpsIotHubConnection(mockConfig, false);
            result = mockConnection;
            new IotHubOutboundPacket(mockMsg, mockCallback, context);
            result = mockPacket;
            mockPacket.getMessage();
            result = null;
        }
    };
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    transport.addMessage(mockMsg, mockCallback, context);
    transport.addMessage(mockMsg, mockCallback, context);
    transport.sendMessages();
    new Verifications() {

        {
            mockConnection.sendMessage((org.apache.qpid.proton.message.Message) 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) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IotHubOutboundPacket(com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket) Test(org.junit.Test)

Aggregations

AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)52 Test (org.junit.Test)52 AmqpsTransport (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport)25 IotHubOutboundPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket)12 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)11 AmqpsMessage (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage)10 HashMap (java.util.HashMap)7 IotHubCallbackPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubCallbackPacket)5 State (com.microsoft.azure.sdk.iot.device.transport.State)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)3 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)3 WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)1 DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)1 IotHubReactor (com.microsoft.azure.sdk.iot.device.transport.amqps.IotHubReactor)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 Symbol (org.apache.qpid.proton.amqp.Symbol)1 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)1