Search in sources :

Example 1 with Close

use of org.apache.qpid.server.protocol.v1_0.type.transport.Close in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _networkConnection = mock(ServerNetworkConnection.class);
    when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
    _broker = mock(Broker.class);
    when(_broker.getModel()).thenReturn(BrokerModel.getInstance());
    when(_broker.getNetworkBufferSize()).thenReturn(256 * 1026);
    final TaskExecutor taskExecutor = new TaskExecutorImpl();
    taskExecutor.start();
    when(_broker.getChildExecutor()).thenReturn(taskExecutor);
    when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(_broker.getId()).thenReturn(UUID.randomUUID());
    when(_broker.getEventLogger()).thenReturn(new EventLogger());
    when(((Broker) _broker).getCategoryClass()).thenReturn(Broker.class);
    _port = mock(AmqpPort.class);
    when(_port.getChildExecutor()).thenReturn(taskExecutor);
    when(_port.getCategoryClass()).thenReturn(Port.class);
    when(_port.getModel()).thenReturn(BrokerModel.getInstance());
    final SubjectCreator subjectCreator = mock(SubjectCreator.class);
    _authenticationProvider = mock(AuthenticationProvider.class);
    when(_port.getAuthenticationProvider()).thenReturn(_authenticationProvider);
    _virtualHost = mock(VirtualHost.class);
    when(_virtualHost.getChildExecutor()).thenReturn(taskExecutor);
    when(_virtualHost.getModel()).thenReturn(BrokerModel.getInstance());
    when(_virtualHost.getState()).thenReturn(State.ACTIVE);
    when(_virtualHost.isActive()).thenReturn(true);
    final ArgumentCaptor<AMQPConnection> connectionCaptor = ArgumentCaptor.forClass(AMQPConnection.class);
    final ArgumentCaptor<ConnectionEstablishmentPolicy> establishmentPolicyCaptor = ArgumentCaptor.forClass(ConnectionEstablishmentPolicy.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            _connection = connectionCaptor.getValue();
            return null;
        }
    }).when(_virtualHost).registerConnection(connectionCaptor.capture(), establishmentPolicyCaptor.capture());
    when(_virtualHost.getPrincipal()).thenReturn(mock(VirtualHostPrincipal.class));
    when(_port.getAddressSpace(anyString())).thenReturn(_virtualHost);
    when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(subjectCreator);
    final ArgumentCaptor<Principal> userCaptor = ArgumentCaptor.forClass(Principal.class);
    when(subjectCreator.createSubjectWithGroups(userCaptor.capture())).then(new Answer<Subject>() {

        @Override
        public Subject answer(final InvocationOnMock invocation) throws Throwable {
            Subject subject = new Subject();
            subject.getPrincipals().add(userCaptor.getValue());
            return subject;
        }
    });
    final ByteBufferSender sender = mock(ByteBufferSender.class);
    when(_networkConnection.getSender()).thenReturn(sender);
    AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer().registerMessagingLayer().registerTransactionLayer().registerSecurityLayer();
    _frameWriter = new FrameWriter(registry, new ByteBufferSender() {

        @Override
        public boolean isDirectBufferPreferred() {
            return false;
        }

        @Override
        public void send(final QpidByteBuffer msg) {
            _protocolEngine_1_0_0.received(msg);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() {
        }
    });
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) InetSocketAddress(java.net.InetSocketAddress) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Subject(javax.security.auth.Subject) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter) ConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) VirtualHost(org.apache.qpid.server.model.VirtualHost) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 2 with Close

use of org.apache.qpid.server.protocol.v1_0.type.transport.Close in project qpid-broker-j by apache.

the class BeginTest method emptyBegin.

@Test
@SpecificationTest(section = "1.3.4", description = "Begin without mandatory fields should result in a decoding error.")
public void emptyBegin() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        Close responseClose = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).beginNextOutgoingId(null).beginIncomingWindow(null).beginOutgoingWindow(null).begin().consumeResponse().getLatestResponse(Close.class);
        assertThat(responseClose.getError(), is(notNullValue()));
        assertThat(responseClose.getError().getCondition(), equalTo(AmqpError.DECODE_ERROR));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with Close

use of org.apache.qpid.server.protocol.v1_0.type.transport.Close in project qpid-broker-j by apache.

the class FrameEncoder method encode.

@Override
public ByteBuffer encode(final Object msg) {
    if (msg instanceof AMQFrame) {
        List<ByteBuffer> buffers = new ArrayList<>();
        FrameWriter _frameWriter = new FrameWriter(TYPE_REGISTRY, new ByteBufferSender() {

            @Override
            public boolean isDirectBufferPreferred() {
                return false;
            }

            @Override
            public void send(final QpidByteBuffer msg) {
                byte[] data = new byte[msg.remaining()];
                msg.get(data);
                buffers.add(ByteBuffer.wrap(data));
            }

            @Override
            public void flush() {
            }

            @Override
            public void close() {
            }
        });
        _frameWriter.send(((AMQFrame) msg));
        int remaining = 0;
        for (ByteBuffer byteBuffer : buffers) {
            remaining += byteBuffer.remaining();
        }
        ByteBuffer result = ByteBuffer.allocate(remaining);
        for (ByteBuffer byteBuffer : buffers) {
            result.put(byteBuffer);
        }
        result.flip();
        return result;
    }
    return null;
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ArrayList(java.util.ArrayList) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQFrame(org.apache.qpid.server.protocol.v1_0.framing.AMQFrame) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteBuffer(java.nio.ByteBuffer) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter)

Example 4 with Close

use of org.apache.qpid.server.protocol.v1_0.type.transport.Close in project qpid-broker-j by apache.

the class Interaction method copyClose.

private Close copyClose(final Close close) {
    final Close closeCopy = new Close();
    closeCopy.setError(close.getError());
    return closeCopy;
}
Also used : Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close)

Example 5 with Close

use of org.apache.qpid.server.protocol.v1_0.type.transport.Close in project qpid-broker-j by apache.

the class Interaction method doCloseConnection.

public void doCloseConnection() throws Exception {
    Close close = new Close();
    sendPerformative(close, UnsignedShort.valueOf((short) 0));
    Response<?> response = consumeResponse().getLatestResponse();
    if (!(response.getBody() instanceof Close)) {
        throw new IllegalStateException(String.format("Unexpected response to connection Close. Expected Close got '%s'", response.getBody()));
    }
}
Also used : Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close)

Aggregations

Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)26 Test (org.junit.Test)23 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)21 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)18 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)15 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)14 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)13 InetSocketAddress (java.net.InetSocketAddress)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)8 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)7 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)7 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)6 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)6 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)5 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)5 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)5 ArrayList (java.util.ArrayList)4 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)4 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)4