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());
}
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());
}
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());
}
}
}
}
}
Aggregations