Search in sources :

Example 6 with ExecutionException

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

the class QueueTest method queueDeclareAutoDeleteAndExclusiveDeletedBySessionDetach.

@Test
@SpecificationTest(section = "10.queue.declare", description = "If this field [auto-delete] is set and the exclusive field is also set, then the queue " + "MUST be deleted when the session closes.")
public void queueDeclareAutoDeleteAndExclusiveDeletedBySessionDetach() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.openAnonymousConnection().channelId(1).attachSession(SESSION_NAME).queue().declareQueue(BrokerAdmin.TEST_QUEUE_NAME).declareId(0).declareExclusive(true).declareAutoDelete(true).declare().session().flushCompleted().flush().consumeResponse(SessionCompleted.class).session().detachName(SESSION_NAME).detach().consumeResponse(SessionDetached.class);
        ExecutionException response = interaction.channelId(2).attachSession(SESSION_NAME).queue().declareQueue(BrokerAdmin.TEST_QUEUE_NAME).declareId(0).declarePassive(true).declare().session().flushCompleted().flush().consumeResponse(SessionCommandPoint.class).consumeResponse().getLatestResponse(ExecutionException.class);
        assertThat(response.getErrorCode(), is(equalTo(ExecutionErrorCode.NOT_FOUND)));
    }
}
Also used : ExecutionException(org.apache.qpid.server.protocol.v0_10.transport.ExecutionException) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 7 with ExecutionException

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

the class ServerSessionDelegateTest method testExchangeDeleteWhenIfUsedIsSetAndExchangeHasBindings.

public void testExchangeDeleteWhenIfUsedIsSetAndExchangeHasBindings() throws Exception {
    Exchange<?> exchange = mock(Exchange.class);
    when(exchange.hasBindings()).thenReturn(true);
    doReturn(exchange).when(_host).getAttainedMessageDestination(getTestName());
    final ExchangeDelete method = new ExchangeDelete(getTestName(), Option.IF_UNUSED);
    _delegate.exchangeDelete(_session, method);
    verify(_session).invoke(argThat(new ArgumentMatcher<ExecutionException>() {

        @Override
        public boolean matches(Object object) {
            ExecutionException exception = (ExecutionException) object;
            return exception.getErrorCode() == ExecutionErrorCode.PRECONDITION_FAILED && "Exchange has bindings".equals(exception.getDescription());
        }
    }));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) ExecutionException(org.apache.qpid.server.protocol.v0_10.transport.ExecutionException) ExchangeDelete(org.apache.qpid.server.protocol.v0_10.transport.ExchangeDelete)

Example 8 with ExecutionException

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

the class ServerSessionTest method testOverlargeMessageTest.

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);
    Subject subject = new Subject();
    when(modelConnection.getSubject()).thenReturn(subject);
    when(modelConnection.getMaxMessageSize()).thenReturn(1024l);
    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(getName().getBytes()), 0) {

        @Override
        public void invoke(final Method m) {
            invokedMethods.add(m);
        }
    };
    Session_0_10 modelSession = new Session_0_10(modelConnection, 1, session);
    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);
    assertTrue("First invoked method not execution error", firstInvoked instanceof ExecutionException);
    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) 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)

Example 9 with ExecutionException

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

the class ServerConnection method closeSessionAsync.

public void closeSessionAsync(final ServerSession session, final AMQPConnection.CloseReason reason, final String message) {
    final int cause;
    switch(reason) {
        case MANAGEMENT:
            cause = ErrorCodes.CONNECTION_FORCED;
            break;
        case TRANSACTION_TIMEOUT:
            cause = ErrorCodes.RESOURCE_ERROR;
            break;
        default:
            cause = ErrorCodes.INTERNAL_ERROR;
    }
    addAsyncTask(new Action<ServerConnection>() {

        @Override
        public void performAction(final ServerConnection conn) {
            if (!session.isClosing()) {
                ExecutionException ex = new ExecutionException();
                ExecutionErrorCode code = ExecutionErrorCode.INTERNAL_ERROR;
                try {
                    code = ExecutionErrorCode.get(cause);
                } catch (IllegalArgumentException iae) {
                // Ignore, already set to INTERNAL_ERROR
                }
                ex.setErrorCode(code);
                ex.setDescription(message);
                session.invoke(ex);
                session.close(cause, message);
            }
        }
    });
}
Also used : ExecutionErrorCode(org.apache.qpid.server.protocol.v0_10.transport.ExecutionErrorCode) ExecutionException(org.apache.qpid.server.protocol.v0_10.transport.ExecutionException)

Example 10 with ExecutionException

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

the class ExchangeTest method exchangeDeclareAlternateExchangeNotFound.

@Test
@SpecificationTest(section = "10.exchange.declare", description = "if the alternate-exchange does not match the name of any existing exchange on the server, " + "then an exception must be raised.")
public void exchangeDeclareAlternateExchangeNotFound() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        ExecutionException response = interaction.openAnonymousConnection().channelId(1).attachSession(SESSION_NAME).exchange().declareExchange("myexch").declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS).declareAlternateExchange("unknownExchange").declareId(0).declare().session().flushCompleted().flush().consumeResponse(SessionCommandPoint.class).consumeResponse().getLatestResponse(ExecutionException.class);
        assertThat(response.getErrorCode(), is(equalTo(ExecutionErrorCode.NOT_FOUND)));
    }
}
Also used : ExecutionException(org.apache.qpid.server.protocol.v0_10.transport.ExecutionException) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

ExecutionException (org.apache.qpid.server.protocol.v0_10.transport.ExecutionException)15 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)1 Subject (javax.security.auth.Subject)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)1 Binary (org.apache.qpid.server.protocol.v0_10.transport.Binary)1 ExchangeDelete (org.apache.qpid.server.protocol.v0_10.transport.ExchangeDelete)1 ExecutionErrorCode (org.apache.qpid.server.protocol.v0_10.transport.ExecutionErrorCode)1 MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)1 Method (org.apache.qpid.server.protocol.v0_10.transport.Method)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1