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;
}
};
}
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);
}
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;
}
};
}
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;
}
};
}
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;
}
};
}
Aggregations