Search in sources :

Example 6 with CommandContext

use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.

the class AMQ3410Test method testNoFactorySet.

public void testNoFactorySet() throws Exception {
    AmqBrowseCommand command = new AmqBrowseCommand();
    CommandContext context = new CommandContext();
    context.setFormatter(new CommandShellOutputFormatter(System.out));
    command.setCommandContext(context);
    List<String> tokens = new ArrayList<>();
    tokens.addAll(DEFAULT_OPTIONS);
    tokens.addAll(DEFAULT_TOKENS);
    command.execute(tokens);
    assertNotNull(command.getConnectionFactory());
    assertTrue(command.getConnectionFactory() instanceof ActiveMQConnectionFactory);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) CommandContext(org.apache.activemq.console.CommandContext) CommandShellOutputFormatter(org.apache.activemq.console.formatter.CommandShellOutputFormatter) ArrayList(java.util.ArrayList)

Example 7 with CommandContext

use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.

the class AMQ3410Test method testFactorySet.

public void testFactorySet() throws Exception {
    AmqBrowseCommand command = new AmqBrowseCommand();
    CommandContext context = new CommandContext();
    context.setFormatter(new CommandShellOutputFormatter(System.out));
    command.setCommandContext(context);
    List<String> tokens = new ArrayList<>();
    tokens.addAll(DEFAULT_OPTIONS);
    tokens.add("--factory");
    tokens.add(DummyConnectionFactory.class.getCanonicalName());
    tokens.addAll(DEFAULT_TOKENS);
    command.execute(tokens);
    assertNotNull(command.getConnectionFactory());
    assertTrue("wrong instance returned: " + command.getConnectionFactory().getClass().getName(), command.getConnectionFactory() instanceof DummyConnectionFactory);
}
Also used : CommandContext(org.apache.activemq.console.CommandContext) CommandShellOutputFormatter(org.apache.activemq.console.formatter.CommandShellOutputFormatter) ArrayList(java.util.ArrayList)

Example 8 with CommandContext

use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.

the class PurgeCommandTest method testPurgeCommandComplexSQLSelector_OR.

public void testPurgeCommandComplexSQLSelector_OR() throws Exception {
    try {
        PurgeCommand purgeCommand = new PurgeCommand();
        CommandContext context = new CommandContext();
        context.setFormatter(new CommandShellOutputFormatter(System.out));
        purgeCommand.setCommandContext(context);
        purgeCommand.setJmxUseLocal(true);
        List<String> tokens = new ArrayList<>();
        tokens.add("--msgsel");
        tokens.add(MSG_SEL_COMPLEX_SQL_OR);
        addMessages();
        validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
        purgeCommand.execute(tokens);
        QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(theQueue, MSG_SEL_COMPLEX_SQL_OR);
        QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
        int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
        int allCount = getMessageCount(allBrowser, "allMessages ");
        withPropertyBrowser.close();
        allBrowser.close();
        assertEquals("Expected withCount to be 0 but was " + withCount, 0, withCount);
        assertEquals("Expected allCount to be 0 but was " + allCount, 0, allCount);
        LOG.info("withCount = " + withCount + "\n allCount = " + allCount + "\n  = " + "\n");
    } finally {
        purgeAllMessages();
    }
}
Also used : CommandContext(org.apache.activemq.console.CommandContext) CommandShellOutputFormatter(org.apache.activemq.console.formatter.CommandShellOutputFormatter) ArrayList(java.util.ArrayList) QueueBrowser(javax.jms.QueueBrowser)

Example 9 with CommandContext

use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.

the class PurgeCommandTest method testPurgeCommandComplexSQLSelector_AND.

public void testPurgeCommandComplexSQLSelector_AND() throws Exception {
    try {
        String one = "ID:mac.fritz.box:1213242.3231.1:1:1:100";
        String two = "\\*:100";
        try {
            if (one.matches(two))
                LOG.info("String matches.");
            else
                LOG.info("string does not match.");
        } catch (Exception ex) {
            LOG.error(ex.getMessage());
        }
        PurgeCommand purgeCommand = new PurgeCommand();
        CommandContext context = new CommandContext();
        context.setFormatter(new CommandShellOutputFormatter(System.out));
        purgeCommand.setCommandContext(context);
        purgeCommand.setJmxUseLocal(true);
        List<String> tokens = new ArrayList<>();
        tokens.add("--msgsel");
        tokens.add(MSG_SEL_COMPLEX_SQL_AND);
        addMessages();
        validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
        purgeCommand.execute(tokens);
        QueueBrowser withPropertyBrowser = requestServerSession.createBrowser(theQueue, MSG_SEL_COMPLEX_SQL_AND);
        QueueBrowser allBrowser = requestServerSession.createBrowser(theQueue);
        int withCount = getMessageCount(withPropertyBrowser, "withProperty ");
        int allCount = getMessageCount(allBrowser, "allMessages ");
        withPropertyBrowser.close();
        allBrowser.close();
        assertEquals("Expected withCount to be " + "0" + " was " + withCount, 0, withCount);
        assertEquals("Expected allCount to be " + MESSAGE_COUNT + " was " + allCount, MESSAGE_COUNT, allCount);
        LOG.info("withCount = " + withCount + "\n allCount = " + allCount + "\n  = " + "\n");
    } finally {
        purgeAllMessages();
    }
}
Also used : CommandContext(org.apache.activemq.console.CommandContext) CommandShellOutputFormatter(org.apache.activemq.console.formatter.CommandShellOutputFormatter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JMSException(javax.jms.JMSException) QueueBrowser(javax.jms.QueueBrowser)

Example 10 with CommandContext

use of org.apache.activemq.console.CommandContext in project activemq-artemis by apache.

the class PurgeCommandTest method testPurgeCommandSimpleSelector.

public void testPurgeCommandSimpleSelector() throws Exception {
    try {
        PurgeCommand purgeCommand = new PurgeCommand();
        CommandContext context = new CommandContext();
        context.setFormatter(new CommandShellOutputFormatter(System.out));
        purgeCommand.setCommandContext(context);
        purgeCommand.setJmxUseLocal(true);
        List<String> tokens = new ArrayList<>();
        tokens.add("--msgsel");
        tokens.add(MSG_SEL_WITH_PROPERTY);
        addMessages();
        validateCounts(MESSAGE_COUNT, MESSAGE_COUNT, MESSAGE_COUNT * 2);
        purgeCommand.execute(tokens);
        validateCounts(0, MESSAGE_COUNT, MESSAGE_COUNT);
    } finally {
        purgeAllMessages();
    }
}
Also used : CommandContext(org.apache.activemq.console.CommandContext) CommandShellOutputFormatter(org.apache.activemq.console.formatter.CommandShellOutputFormatter) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)15 CommandContext (org.apache.activemq.console.CommandContext)15 CommandShellOutputFormatter (org.apache.activemq.console.formatter.CommandShellOutputFormatter)15 QueueBrowser (javax.jms.QueueBrowser)3 IOException (java.io.IOException)2 JMSException (javax.jms.JMSException)2 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1