diff --git a/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js b/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js index 098a6de07c..7b1284018f 100644 --- a/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js +++ b/artemis-hawtio/artemis-plugin/src/main/webapp/plugin/js/components/browse.js @@ -339,7 +339,7 @@ var Artemis; itemField: 'StringProperties', header: 'Original Queue', templateFn: function(value) { - return value._AMQ_ORIG_QUEUE; + return (value['_AMQ_ORIG_QUEUE'] ? value['_AMQ_ORIG_QUEUE'] : value['extraProperties._AMQ_ORIG_QUEUE']); } }; ctrl.tableColumns.push(origQueue); diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/QueuesTest.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/QueuesTest.java index b5db6b16bd..51b30c68c7 100644 --- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/QueuesTest.java +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/QueuesTest.java @@ -17,6 +17,9 @@ package org.apache.activemq.artemis.tests.smoke.console; +import org.apache.activemq.artemis.api.core.RoutingType; +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder; import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.cli.commands.messages.Consumer; import org.apache.activemq.artemis.cli.commands.messages.Producer; @@ -26,11 +29,14 @@ import org.apache.activemq.artemis.tests.smoke.console.pages.QueuePage; import org.apache.activemq.artemis.tests.smoke.console.pages.QueuesPage; import org.apache.activemq.artemis.tests.smoke.console.pages.StatusPage; import org.apache.activemq.artemis.utils.Wait; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.openqa.selenium.MutableCapabilities; +import javax.management.ObjectName; + @RunWith(Parameterized.class) public class QueuesTest extends ConsoleTest { @@ -101,4 +107,61 @@ public class QueuesTest extends ConsoleTest { Wait.assertEquals(1, () -> afterQueuesPage.countQueue("DLQ")); Wait.assertEquals(0, () -> afterQueuesPage.getMessagesCount(queueName)); } + + @Test + public void testExpiryQueue() throws Exception { + final int messages = 1; + final String expiryQueueName = "ExpiryQueue"; + final String testQueueName = "TEST"; + final String messageText = "TEST"; + final ObjectNameBuilder objectNameBuilder = ObjectNameBuilder.create(null, "0.0.0.0", true); + final ObjectName expiryQueueObjectName = objectNameBuilder.getQueueObjectName( + SimpleString.toSimpleString(expiryQueueName), + SimpleString.toSimpleString(expiryQueueName), + RoutingType.ANYCAST); + final ObjectName testQueueObjectName = objectNameBuilder.getQueueObjectName( + SimpleString.toSimpleString(testQueueName), + SimpleString.toSimpleString(testQueueName), + RoutingType.ANYCAST); + + driver.get(serverUrl + "/console"); + LoginPage loginPage = new LoginPage(driver); + StatusPage statusPage = loginPage.loginValidUser( + SERVER_ADMIN_USERNAME, SERVER_ADMIN_PASSWORD, DEFAULT_TIMEOUT); + Assert.assertTrue(statusPage.postJolokiaExecRequest(expiryQueueObjectName.getCanonicalName(), + "removeAllMessages()", "").toString().contains("\"status\":200")); + + QueuesPage beforeQueuesPage = statusPage.getQueuesPage(DEFAULT_TIMEOUT); + Wait.assertEquals(1, () -> beforeQueuesPage.countQueue("ExpiryQueue")); + Wait.assertEquals(0, () -> beforeQueuesPage.countQueue(testQueueName)); + + Producer producer = new Producer(); + producer.setUser(SERVER_ADMIN_USERNAME); + producer.setPassword(SERVER_ADMIN_PASSWORD); + producer.setDestination(testQueueName); + producer.setMessageCount(messages); + producer.setMessage(messageText); + producer.setSilentInput(true); + producer.setProtocol("amqp"); + producer.execute(new ActionContext()); + + beforeQueuesPage.refresh(DEFAULT_TIMEOUT); + Wait.assertEquals(1, () -> beforeQueuesPage.countQueue(expiryQueueName)); + assertEquals(0, beforeQueuesPage.getMessagesCount(expiryQueueName)); + Wait.assertEquals(1, () -> beforeQueuesPage.countQueue(testQueueName)); + assertEquals(messages, beforeQueuesPage.getMessagesCount(testQueueName)); + + QueuePage queuePage = beforeQueuesPage.getQueuePage(testQueueName, DEFAULT_TIMEOUT); + Assert.assertTrue(queuePage.postJolokiaExecRequest(testQueueObjectName.getCanonicalName(), "expireMessage(long)", + String.valueOf(queuePage.getMessageId(0))).toString().contains("\"status\":200")); + + QueuesPage afterQueuesPage = queuePage.getQueuesPage(DEFAULT_TIMEOUT); + Wait.assertEquals(1, () -> afterQueuesPage.countQueue(expiryQueueName)); + assertEquals(messages, afterQueuesPage.getMessagesCount(expiryQueueName)); + Wait.assertEquals(1, () -> beforeQueuesPage.countQueue(testQueueName)); + assertEquals(0, afterQueuesPage.getMessagesCount(testQueueName)); + + QueuePage dlqPage = afterQueuesPage.getQueuePage(expiryQueueName, DEFAULT_TIMEOUT); + assertEquals(testQueueName, dlqPage.getMessageOriginalQueue(0)); + } } diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/ArtemisPage.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/ArtemisPage.java index 26ac432be3..00781296d0 100644 --- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/ArtemisPage.java +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/ArtemisPage.java @@ -21,7 +21,9 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.activemq.artemis.utils.StringEscapeUtils; import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -75,4 +77,21 @@ public abstract class ArtemisPage extends ConsolePage { return new QueuesPage(driver); } + + public Object postJolokiaExecRequest(String mbean, String operation, String arguments) { + Object response = ((JavascriptExecutor) driver).executeAsyncScript( + "var callback = arguments[arguments.length - 1];" + + "var xhr = new XMLHttpRequest();" + + "xhr.open('POST', '/console/jolokia', true);" + + "xhr.onreadystatechange = function() {" + + " if (xhr.readyState == 4) {" + + " callback(xhr.responseText);" + + " }" + + "};" + + "xhr.send('{\"type\":\"exec\",\"mbean\":\"" + StringEscapeUtils.escapeString(StringEscapeUtils.escapeString(mbean)) + + "\",\"operation\":\"" + StringEscapeUtils.escapeString(StringEscapeUtils.escapeString(operation)) + + "\",\"arguments\":[" + StringEscapeUtils.escapeString(arguments) + "]}');"); + + return response; + } } diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/QueuePage.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/QueuePage.java index 30d2e6dc89..96692149f1 100644 --- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/QueuePage.java +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/pages/QueuePage.java @@ -19,8 +19,13 @@ package org.apache.activemq.artemis.tests.smoke.console.pages; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; public class QueuePage extends ArtemisPage { + private By messageRowLocator = By.cssSelector("tr[role='row'][class='ng-scope odd']"); + public QueuePage(WebDriver driver) { super(driver); } @@ -32,4 +37,35 @@ public class QueuePage extends ArtemisPage { return new MessagePage(driver); } + + public long getMessageId(int index) { + WebElement messageRowWebElement = driver.findElements(messageRowLocator).get(index); + + String messageIdText = messageRowWebElement.findElements(By.tagName("td")).get( + getIndexOfColumn("Message ID")).findElement(By.tagName("span")).getText(); + + return Long.parseLong(messageIdText); + } + + public String getMessageOriginalQueue(int index) { + WebElement messageRowWebElement = driver.findElements(messageRowLocator).get(index); + + String messageOriginalQueue = messageRowWebElement.findElements(By.tagName("td")).get( + getIndexOfColumn("Original Queue")).findElement(By.tagName("span")).getText(); + + return messageOriginalQueue; + } + + public int getIndexOfColumn(String name) { + WebElement headerRowWebElement = driver.findElement(By.cssSelector("tr[role='row']")); + + List columnWebElements = headerRowWebElement.findElements(By.tagName("th")); + for (int i = 0; i < columnWebElements.size(); i++) { + if (name.equals(columnWebElements.get(i).getText())) { + return i; + } + } + + return -1; + } }