Search in sources :

Example 41 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 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 42 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 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 43 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 onLinkFlow.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_040: [The event handler shall save the remaining link credit.]
@Test
public void onLinkFlow() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockEvent.getLink();
            result = mockSender;
            mockSender.getCredit();
            result = 100;
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    connection.onLinkFlow(mockEvent);
    Integer expectedLinkCredit = 100;
    Integer actualLinkCredit = Deencapsulation.getField(connection, "linkCredit");
    assertEquals(expectedLinkCredit, actualLinkCredit);
    new Verifications() {

        {
            mockEvent.getLink();
            times = 1;
            mockSender.getCredit();
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) Test(org.junit.Test)

Example 44 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 closeDoesNothingIfTheConnectionWasNeverOpened.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_048 [If the AMQPS connection is already closed, the function shall do nothing.]
@Test
public void closeDoesNothingIfTheConnectionWasNeverOpened() throws InterruptedException, IOException {
    baseExpectations();
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "closeLock", mockCloseLock);
    new NonStrictExpectations() {

        {
            mockCloseLock.waitLock(anyLong);
        }
    };
    connection.close();
    new Verifications() {

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

Example 45 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 onConnectionBoundWebSockets.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_030: [The event handler shall get the Transport (Proton) object from the event.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_031: [The event handler shall set the SASL_PLAIN authentication on the transport using the given user name and sas token.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_032: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_25_049: [The event handler shall set the SSL Context to IOTHub SSL context containing valid certificates.]
@Test
public void onConnectionBoundWebSockets() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockEvent.getConnection();
            result = mockConnection;
            mockConnection.getTransport();
            result = mockTransportInternal;
            new WebSocketImpl();
            result = mockWebSocket;
            mockWebSocket.configure(anyString, anyString, anyInt, anyString, (Map<String, String>) any, (WebSocketHandler) any);
            mockTransportInternal.addTransportLayer(mockWebSocket);
            mockTransportInternal.sasl();
            result = mockSasl;
            mockSasl.plain(anyString, anyString);
            mockSslDomain.setSslContext(mockIotHubSSLContext.getIotHubSSlContext());
            mockSslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
            mockTransportInternal.ssl(mockSslDomain);
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "useWebSockets", true);
    connection.onConnectionBound(mockEvent);
    new Verifications() {

        {
            mockEvent.getConnection();
            times = 1;
            mockConnection.getTransport();
            times = 1;
            mockWebSocket.configure(hostName + ":" + amqpPort, "/$iothub/websocket", 0, "AMQPWSB10", null, null);
            times = 1;
            mockTransportInternal.addTransportLayer(mockWebSocket);
            times = 1;
            mockTransportInternal.sasl();
            times = 1;
            mockSasl.plain(deviceId + "@sas." + hubName, anyString);
            times = 1;
            mockSslDomain.setSslContext(mockIotHubSSLContext.getIotHubSSlContext());
            times = 1;
            mockSslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
            times = 1;
            mockTransportInternal.ssl(mockSslDomain);
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) 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