You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2019/12/27 14:52:48 UTC
[qpid-broker-j] branch master updated: QPID-8392 : Add system test
for default alternate binding setting
This is an automated email from the ASF dual-hosted git repository.
orudyy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
The following commit(s) were added to refs/heads/master by this push:
new 35afa69 QPID-8392 : Add system test for default alternate binding setting
35afa69 is described below
commit 35afa69a92685d29200e1b492b7e54be326d0826
Author: Alex Rudyy <or...@apache.org>
AuthorDate: Fri Dec 27 14:52:28 2019 +0000
QPID-8392 : Add system test for default alternate binding setting
---
.../autocreation/DefaultAlternateBindingTest.java | 175 +++++++++++++++++++++
1 file changed, 175 insertions(+)
diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/extensions/autocreation/DefaultAlternateBindingTest.java b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/extensions/autocreation/DefaultAlternateBindingTest.java
new file mode 100644
index 0000000..586fcf2
--- /dev/null
+++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/extensions/autocreation/DefaultAlternateBindingTest.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.qpid.systests.jms_1_1.extensions.autocreation;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.qpid.server.virtualhost.NodeAutoCreationPolicy;
+import org.apache.qpid.server.virtualhost.QueueManagingVirtualHost;
+import org.apache.qpid.systests.JmsTestBase;
+import org.apache.qpid.systests.Utils;
+
+public class DefaultAlternateBindingTest extends JmsTestBase
+{
+ // quadruple of '$' is used intentionally instead of '$$' to account conversion in management layer
+ private static final String DEFAULT_ALTERNATE_BINDING = "{\"destination\": \"$$$${this:name}_DLQ\"}";
+ private static final int MAXIMUM_DELIVERY_ATTEMPTS = 1;
+ private static final int MESSAGE_COUNT = 4;
+ private String _queueName;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ _queueName = getTestName();
+ updateVirtualHostForDefaultAlternateBinding();
+ }
+
+ @Test
+ public void testDefaultAlternateBinding() throws Exception
+ {
+ createAndBindQueueWithMaxDeliveryAttempts();
+
+ final Connection connection = getConnectionBuilder().setMessageRedelivery(true).setSyncPublish(true).build();
+ try
+ {
+ final Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+
+ final Queue queue = session.createQueue(_queueName);
+ Utils.sendMessages(session, queue, MESSAGE_COUNT);
+
+ connection.start();
+ final MessageConsumer queueConsumer = session.createConsumer(queue);
+
+ for (int i = 0; i < MESSAGE_COUNT; i++)
+ {
+ final Message message = queueConsumer.receive(getReceiveTimeout());
+ assertThat(message, is(notNullValue()));
+ int index = message.getIntProperty(Utils.INDEX);
+ if (index % 2 == 0)
+ {
+ session.commit();
+ }
+ else
+ {
+ session.rollback();
+ }
+ }
+
+ final Queue dlq = session.createQueue(_queueName + "_DLQ");
+ final MessageConsumer dlqConsumer = session.createConsumer(dlq);
+
+ final Message message2 = dlqConsumer.receive(getReceiveTimeout());
+ assertThat(message2, is(notNullValue()));
+ assertThat(message2.getIntProperty(Utils.INDEX), is(equalTo(1)));
+
+ final Message message4 = dlqConsumer.receive(getReceiveTimeout());
+ assertThat(message4, is(notNullValue()));
+ assertThat(message4.getIntProperty(Utils.INDEX), is(equalTo(3)));
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ private void createAndBindQueueWithMaxDeliveryAttempts() throws Exception
+ {
+ final Map<String, Object> queueAttributes =
+ Collections.singletonMap(org.apache.qpid.server.model.Queue.MAXIMUM_DELIVERY_ATTEMPTS,
+ MAXIMUM_DELIVERY_ATTEMPTS);
+ createEntityUsingAmqpManagement(_queueName, "org.apache.qpid.Queue", queueAttributes);
+ final Map<String, Object> arguments = new HashMap<>();
+ arguments.put("destination", _queueName);
+ arguments.put("bindingKey", _queueName);
+ performOperationUsingAmqpManagement("amq.direct", "bind", "org.apache.qpid.Exchange", arguments);
+ }
+
+
+ private void updateVirtualHostForDefaultAlternateBinding() throws Exception
+ {
+ final Map<String, Object> attributes = new HashMap<>();
+ attributes.put(QueueManagingVirtualHost.CONTEXT,
+ objectToJsonString(Collections.singletonMap("queue.defaultAlternateBinding",
+ DEFAULT_ALTERNATE_BINDING)));
+ attributes.put(QueueManagingVirtualHost.NODE_AUTO_CREATION_POLICIES, createAutoCreationPolicies());
+ updateEntityUsingAmqpManagement(getVirtualHostName(), "org.apache.qpid.VirtualHost", attributes);
+ }
+
+ private String createAutoCreationPolicies() throws JsonProcessingException
+ {
+ List<NodeAutoCreationPolicy> objects = Collections.singletonList(new NodeAutoCreationPolicy()
+ {
+ @Override
+ public String getPattern()
+ {
+ return ".*_DLQ";
+ }
+
+ @Override
+ public boolean isCreatedOnPublish()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isCreatedOnConsume()
+ {
+ return false;
+ }
+
+ @Override
+ public String getNodeType()
+ {
+ return "Queue";
+ }
+
+ @Override
+ public Map<String, Object> getAttributes()
+ {
+ return Collections.singletonMap("alternateBinding", "");
+ }
+ });
+ return objectToJsonString(objects);
+ }
+
+ private String objectToJsonString(final Object objects) throws JsonProcessingException
+ {
+ return new ObjectMapper().writeValueAsString(objects);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org