use of org.apache.activemq.artemis.cli.commands.queue.StatQueue in project activemq-artemis by apache.
the class ArtemisTest method testQstat.
@Test
public void testQstat() throws Exception {
File instanceQstat = new File(temporaryFolder.getRoot(), "instanceQStat");
setupAuth(instanceQstat);
Run.setEmbedded(true);
Artemis.main("create", instanceQstat.getAbsolutePath(), "--silent", "--no-fsync", "--no-autotune", "--no-web", "--require-login");
System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
Artemis.internalExecute("run");
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection("admin", "admin")) {
// set up some queues with messages and consumers
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
sendMessages(session, "Test1", 15);
sendMessages(session, "Test11", 1);
sendMessages(session, "Test12", 1);
sendMessages(session, "Test20", 20);
MessageConsumer consumer = session.createConsumer(ActiveMQDestination.createDestination("queue://Test1", ActiveMQDestination.TYPE.QUEUE));
MessageConsumer consumer2 = session.createConsumer(ActiveMQDestination.createDestination("queue://Test1", ActiveMQDestination.TYPE.QUEUE));
for (int i = 0; i < 5; i++) {
Message message = consumer.receive(100);
}
// check all queues containing "Test1" are displayed
TestActionContext context = new TestActionContext();
StatQueue statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test1");
statQueue.execute(context);
ArrayList<String> lines = getOutputLines(context, false);
// Header line + 3 queues
Assert.assertEquals("rows returned using queueName=Test1", 4, lines.size());
// check all queues are displayed when no Filter set
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 4 queues (at least - possibly other infra queues as well)
Assert.assertTrue("rows returned filtering no name ", 5 <= lines.size());
// check all queues containing "Test1" are displayed using Filter field NAME
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("NAME");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("Test1");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 3 queues
Assert.assertEquals("rows returned filtering by NAME ", 4, lines.size());
// check only queue named "Test1" is displayed using Filter field NAME and operation EQUALS
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("NAME");
statQueue.setOperationName("EQUALS");
statQueue.setValue("Test1");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 1 queue only
Assert.assertEquals("rows returned filtering by NAME operation EQUALS", 2, lines.size());
// verify contents of queue stat line is correct
String queueTest1 = lines.get(1);
String[] parts = queueTest1.split("\\|");
Assert.assertEquals("queue name", "Test1", parts[1].trim());
Assert.assertEquals("address name", "Test1", parts[2].trim());
Assert.assertEquals("Consumer count", "2", parts[3].trim());
Assert.assertEquals("Message count", "10", parts[4].trim());
Assert.assertEquals("Added count", "15", parts[5].trim());
Assert.assertEquals("Delivering count", "10", parts[6].trim());
Assert.assertEquals("Acked count", "5", parts[7].trim());
// check all queues containing address "Test1" are displayed using Filter field ADDRESS
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("ADDRESS");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("Test1");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 3 queues
Assert.assertEquals("rows returned filtering by ADDRESS", 4, lines.size());
// check all queues containing address "Test1" are displayed using Filter field MESSAGE_COUNT
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGE_COUNT");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("10");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queues
Assert.assertEquals("rows returned filtering by MESSAGE_COUNT", 1, lines.size());
// check all queues containing address "Test1" are displayed using Filter field MESSAGE_ADDED
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ADDED");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("20");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queues
Assert.assertEquals("rows returned filtering by MESSAGES_ADDED", 1, lines.size());
// check queues with greater_than 19 MESSAGE_ADDED displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ADDED");
statQueue.setOperationName("GREATER_THAN");
statQueue.setValue("19");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by MESSAGES_ADDED", 2, lines.size());
String[] columns = lines.get(1).split("\\|");
Assert.assertEquals("queue name filtered by MESSAGES_ADDED GREATER_THAN ", "Test20", columns[2].trim());
// check queues with less_than 2 MESSAGE_ADDED displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ADDED");
statQueue.setOperationName("LESS_THAN");
statQueue.setValue("2");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + "at least" 2 queues
Assert.assertTrue("rows returned filtering by MESSAGES_ADDED LESS_THAN", 2 <= lines.size());
// walk the result returned and the specific destinations are not part of the output
for (String line : lines) {
columns = line.split("\\|");
Assert.assertNotEquals("ensure Test20 is not part of returned result", "Test20", columns[2].trim());
Assert.assertNotEquals("ensure Test1 is not part of returned result", "Test1", columns[2].trim());
}
// check all queues containing address "Test1" are displayed using Filter field DELIVERING_COUNT
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("DELIVERING_COUNT");
statQueue.setOperationName("EQUALS");
statQueue.setValue("10");
statQueue.execute(context);
lines = getOutputLines(context, false);
columns = lines.get(1).split("\\|");
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by DELIVERING_COUNT", 2, lines.size());
Assert.assertEquals("queue name filtered by DELIVERING_COUNT ", "Test1", columns[2].trim());
// check all queues containing address "Test1" are displayed using Filter field CONSUMER_COUNT
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("CONSUMER_COUNT");
statQueue.setOperationName("EQUALS");
statQueue.setValue("2");
statQueue.execute(context);
lines = getOutputLines(context, false);
columns = lines.get(1).split("\\|");
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by CONSUMER_COUNT ", 2, lines.size());
Assert.assertEquals("queue name filtered by CONSUMER_COUNT ", "Test1", columns[2].trim());
// check all queues containing address "Test1" are displayed using Filter field MESSAGE_ACKED
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ACKED");
statQueue.setOperationName("EQUALS");
statQueue.setValue("5");
statQueue.execute(context);
lines = getOutputLines(context, false);
columns = lines.get(1).split("\\|");
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by MESSAGE_ACKED ", 2, lines.size());
Assert.assertEquals("queue name filtered by MESSAGE_ACKED", "Test1", columns[2].trim());
// check no queues are displayed when name does not match
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("no_queue_name");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queues
Assert.assertEquals("rows returned by queueName for no Matching queue ", 1, lines.size());
// check maxrows is taking effect"
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test1");
statQueue.setMaxRows(1);
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 1 queue only
Assert.assertEquals("rows returned by maxRows=1", 2, lines.size());
} finally {
stopServer();
}
}
use of org.apache.activemq.artemis.cli.commands.queue.StatQueue in project activemq-artemis by apache.
the class ArtemisTest method testQstatErrors.
@Test
public void testQstatErrors() throws Exception {
File instanceQstat = new File(temporaryFolder.getRoot(), "instanceQStatErrors");
setupAuth(instanceQstat);
Run.setEmbedded(true);
Artemis.main("create", instanceQstat.getAbsolutePath(), "--silent", "--no-fsync", "--no-autotune", "--no-web", "--require-login");
System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
Artemis.internalExecute("run");
try {
// check err when FIELD wrong"
TestActionContext context = new TestActionContext();
StatQueue statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("WRONG_FILE");
statQueue.setOperationName("EQUALS");
statQueue.setValue("5");
statQueue.execute(context);
ArrayList<String> lines = getOutputLines(context, false);
// Header line + 0 queue
Assert.assertEquals("No stdout for wrong FIELD", 0, lines.size());
lines = getOutputLines(context, true);
// 1 error line
Assert.assertEquals("stderr for wrong FIELD", 1, lines.size());
Assert.assertTrue("'FIELD incorrect' error messsage", lines.get(0).contains("'--field' must be set to one of the following"));
// Test err when OPERATION wrong
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGE_COUNT");
statQueue.setOperationName("WRONG_OPERATION");
statQueue.setValue("5");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queue
Assert.assertEquals("No stdout for wrong OPERATION", 0, lines.size());
lines = getOutputLines(context, true);
// 1 error line
Assert.assertEquals("stderr for wrong OPERATION", 1, lines.size());
Assert.assertTrue("'OPERATION incorrect' error message", lines.get(0).contains("'--operation' must be set to one of the following"));
// Test err when queueName and field set together
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("DLQ");
statQueue.setFieldName("MESSAGE_COUNT");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("5");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queue
Assert.assertEquals("No stdout for --field and --queueName both set", 0, lines.size());
lines = getOutputLines(context, true);
// 1 error line
Assert.assertEquals("stderr for --field and --queueName both set", 1, lines.size());
Assert.assertTrue("field and queueName error message", lines.get(0).contains("'--field' and '--queueName' cannot be specified together"));
// Test err when field set but no value
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGE_COUNT");
statQueue.setOperationName("CONTAINS");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queue
Assert.assertEquals("No stdout for --field set BUT no --value", 0, lines.size());
lines = getOutputLines(context, true);
// 1 error line
Assert.assertEquals("stderr for --field set BUT no --value", 1, lines.size());
Assert.assertTrue("NO VALUE error message", lines.get(0).contains("'--value' needs to be set when '--field' is specified"));
// Test err when field set but no operation
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGE_COUNT");
statQueue.setValue("5");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queue
Assert.assertEquals("No stdout for --field set BUT no --operation", 0, lines.size());
lines = getOutputLines(context, true);
// 1 error line
Assert.assertEquals("stderr for --field set BUT no --operation", 1, lines.size());
Assert.assertTrue("OPERATION incorrect error message", lines.get(0).contains("'--operation' must be set when '--field' is specified "));
} finally {
stopServer();
}
}
Aggregations