Search in sources :

Example 1 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class ServerSessionTest method testOverlargeMessageTest.

@Test
public void testOverlargeMessageTest() throws Exception {
    final Broker<?> broker = mock(Broker.class);
    when(broker.getContextValue(eq(Long.class), eq(Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT))).thenReturn(0l);
    AmqpPort port = createMockPort();
    final AMQPConnection_0_10 modelConnection = mock(AMQPConnection_0_10.class);
    when(modelConnection.getCategoryClass()).thenReturn(Connection.class);
    when(modelConnection.getTypeClass()).thenReturn(AMQPConnection_0_10.class);
    when(modelConnection.closeAsync()).thenReturn(Futures.immediateFuture(null));
    when(modelConnection.getAddressSpace()).thenReturn(_virtualHost);
    when(modelConnection.getContextProvider()).thenReturn(_virtualHost);
    when(modelConnection.getBroker()).thenReturn(broker);
    when(modelConnection.getEventLogger()).thenReturn(mock(EventLogger.class));
    when(modelConnection.getContextValue(Long.class, Session.PRODUCER_AUTH_CACHE_TIMEOUT)).thenReturn(Session.PRODUCER_AUTH_CACHE_TIMEOUT_DEFAULT);
    when(modelConnection.getContextValue(Integer.class, Session.PRODUCER_AUTH_CACHE_SIZE)).thenReturn(Session.PRODUCER_AUTH_CACHE_SIZE_DEFAULT);
    when(modelConnection.getContextValue(Long.class, Connection.MAX_UNCOMMITTED_IN_MEMORY_SIZE)).thenReturn(Connection.DEFAULT_MAX_UNCOMMITTED_IN_MEMORY_SIZE);
    when(modelConnection.getChildExecutor()).thenReturn(_taskExecutor);
    when(modelConnection.getModel()).thenReturn(BrokerModel.getInstance());
    when(modelConnection.getPort()).thenReturn(port);
    final AuthenticatedPrincipal principal = new AuthenticatedPrincipal(new UsernamePrincipal(getTestName(), mock(AuthenticationProvider.class)));
    final Subject subject = new Subject(false, Collections.singleton(principal), Collections.emptySet(), Collections.emptySet());
    when(modelConnection.getSubject()).thenReturn(subject);
    when(modelConnection.getMaxMessageSize()).thenReturn(1024l);
    when(modelConnection.getCreatedTime()).thenReturn(new Date());
    ServerConnection connection = new ServerConnection(1, broker, port, Transport.TCP, modelConnection);
    connection.setVirtualHost(_virtualHost);
    final List<Method> invokedMethods = new ArrayList<>();
    ServerSession session = new ServerSession(connection, new ServerSessionDelegate(), new Binary(getTestName().getBytes()), 0) {

        @Override
        public void invoke(final Method m) {
            invokedMethods.add(m);
        }
    };
    Session_0_10 modelSession = new Session_0_10(modelConnection, 1, session, getTestName());
    session.setModelObject(modelSession);
    ServerSessionDelegate delegate = new ServerSessionDelegate();
    MessageTransfer xfr = new MessageTransfer();
    byte[] body1 = new byte[2048];
    xfr.setBody(QpidByteBuffer.wrap(body1));
    delegate.messageTransfer(session, xfr);
    assertFalse("No methods invoked - expecting at least 1", invokedMethods.isEmpty());
    Method firstInvoked = invokedMethods.get(0);
    final boolean condition = firstInvoked instanceof ExecutionException;
    assertTrue("First invoked method not execution error", condition);
    assertEquals(ExecutionErrorCode.RESOURCE_LIMIT_EXCEEDED, ((ExecutionException) firstInvoked).getErrorCode());
    invokedMethods.clear();
    // test the boundary condition
    byte[] body = new byte[1024];
    xfr.setBody(QpidByteBuffer.wrap(body));
    delegate.messageTransfer(session, xfr);
    assertTrue("Methods invoked when not expecting any", invokedMethods.isEmpty());
}
Also used : EventLogger(org.apache.qpid.server.logging.EventLogger) ArrayList(java.util.ArrayList) Method(org.apache.qpid.server.protocol.v0_10.transport.Method) Subject(javax.security.auth.Subject) Date(java.util.Date) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) Binary(org.apache.qpid.server.protocol.v0_10.transport.Binary) ExecutionException(org.apache.qpid.server.protocol.v0_10.transport.ExecutionException) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test)

Example 2 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class LargeApplicationHeadersTest method applicationHeadersSentOverManyFrames.

@Test
public void applicationHeadersSentOverManyFrames() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        final String subscriberName = "testSubscriber";
        byte[] sessionName = "test".getBytes(UTF_8);
        final ConnectionTune tune = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
        int headerPropertySize = ((1 << 16) - 1);
        Map<String, Object> applicationHeaders = createApplicationHeadersThatExceedSingleFrame(headerPropertySize, tune.getMaxFrameSize());
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setApplicationHeaders(applicationHeaders);
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
        interaction.channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferHeader(null, messageProperties).transferId(0).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        assertThat(transfer.getBodySize(), is(0));
        Header header = transfer.getHeader();
        assertThat(header, is(notNullValue()));
        MessageProperties receivedMessageProperties = header.getMessageProperties();
        assertThat(receivedMessageProperties, is(notNullValue()));
        Map<String, Object> receivedApplicationHeaders = receivedMessageProperties.getApplicationHeaders();
        assertThat(receivedApplicationHeaders, is(notNullValue()));
        assertThat(receivedApplicationHeaders, is(equalTo(applicationHeaders)));
    }
}
Also used : Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) SessionCommandPoint(org.apache.qpid.server.protocol.v0_10.transport.SessionCommandPoint) Test(org.junit.Test)

Example 3 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class MessageTest method acquireTransfer.

@Test
@SpecificationTest(section = "10.message.acquire", description = "Acquires previously transferred messages for consumption. The acquired ids (if any) are " + "sent via message.acquired.")
public void acquireTransfer() throws Exception {
    String testMessageBody = "testMessage";
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageBody);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "testSession".getBytes(UTF_8);
        final String subscriberName = "testSubscriber";
        interaction.negotiateOpen().channelId(1).attachSession(sessionName).message().subscribeAcceptMode(MessageAcceptMode.EXPLICIT).subscribeAcquireMode(MessageAcquireMode.NOT_ACQUIRED).subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow();
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class, SessionFlush.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
        RangeSet transfers = Range.newInstance(transfer.getId());
        final ExecutionResult result = interaction.message().acquireId(3).acquireTransfers(transfers).acquire().consumeResponse(SessionFlush.class).consumeResponse().getLatestResponse(ExecutionResult.class);
        final Acquired acquired = (Acquired) result.getValue();
        assertThat(acquired.getTransfers().includes(transfer.getId()), is(equalTo(true)));
        interaction.message().acceptId(4).acceptTransfers(transfers).accept().session().flushCompleted().flush();
        SessionCompleted completed = interaction.consume(SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class, SessionFlush.class);
        assertThat(completed.getCommands(), is(notNullValue()));
        assertThat(completed.getCommands().includes(4), is(equalTo(true)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) Acquired(org.apache.qpid.server.protocol.v0_10.transport.Acquired) RangeSet(org.apache.qpid.server.protocol.v0_10.transport.RangeSet) ExecutionResult(org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 4 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class MessageTest method acceptTransfer.

@Test
@SpecificationTest(section = "10.message.accept", description = "Accepts the message.")
public void acceptTransfer() throws Exception {
    String testMessageBody = "testMessage";
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageBody);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "testSession".getBytes(UTF_8);
        final String subscriberName = "testSubscriber";
        interaction.negotiateOpen().channelId(1).attachSession(sessionName).message().subscribeAcceptMode(MessageAcceptMode.EXPLICIT).subscribeAcquireMode(MessageAcquireMode.PRE_ACQUIRED).subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow();
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
        RangeSet transfers = Range.newInstance(transfer.getId());
        interaction.message().acceptId(3).acceptTransfers(transfers).accept().session().flushCompleted().flush();
        SessionCompleted completed = interaction.consume(SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class, SessionFlush.class);
        assertThat(completed.getCommands(), is(notNullValue()));
        assertThat(completed.getCommands().includes(3), is(equalTo(true)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) RangeSet(org.apache.qpid.server.protocol.v0_10.transport.RangeSet) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class LargeMessageBodyTest method messageBodyOverManyFrames.

@Test
public void messageBodyOverManyFrames() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        final String subscriberName = "testSubscriber";
        byte[] sessionName = "test".getBytes(UTF_8);
        final ConnectionTune tune = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
        final byte[] messageContent = new byte[tune.getMaxFrameSize() * 2];
        IntStream.range(0, messageContent.length).forEach(i -> {
            messageContent[i] = (byte) (i & 0xFF);
        });
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setContentLength(messageContent.length);
        interaction.channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferBody(messageContent).transferHeader(null, messageProperties).transferId(3).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        assertThat(transfer.getBodySize(), is(equalTo(messageContent.length)));
        QpidByteBuffer receivedBody = transfer.getBody();
        byte[] receivedBytes = new byte[receivedBody.remaining()];
        receivedBody.get(receivedBytes);
        assertThat(receivedBytes, is(equalTo(messageContent)));
    }
}
Also used : MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test)

Aggregations

MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)9 Test (org.junit.Test)8 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)4 SessionCompleted (org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted)4 RangeSet (org.apache.qpid.server.protocol.v0_10.transport.RangeSet)3 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)3 ConnectionTune (org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune)2 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)2 Method (org.apache.qpid.server.protocol.v0_10.transport.Method)2 FrameTransport (org.apache.qpid.tests.protocol.v0_10.FrameTransport)2 Interaction (org.apache.qpid.tests.protocol.v0_10.Interaction)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Subject (javax.security.auth.Subject)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 ServerMessage (org.apache.qpid.server.message.ServerMessage)1 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)1 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)1 Acquired (org.apache.qpid.server.protocol.v0_10.transport.Acquired)1