Search in sources :

Example 36 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 sendMessageAcknowledgesProperlyBasedOnMessageResult.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_023: [If the message result is COMPLETE, ABANDON, or REJECT,
// the function shall acknowledge the last message with acknowledgement type COMPLETE, ABANDON, or REJECT respectively.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_024: [The function shall return true after the message was acknowledged.]
@Test
public void sendMessageAcknowledgesProperlyBasedOnMessageResult() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockAmqpsMessage.acknowledge(AmqpsMessage.ACK_TYPE.COMPLETE);
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "state", State.OPEN);
    for (final AmqpsMessage.ACK_TYPE ackType : AmqpsMessage.ACK_TYPE.values()) {
        Boolean expectedResult = true;
        Boolean actualResult = connection.sendMessageResult(mockAmqpsMessage, IotHubMessageResult.valueOf(ackType.toString()));
        assertEquals(expectedResult, actualResult);
        new Verifications() {

            {
                mockAmqpsMessage.acknowledge(ackType);
                times = 1;
            }
        };
    }
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsMessage(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage) Test(org.junit.Test)

Example 37 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 onReactorInit.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_033: [The event handler shall set the current handler to handle the connection events.]
@Test
public void onReactorInit() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockEvent.getReactor();
            result = mockReactor;
            mockReactor.connectionToHost(anyString, anyInt, (Handler) any);
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    connection.onReactorInit(mockEvent);
    new Verifications() {

        {
            mockEvent.getReactor();
            times = 1;
            mockReactor.connectionToHost(anyString, anyInt, (Handler) connection);
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) Test(org.junit.Test)

Example 38 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 sendMessageDoesNothingIfNotEnoughLinkCredit.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_015: [If the state of the connection is CLOSED or there is not enough
// credit, the function shall return -1.]
@Test
public void sendMessageDoesNothingIfNotEnoughLinkCredit() throws IOException {
    baseExpectations();
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "state", State.OPEN);
    Deencapsulation.setField(connection, "linkCredit", -1);
    Integer expectedDeliveryHash = -1;
    Integer actualDeliveryHash = connection.sendMessage(Message.Factory.create());
    assertEquals(expectedDeliveryHash, actualDeliveryHash);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) Test(org.junit.Test)

Example 39 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 closeClosesAllProtonVariablesAndStopsProtonReactor.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_012: [The function shall set the status of the AMQPS connection to CLOSED.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_013: [The function shall close the AMQPS sender and receiver links,
// the AMQPS session and the AMQPS connection.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_014: [The function shall stop the Proton reactor.]
@Test
public void closeClosesAllProtonVariablesAndStopsProtonReactor() throws IOException, InterruptedException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockReactorFuture.cancel(true);
            mockExecutorService.shutdown();
        }
    };
    new MockUp<AmqpsIotHubConnection>() {

        @Mock
        void open() {
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "state", State.OPEN);
    Deencapsulation.setField(connection, "sender", mockSender);
    Deencapsulation.setField(connection, "receiver", mockReceiver);
    Deencapsulation.setField(connection, "session", mockSession);
    Deencapsulation.setField(connection, "connection", mockConnection);
    Deencapsulation.setField(connection, "executorService", mockExecutorService);
    connection.close();
    State actualState = Deencapsulation.getField(connection, "state");
    assertEquals(State.CLOSED, actualState);
    new Verifications() {

        {
            mockSender.close();
            times = 1;
            mockReceiver.close();
            times = 1;
            mockSession.close();
            times = 1;
            mockConnection.close();
            times = 1;
            mockExecutorService.shutdown();
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) State(com.microsoft.azure.sdk.iot.device.transport.State) Test(org.junit.Test)

Example 40 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 openSetsStateToOpenIfSuccessful.

// Tests_SRS_AMQPSTRANSPORT_15_006: [If the connection was opened successfully, the transport state shall be set to OPEN.]
@Test
public void openSetsStateToOpenIfSuccessful() throws IOException {
    new NonStrictExpectations() {

        {
            new AmqpsIotHubConnection(mockConfig, false);
            result = mockConnection;
        }
    };
    final AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    State state = Deencapsulation.getField(transport, "state");
    assertEquals(State.OPEN, state);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) State(com.microsoft.azure.sdk.iot.device.transport.State) 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