use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method messageSentReturnsIfThereAreNoMessagesInProgress.
// Tests_SRS_AMQPSTRANSPORT_15_029: [If the hash cannot be found in the list of keys for the messages in progress, the method returns.]
@Test
public void messageSentReturnsIfThereAreNoMessagesInProgress() throws IOException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
Map<Integer, IotHubOutboundPacket> inProgressMessages = new ConcurrentHashMap<>();
Deencapsulation.setField(transport, "inProgressMessages", inProgressMessages);
transport.messageSent(1, true);
new Verifications() {
{
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, (IotHubEventCallback) any, any);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method openOpensAmqpsConnection.
// Tests_SRS_AMQPSTRANSPORT_15_004: [The function shall open an AMQPS connection with the IoT Hub given in the configuration.]
@Test
public void openOpensAmqpsConnection() throws IOException, InterruptedException {
new NonStrictExpectations() {
{
new AmqpsIotHubConnection(mockConfig, false);
result = mockConnection;
}
};
AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
transport.open();
final AmqpsIotHubConnection expectedConnection = mockConnection;
new Verifications() {
{
expectedConnection.open();
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsTransportTest method messageSentBuffersPreviouslySentMessageIfNotSuccessfullyDelivered.
// Tests_SRS_AMQPSTRANSPORT_15_031: [If the message was not delivered successfully, it is buffered to be sent again.]
@Test
public void messageSentBuffersPreviouslySentMessageIfNotSuccessfullyDelivered() 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);
transport.messageSent(1, false);
new Verifications() {
{
new IotHubCallbackPacket(IotHubStatusCode.OK_EMPTY, (IotHubEventCallback) any, any);
times = 0;
}
};
Queue<IotHubOutboundPacket> waitingMessages = Deencapsulation.getField(transport, "waitingMessages");
Queue<IotHubCallbackPacket> callbackList = Deencapsulation.getField(transport, "callbackList");
Assert.assertTrue(inProgressMessages.size() == 1);
Assert.assertTrue(waitingMessages.size() == 1);
Assert.assertTrue(callbackList.size() == 0);
}
use of com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection in project azure-iot-sdk-java by Azure.
the class AmqpsIotHubConnectionTest method onLinkInitReceive.
// Tests_SRS_AMQPSIOTHUBCONNECTION_14_046: [If the link is the Receiver link, the event handler shall create a new Source (Proton) object using the receiver endpoint address member variable.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_14_047: [If the link is the Receiver link, the event handler shall set its source to the created Source (Proton) object.]
@Test
public void onLinkInitReceive() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
mockEvent.getLink();
result = mockReceiver;
mockReceiver.getName();
result = "receiver";
new Source();
result = mockSource;
mockSource.setAddress(anyString);
mockReceiver.setSource(mockSource);
}
};
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
connection.onLinkInit(mockEvent);
new Verifications() {
{
mockEvent.getLink();
times = 1;
mockReceiver.getName();
times = 1;
new Source();
times = 1;
mockSource.setAddress(anyString);
times = 1;
mockReceiver.setSource((org.apache.qpid.proton.amqp.transport.Source) any);
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 onLinkRemoteClose.
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_042 [The event handler shall attempt to reconnect to the IoTHub.]
@Test
public void onLinkRemoteClose() throws IOException {
baseExpectations();
new NonStrictExpectations() {
{
mockEvent.getLink();
result = mockSender;
mockSender.getName();
result = "sender";
mockServerListener.connectionLost();
}
};
final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
final Boolean[] openAsyncCalled = { false };
final Boolean[] closeAsyncCalled = { false };
new MockUp<AmqpsIotHubConnection>() {
@Mock
void openAsync() {
openAsyncCalled[0] = true;
Deencapsulation.setField(connection, "state", State.OPEN);
}
@Mock
void closeAsync() {
closeAsyncCalled[0] = true;
Deencapsulation.setField(connection, "state", State.CLOSED);
}
};
connection.addListener(mockServerListener);
connection.onLinkRemoteClose(mockEvent);
assertEquals(true, closeAsyncCalled[0]);
assertEquals(false, openAsyncCalled[0]);
new Verifications() {
{
mockEvent.getLink();
times = 1;
mockSender.getName();
times = 1;
mockServerListener.connectionLost();
times = 1;
}
};
}
Aggregations