use of org.apache.qpid.server.transport.AbstractAMQPConnection in project qpid-broker-j by apache.
the class VirtualHostTest method createMockProtocolConnection.
private AbstractAMQPConnection createMockProtocolConnection(final VirtualHost<?> virtualHost) {
final AbstractAMQPConnection connection = mock(AbstractAMQPConnection.class);
final List<Action<?>> tasks = new ArrayList<>();
final ArgumentCaptor<Action> deleteTaskCaptor = ArgumentCaptor.forClass(Action.class);
Answer answer = new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) {
return tasks.add(deleteTaskCaptor.getValue());
}
};
doAnswer(answer).when(connection).addDeleteTask(deleteTaskCaptor.capture());
when(connection.getAddressSpace()).thenReturn(virtualHost);
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocation) {
for (Action action : tasks) {
action.performAction(connection);
}
return null;
}
}).when(connection).sendConnectionCloseAsync(any(AMQPConnection.CloseReason.class), anyString());
when(connection.getRemoteAddressString()).thenReturn("peer:1234");
return connection;
}
use of org.apache.qpid.server.transport.AbstractAMQPConnection in project qpid-broker-j by apache.
the class VirtualHostTest method testStopVirtualHost_ClosesConnections.
public void testStopVirtualHost_ClosesConnections() {
String virtualHostName = getName();
QueueManagingVirtualHost<?> virtualHost = createVirtualHost(virtualHostName);
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
AbstractAMQPConnection connection = createMockProtocolConnection(virtualHost);
assertEquals("Unexpected number of connections before connection registered", 0, virtualHost.getConnectionCount());
AMQPConnection modelConnection = mock(AMQPConnection.class);
when(modelConnection.closeAsync()).thenReturn(Futures.immediateFuture(null));
virtualHost.registerConnection(modelConnection, new NoopConnectionEstablishmentPolicy());
assertEquals("Unexpected number of connections after connection registered", 1, virtualHost.getConnectionCount());
((AbstractConfiguredObject<?>) virtualHost).stop();
assertEquals("Unexpected state", State.STOPPED, virtualHost.getState());
assertEquals("Unexpected number of connections after virtualhost stopped", 0, virtualHost.getConnectionCount());
verify(modelConnection).closeAsync();
}
use of org.apache.qpid.server.transport.AbstractAMQPConnection in project qpid-broker-j by apache.
the class VirtualHostTest method testExistingConnectionBlocking.
public void testExistingConnectionBlocking() {
VirtualHost<?> host = createVirtualHost(getTestName());
AbstractAMQPConnection connection = mock(AbstractAMQPConnection.class);
host.registerConnection(connection, new NoopConnectionEstablishmentPolicy());
((EventListener) host).event(Event.PERSISTENT_MESSAGE_SIZE_OVERFULL);
verify(connection).block();
}
use of org.apache.qpid.server.transport.AbstractAMQPConnection in project qpid-broker-j by apache.
the class VirtualHostTest method testDeleteVirtualHost_ClosesConnections.
public void testDeleteVirtualHost_ClosesConnections() {
String virtualHostName = getName();
QueueManagingVirtualHost<?> virtualHost = createVirtualHost(virtualHostName);
assertEquals("Unexpected state", State.ACTIVE, virtualHost.getState());
AbstractAMQPConnection connection = createMockProtocolConnection(virtualHost);
assertEquals("Unexpected number of connections before connection registered", 0, virtualHost.getConnectionCount());
AMQPConnection modelConnection = mock(AMQPConnection.class);
when(modelConnection.closeAsync()).thenReturn(Futures.immediateFuture(null));
virtualHost.registerConnection(modelConnection, new NoopConnectionEstablishmentPolicy());
assertEquals("Unexpected number of connections after connection registered", 1, virtualHost.getConnectionCount());
virtualHost.delete();
assertEquals("Unexpected state", State.DELETED, virtualHost.getState());
assertEquals("Unexpected number of connections after virtualhost deleted", 0, virtualHost.getConnectionCount());
verify(modelConnection).closeAsync();
}
Aggregations