Skip to content

Commit

Permalink
QPID-8665: [Broker-J] Changing queue exclusive mode throws exception (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dakirily authored Jan 29, 2024
1 parent 3fcd696 commit f2381ec
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,17 @@ public Collection<String> getAvailableAttributes()
@Override
public String getOwner()
{
if(_exclusiveOwner != null)
if (_exclusiveOwner instanceof String)
{
switch(_exclusive)
{
case CONTAINER:
return (String) _exclusiveOwner;
case PRINCIPAL:
return ((Principal)_exclusiveOwner).getName();
}
return (String) _exclusiveOwner;
}
else if (_exclusiveOwner instanceof ConfiguredObject)
{
return ((ConfiguredObject<?>) _exclusiveOwner).getName();
}
else if (_exclusiveOwner instanceof Principal)
{
return ((Principal) _exclusiveOwner).getName();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.security.Principal;
import java.util.ArrayList;

import com.google.common.util.concurrent.Futures;
Expand Down Expand Up @@ -52,8 +53,18 @@ public class TestConsumerTarget implements ConsumerTarget<TestConsumerTarget>

public TestConsumerTarget()
{
when(_sessionModel.getName()).thenReturn("mock session");

final Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn("mock principal");

final AMQPConnection amqpConnection = mock(AMQPConnection.class);
when(amqpConnection.getAuthorizedPrincipal()).thenReturn(principal);
when(amqpConnection.getName()).thenReturn("mock connection");
when(amqpConnection.getRemoteContainerName()).thenReturn("mock container");

when(_sessionModel.getChannelId()).thenReturn(0);
when(_sessionModel.getAMQPConnection()).thenReturn(mock(AMQPConnection.class));
when(_sessionModel.getAMQPConnection()).thenReturn(amqpConnection);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.apache.qpid.server.model.Binding;
import org.apache.qpid.server.model.BrokerTestHelper;
import org.apache.qpid.server.model.Exchange;
import org.apache.qpid.server.model.ExclusivityPolicy;
import org.apache.qpid.server.model.OverflowPolicy;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.QueueNotificationListener;
Expand Down Expand Up @@ -557,6 +558,37 @@ public void testReleaseForQueueWithMultipleConsumers() throws Exception
"releasedEntry should be cleared after requeue processed");
}

@Test
public void testExclusivePolicy() throws Exception
{
final ServerMessage<?> messageA = createMessage(24L);
_consumer = (QueueConsumer<?,?>) _queue.addConsumer(_consumerTarget, null, messageA.getClass(), "test",
EnumSet.of(ConsumerOption.EXCLUSIVE, ConsumerOption.ACQUIRES, ConsumerOption.SEES_REQUEUES), 0);

_queue.setAttributes(Map.of(Queue.EXCLUSIVE, ExclusivityPolicy.CONNECTION));
assertEquals("mock connection", _queue.getOwner());

_queue.setAttributes(Map.of(Queue.EXCLUSIVE, ExclusivityPolicy.SESSION));
assertEquals("mock session", _queue.getOwner());

_queue.setAttributes(Map.of(Queue.EXCLUSIVE, ExclusivityPolicy.PRINCIPAL));
assertEquals("mock principal", _queue.getOwner());

_queue.setAttributes(Map.of(Queue.EXCLUSIVE, ExclusivityPolicy.CONTAINER));
assertEquals("mock container", _queue.getOwner());

_queue.setAttributes(Map.of(Queue.EXCLUSIVE, ExclusivityPolicy.LINK));
assertNull(_queue.getOwner());

_queue.setAttributes(Map.of(Queue.EXCLUSIVE, ExclusivityPolicy.SHARED_SUBSCRIPTION));
assertNull(_queue.getOwner());

_queue.setAttributes(Map.of(Queue.EXCLUSIVE, ExclusivityPolicy.NONE));
assertNull(_queue.getOwner());

_consumer.close();
}

@Test
public void testExclusiveConsumer() throws Exception
{
Expand Down

0 comments on commit f2381ec

Please sign in to comment.