Search in sources :

Example 1 with AbstractAMQPConnection

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;
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Action(org.apache.qpid.server.util.Action) AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList)

Example 2 with AbstractAMQPConnection

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();
}
Also used : AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) NoopConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy) Matchers.anyString(org.mockito.Matchers.anyString)

Example 3 with AbstractAMQPConnection

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();
}
Also used : AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) NoopConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy) EventListener(org.apache.qpid.server.store.EventListener)

Example 4 with AbstractAMQPConnection

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();
}
Also used : AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) AbstractAMQPConnection(org.apache.qpid.server.transport.AbstractAMQPConnection) NoopConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

AbstractAMQPConnection (org.apache.qpid.server.transport.AbstractAMQPConnection)4 NoopConnectionEstablishmentPolicy (org.apache.qpid.server.virtualhost.NoopConnectionEstablishmentPolicy)3 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrayList (java.util.ArrayList)1 EventListener (org.apache.qpid.server.store.EventListener)1 Action (org.apache.qpid.server.util.Action)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1