Search in sources :

Example 1 with MessageDestinationIsAlternateException

use of org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException in project qpid-broker-j by apache.

the class DirectExchangeTest method testDeleteOfExchangeSetAsAlternate.

public void testDeleteOfExchangeSetAsAlternate() throws Exception {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(Queue.NAME, getTestName());
    attributes.put(Queue.DURABLE, false);
    attributes.put(Queue.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, _exchange.getName()));
    Queue queue = _vhost.createChild(Queue.class, attributes);
    queue.open();
    assertEquals("Unexpected alternate exchange on queue", _exchange, queue.getAlternateBindingDestination());
    try {
        _exchange.delete();
        fail("Exchange deletion should fail with MessageDestinationIsAlternateException");
    } catch (MessageDestinationIsAlternateException e) {
    // pass
    }
    assertEquals("Unexpected effective exchange state", State.ACTIVE, _exchange.getState());
    assertEquals("Unexpected desired exchange state", State.ACTIVE, _exchange.getDesiredState());
}
Also used : HashMap(java.util.HashMap) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) Queue(org.apache.qpid.server.model.Queue)

Example 2 with MessageDestinationIsAlternateException

use of org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException in project qpid-broker-j by apache.

the class AbstractQueueTestBase method testDeleteOfQueueSetAsAlternate.

public void testDeleteOfQueueSetAsAlternate() {
    Map<String, Object> attributes = new HashMap<>(_arguments);
    attributes.put(Queue.NAME, getTestName());
    attributes.put(Queue.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, _qname));
    Queue newQueue = _virtualHost.createChild(Queue.class, attributes);
    assertEquals("Unexpected alternate binding", _qname, newQueue.getAlternateBinding().getDestination());
    try {
        _queue.delete();
        fail("Expected exception is not thrown");
    } catch (MessageDestinationIsAlternateException e) {
    // pass
    }
    assertFalse(_queue.isDeleted());
}
Also used : HashMap(java.util.HashMap) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) Queue(org.apache.qpid.server.model.Queue)

Example 3 with MessageDestinationIsAlternateException

use of org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException in project qpid-broker-j by apache.

the class AMQChannel method receiveExchangeDelete.

@Override
public void receiveExchangeDelete(final AMQShortString exchangeStr, final boolean ifUnused, final boolean nowait) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] ExchangeDelete[" + " exchange: " + exchangeStr + " ifUnused: " + ifUnused + " nowait: " + nowait + " ]");
    }
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    sync();
    if (isDefaultExchange(exchangeStr)) {
        _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Default Exchange cannot be deleted", getChannelId());
    } else {
        final String exchangeName = exchangeStr.toString();
        final Exchange<?> exchange = getExchange(exchangeName);
        if (exchange == null) {
            closeChannel(ErrorCodes.NOT_FOUND, "No such exchange: '" + exchangeStr + "'");
        } else {
            if (ifUnused && exchange.hasBindings()) {
                closeChannel(ErrorCodes.IN_USE, "Exchange has bindings");
            } else {
                try {
                    exchange.delete();
                    if (!nowait) {
                        ExchangeDeleteOkBody responseBody = _connection.getMethodRegistry().createExchangeDeleteOkBody();
                        _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                    }
                } catch (MessageDestinationIsAlternateException e) {
                    closeChannel(ErrorCodes.NOT_ALLOWED, "Exchange in use as an alternate binding destination");
                } catch (RequiredExchangeException e) {
                    closeChannel(ErrorCodes.NOT_ALLOWED, "Exchange '" + exchangeStr + "' cannot be deleted");
                } catch (AccessControlException e) {
                    _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
                }
            }
        }
    }
}
Also used : NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) AccessControlException(java.security.AccessControlException) RequiredExchangeException(org.apache.qpid.server.virtualhost.RequiredExchangeException)

Aggregations

MessageDestinationIsAlternateException (org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException)3 HashMap (java.util.HashMap)2 Queue (org.apache.qpid.server.model.Queue)2 AccessControlException (java.security.AccessControlException)1 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)1 RequiredExchangeException (org.apache.qpid.server.virtualhost.RequiredExchangeException)1