Search in sources :

Example 1 with AlternateBinding

use of org.apache.qpid.server.model.AlternateBinding in project qpid-broker-j by apache.

the class QueueEntryImplTestBase method testRouteToAlternateInvokesAction.

@Test
public void testRouteToAlternateInvokesAction() {
    String dlqName = "dlq";
    Map<String, Object> dlqAttributes = new HashMap<>();
    dlqAttributes.put(Queue.ID, UUID.randomUUID());
    dlqAttributes.put(Queue.NAME, dlqName);
    Queue<?> dlq = (Queue<?>) _queueEntry.getQueue().getVirtualHost().createChild(Queue.class, dlqAttributes);
    final AlternateBinding alternateBinding = mock(AlternateBinding.class);
    when(alternateBinding.getDestination()).thenReturn(dlqName);
    _queueEntry.getQueue().setAttributes(Collections.singletonMap(Queue.ALTERNATE_BINDING, alternateBinding));
    final Action<? super MessageInstance> action = mock(Action.class);
    when(_queueEntry.getMessage().isResourceAcceptable(dlq)).thenReturn(true);
    when(_queueEntry.getMessage().checkValid()).thenReturn(true);
    _queueEntry.acquire();
    int enqueues = _queueEntry.routeToAlternate(action, null, null);
    assertEquals("Unexpected number of enqueues", 1, enqueues);
    verify(action).performAction(any());
    assertEquals("Unexpected number of messages on DLQ", 1, dlq.getQueueDepthMessages());
}
Also used : HashMap(java.util.HashMap) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Queue(org.apache.qpid.server.model.Queue) Test(org.junit.Test)

Example 2 with AlternateBinding

use of org.apache.qpid.server.model.AlternateBinding in project qpid-broker-j by apache.

the class DestinationControllerTest method testLegacyDestination.

@Test
public void testLegacyDestination() {
    final String alternateExchangeName = "alt";
    final LegacyConfiguredObject nextVersionDestination = mock(LegacyConfiguredObject.class);
    final AlternateBinding alternateDestination = mock(AlternateBinding.class);
    when(alternateDestination.getDestination()).thenReturn(alternateExchangeName);
    when(nextVersionDestination.getAttribute("alternateBinding")).thenReturn(alternateDestination);
    final LegacyConfiguredObject vh = mock(LegacyConfiguredObject.class);
    when(nextVersionDestination.getParent(VirtualHostController.TYPE)).thenReturn(vh);
    final LegacyConfiguredObject alternateExchange = mock(LegacyConfiguredObject.class);
    when(alternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(alternateExchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn(alternateExchangeName);
    final Collection<LegacyConfiguredObject> exchanges = Collections.singletonList(alternateExchange);
    when(vh.getChildren(ExchangeController.TYPE)).thenReturn(exchanges);
    final LegacyConfiguredObject converted = mock(LegacyConfiguredObject.class);
    when(_legacyVersionManagementController.convertFromNextVersion(alternateExchange)).thenReturn(converted);
    DestinationController.LegacyDestination destination = new DestinationController.LegacyDestination(_legacyVersionManagementController, nextVersionDestination, "Queue");
    assertThat(destination.getAttribute("alternateExchange"), is(equalTo(converted)));
}
Also used : LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Test(org.junit.Test)

Example 3 with AlternateBinding

use of org.apache.qpid.server.model.AlternateBinding in project qpid-broker-j by apache.

the class ExchangeControllerTest method convertNextVersionLegacyConfiguredObject.

@Test
public void convertNextVersionLegacyConfiguredObject() {
    final ExchangeController exchangeController = new ExchangeController(_legacyManagementController, Collections.emptySet());
    final String exchangeName = "testExchange";
    final String alternateExchangeName = "altExchange";
    final String queueName = "testQueue";
    final String bindingKey = "testBindingKey";
    final LegacyConfiguredObject nextVersionExchange = mock(LegacyConfiguredObject.class);
    final AlternateBinding alternateBinding = mock(AlternateBinding.class);
    final Binding nextVersionBinding = mock(Binding.class);
    final LegacyConfiguredObject nextVersionAlternateExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject nextVersionVirtualHost = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    when(alternateBinding.getDestination()).thenReturn(alternateExchangeName);
    when(nextVersionExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionExchange.getAttribute("alternateBinding")).thenReturn(alternateBinding);
    when(nextVersionExchange.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(exchangeName);
    when(nextVersionExchange.getAttribute("bindings")).thenReturn(Collections.singletonList(nextVersionBinding));
    when(nextVersionExchange.getParent(VirtualHostController.TYPE)).thenReturn(nextVersionVirtualHost);
    when(nextVersionBinding.getDestination()).thenReturn(queueName);
    when(nextVersionBinding.getBindingKey()).thenReturn(bindingKey);
    when(nextVersionAlternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionAlternateExchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn(alternateExchangeName);
    when(nextVersionVirtualHost.getChildren(ExchangeController.TYPE)).thenReturn(Arrays.asList(nextVersionExchange, nextVersionAlternateExchange));
    when(nextVersionVirtualHost.getChildren(QueueController.TYPE)).thenReturn(Collections.singletonList(queue));
    final LegacyConfiguredObject convertedExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedAltExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedQueue = mock(LegacyConfiguredObject.class);
    when(_legacyManagementController.convertFromNextVersion(nextVersionExchange)).thenReturn(convertedExchange);
    when(_legacyManagementController.convertFromNextVersion(nextVersionAlternateExchange)).thenReturn(convertedAltExchange);
    when(_legacyManagementController.convertFromNextVersion(queue)).thenReturn(convertedQueue);
    final LegacyConfiguredObject destination = exchangeController.convertFromNextVersion(nextVersionExchange);
    assertThat(destination.getAttribute("alternateExchange"), is(equalTo(convertedAltExchange)));
    final Collection<LegacyConfiguredObject> children = destination.getChildren(BindingController.TYPE);
    assertThat(children.size(), is(equalTo(1)));
    final LegacyConfiguredObject o = children.iterator().next();
    assertThat(o.getCategory(), is(equalTo(BindingController.TYPE)));
    assertThat(o.getAttribute(AbstractConfiguredObject.NAME), is(equalTo(bindingKey)));
    assertThat(o.getAttribute("queue"), is(equalTo(convertedQueue)));
    assertThat(o.getAttribute("exchange"), is(equalTo(convertedExchange)));
}
Also used : AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Test(org.junit.Test)

Example 4 with AlternateBinding

use of org.apache.qpid.server.model.AlternateBinding in project qpid-broker-j by apache.

the class AbstractExchange method validateOrCreateAlternateBinding.

private void validateOrCreateAlternateBinding(final Exchange<?> exchange, final boolean mayCreate) {
    Object value = exchange.getAttribute(ALTERNATE_BINDING);
    if (value instanceof AlternateBinding) {
        AlternateBinding alternateBinding = (AlternateBinding) value;
        String destinationName = alternateBinding.getDestination();
        MessageDestination messageDestination = _virtualHost.getAttainedMessageDestination(destinationName, mayCreate);
        if (messageDestination == null) {
            throw new UnknownAlternateBindingException(destinationName);
        } else if (messageDestination == this) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination cannot refer to self.", getName()));
        } else if (isDurable() && !messageDestination.isDurable()) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination '%s' is not durable.", getName(), destinationName));
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 5 with AlternateBinding

use of org.apache.qpid.server.model.AlternateBinding in project qpid-broker-j by apache.

the class QueueControllerTest method convertNextVersionLegacyConfiguredObject.

@Test
public void convertNextVersionLegacyConfiguredObject() {
    final String exchangeName = "testExchange";
    final String alternateExchangeName = "altExchange";
    final String queueName = "testQueue";
    final String bindingKey = "testBindingKey";
    final LegacyConfiguredObject nextVersionQueue = mock(LegacyConfiguredObject.class);
    final Binding nextVersionBinding = mock(Binding.class);
    final LegacyConfiguredObject nextVersionVirtualHost = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject nextVersionAlternateExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject nextVersionExchange = mock(LegacyConfiguredObject.class);
    final AlternateBinding alternateDestination = mock(AlternateBinding.class);
    when(alternateDestination.getDestination()).thenReturn(alternateExchangeName);
    when(nextVersionQueue.getCategory()).thenReturn(QueueController.TYPE);
    when(nextVersionQueue.getParent(VirtualHostController.TYPE)).thenReturn(nextVersionVirtualHost);
    when(nextVersionQueue.getAttribute("alternateBinding")).thenReturn(alternateDestination);
    when(nextVersionQueue.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(queueName);
    when(nextVersionQueue.getAttribute("overflowPolicy")).thenReturn("PRODUCER_FLOW_CONTROL");
    when(nextVersionQueue.getAttribute("maximumQueueDepthBytes")).thenReturn(10000L);
    when(nextVersionQueue.getAttribute("context")).thenReturn(Collections.singletonMap("queue.queueFlowResumeLimit", "70"));
    when(nextVersionQueue.getAttribute("messageGroupType")).thenReturn("SHARED_GROUPS");
    when(nextVersionQueue.getAttribute("messageGroupKeyOverride")).thenReturn("test");
    when(nextVersionBinding.getDestination()).thenReturn(queueName);
    when(nextVersionBinding.getBindingKey()).thenReturn(bindingKey);
    when(nextVersionExchange.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(exchangeName);
    when(nextVersionExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionExchange.getAttribute("bindings")).thenReturn(Collections.singletonList(nextVersionBinding));
    when(nextVersionAlternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionAlternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
    when(nextVersionAlternateExchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn(alternateExchangeName);
    when(nextVersionVirtualHost.getChildren(ExchangeController.TYPE)).thenReturn(Arrays.asList(nextVersionExchange, nextVersionAlternateExchange));
    when(nextVersionVirtualHost.getChildren(QueueController.TYPE)).thenReturn(Collections.singletonList(nextVersionExchange));
    final LegacyConfiguredObject convertedExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedAltExchange = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject convertedQueue = mock(LegacyConfiguredObject.class);
    when(_legacyVersionManagementController.convertFromNextVersion(nextVersionQueue)).thenReturn(convertedQueue);
    when(_legacyVersionManagementController.convertFromNextVersion(nextVersionAlternateExchange)).thenReturn(convertedAltExchange);
    when(_legacyVersionManagementController.convertFromNextVersion(nextVersionExchange)).thenReturn(convertedExchange);
    final LegacyConfiguredObject destination = _queueController.convertFromNextVersion(nextVersionQueue);
    assertThat(destination.getAttribute("alternateExchange"), is(equalTo(convertedAltExchange)));
    assertThat(destination.getAttribute("queueFlowControlSizeBytes"), is(equalTo(10000L)));
    assertThat(destination.getAttribute("queueFlowResumeSizeBytes"), is(equalTo(7000L)));
    assertThat(destination.getAttribute("messageGroupSharedGroups"), is(equalTo(true)));
    assertThat(destination.getAttribute("messageGroupKey"), is(equalTo("test")));
    final Collection<LegacyConfiguredObject> children = destination.getChildren(BindingController.TYPE);
    assertThat(children.size(), is(equalTo(1)));
    final LegacyConfiguredObject o = children.iterator().next();
    assertThat(o.getCategory(), is(equalTo(BindingController.TYPE)));
    assertThat(o.getAttribute(AbstractConfiguredObject.NAME), is(equalTo(bindingKey)));
    assertThat(o.getAttribute("queue"), is(equalTo(convertedQueue)));
    assertThat(o.getAttribute("exchange"), is(equalTo(convertedExchange)));
}
Also used : AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Test(org.junit.Test)

Aggregations

AlternateBinding (org.apache.qpid.server.model.AlternateBinding)5 Test (org.junit.Test)4 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)3 Binding (org.apache.qpid.server.model.Binding)2 HashMap (java.util.HashMap)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 MessageDestination (org.apache.qpid.server.message.MessageDestination)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 Queue (org.apache.qpid.server.model.Queue)1 UnknownAlternateBindingException (org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)1