Search in sources :

Example 31 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 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)

Example 32 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 constructorSavesInputParameters.

// Tests_SRS_AMQPSTRANSPORT_15_001: [The constructor shall save the input parameters into instance variables.]
@Test
public void constructorSavesInputParameters() {
    DeviceClientConfig expectedClientConfig = mockConfig;
    Boolean expectedUseWebSockets = false;
    AmqpsTransport transport = new AmqpsTransport(expectedClientConfig, expectedUseWebSockets);
    DeviceClientConfig actualClientConfig = Deencapsulation.getField(transport, "config");
    Boolean actualUseWebSockets = Deencapsulation.getField(transport, "useWebSockets");
    assertEquals(expectedClientConfig, actualClientConfig);
    assertEquals(expectedUseWebSockets, actualUseWebSockets);
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) Test(org.junit.Test)

Example 33 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 closeDoesNothingIfConnectionAlreadyClosed.

// Tests_SRS_AMQPSTRANSPORT_15_007: [If the AMQPS connection is closed, the function shall do nothing.]
@Test
public void closeDoesNothingIfConnectionAlreadyClosed() throws IOException, InterruptedException {
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    transport.close();
    transport.close();
    final AmqpsIotHubConnection expectedConnection = mockConnection;
    new Verifications() {

        {
            expectedConnection.close();
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) Test(org.junit.Test)

Example 34 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 connectionLostClearsAllInProgressMessagesAndAddsThemToTheWaitingList.

// Tests_SRS_AMQPSTRANSPORT_15_032: [The messages in progress are buffered to be sent again.]
// Tests_SRS_AMQPSTRANSPORT_15_033: [The map of messages in progress is cleared.]
@Test
public void connectionLostClearsAllInProgressMessagesAndAddsThemToTheWaitingList() throws IOException {
    new NonStrictExpectations() {

        {
            new AmqpsIotHubConnection(mockConfig, false);
            result = mockConnection;
        }
    };
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
    inProgressMessages.put(1, new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
    inProgressMessages.put(2, new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
    Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
    Queue<IotHubOutboundPacket> waitingMessages = new LinkedBlockingDeque<>();
    waitingMessages.add(new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
    waitingMessages.add(new IotHubOutboundPacket(new Message(), mockIotHubEventCallback, new Object()));
    Deencapsulation.setField(transport, "waitingMessages", waitingMessages);
    transport.connectionLost();
    Assert.assertTrue(inProgressMessages.size() == 0);
    Assert.assertTrue(waitingMessages.size() == 4);
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) 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) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Example 35 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 addMessageFailsIfTransportAlreadyClosed.

// Tests_SRS_AMQPSTRANSPORT_15_010: [If the AMQPS session is closed, the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void addMessageFailsIfTransportAlreadyClosed(@Mocked final Message mockMsg, @Mocked final IotHubEventCallback mockCallback) throws IOException {
    final Map<String, Object> context = new HashMap<>();
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    transport.close();
    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