Repository: activemq-artemis Updated Branches: refs/heads/master 048173d0e -> 6a59443d2
simply renaming parameters on CLI Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/63a17adb Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/63a17adb Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/63a17adb Branch: refs/heads/master Commit: 63a17adbdfff6e791e14c50541d27ee394c927d7 Parents: 048173d Author: Clebert Suconic <[email protected]> Authored: Fri Jun 26 11:01:24 2015 -0400 Committer: Clebert Suconic <[email protected]> Committed: Fri Jun 26 11:42:50 2015 -0400 ---------------------------------------------------------------------- .../activemq/artemis/cli/commands/Browse.java | 10 +- .../activemq/artemis/cli/commands/Consumer.java | 8 +- .../artemis/cli/commands/DestAbstract.java | 4 +- .../activemq/artemis/cli/commands/Producer.java | 8 +- .../activemq/artemis/test/ArtemisTest.java | 134 ------------------- .../activemq/artemis/test/FileBrokerTest.java | 81 ----------- .../artemis/test/StreamClassPathTest.java | 62 --------- .../apache/activemq/cli/test/ArtemisTest.java | 134 +++++++++++++++++++ .../activemq/cli/test/FileBrokerTest.java | 81 +++++++++++ .../activemq/cli/test/StreamClassPathTest.java | 62 +++++++++ .../artemis/test/WebServerComponentTest.java | 128 ------------------ .../cli/test/WebServerComponentTest.java | 128 ++++++++++++++++++ 12 files changed, 420 insertions(+), 420 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java index 614ab6c..db26cdb 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java @@ -17,17 +17,17 @@ package org.apache.activemq.artemis.cli.commands; -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.Session; - import io.airlift.airline.Command; import io.airlift.airline.Option; import org.apache.activemq.artemis.cli.commands.util.ConsumerThread; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; -@Command(name = "browse", description = "It will send consume messages from an instance") +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.Session; + +@Command(name = "browser", description = "It will send consume messages from an instance") public class Browse extends DestAbstract { @Option(name = "--filter", description = "filter to be used with the consumer") http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java index 77d9643..9c6f433 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java @@ -27,7 +27,7 @@ import org.apache.activemq.artemis.cli.commands.util.ConsumerThread; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; -@Command(name = "consume", description = "It will send consume messages from an instance") +@Command(name = "consumer", description = "It will send consume messages from an instance") public class Consumer extends DestAbstract { @@ -35,11 +35,11 @@ public class Consumer extends DestAbstract @Option(name = "--durable", description = "It will use durable subscription in case of client") boolean durable = false; - @Option(name = "--breakOnNull", description = "It will break on null messages") + @Option(name = "--break-on-null", description = "It will break on null messages") boolean breakOnNull = false; - @Option(name = "--receiveTimeout", description = "Time used on receive(timeout)") - int receiveTimeout; + @Option(name = "--receive-timeout", description = "Time used on receive(timeout)") + int receiveTimeout = 3000; @Option(name = "--filter", description = "filter to be used with the consumer") String filter; http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java index e8f7b58..402f0d9 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java @@ -27,7 +27,7 @@ public class DestAbstract extends ActionAbstract @Option(name = "--destination", description = "Destination to be used. it could be prefixed with queue:// or topic:: (Default: queue://TEST") String destination = "queue://TEST"; - @Option(name = "--messageCount", description = "Number of messages to act on (Default: 1000)") + @Option(name = "--message-count", description = "Number of messages to act on (Default: 1000)") int messageCount = 1000; @Option(name = "--user", description = "User used to connect") @@ -39,7 +39,7 @@ public class DestAbstract extends ActionAbstract @Option(name = "--sleep", description = "Time wait between each message") int sleep = 0; - @Option(name = "--txSize", description = "TX Batch Size") + @Option(name = "--txt-size", description = "TX Batch Size") int txBatchSize; @Option(name = "--threads", description = "Number of Threads to be used (Default: 1)") http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java index 96c1331..2819436 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java @@ -27,17 +27,17 @@ import org.apache.activemq.artemis.cli.commands.util.ProducerThread; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; -@Command(name = "produce", description = "It will send messages to an instance") +@Command(name = "producer", description = "It will send messages to an instance") public class Producer extends DestAbstract { - @Option(name = "--nonPersistent", description = "It will send messages non persistently") + @Option(name = "--non-persistent", description = "It will send messages non persistently") boolean nonpersistent = false; - @Option(name = "--messageSize", description = "Size of each byteMessage (The producer will use byte message on this case)") + @Option(name = "--message-size", description = "Size of each byteMessage (The producer will use byte message on this case)") int messageSize = 0; - @Option(name = "--textSize", description = "Size of each textNessage (The producer will use text message on this case)") + @Option(name = "--text-size", description = "Size of each textNessage (The producer will use text message on this case)") int textMessageSize; @Option(name = "--msgttl", description = "TTL for each message") http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java b/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java deleted file mode 100644 index 595a246..0000000 --- a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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.activemq.artemis.test; - -import javax.jms.Connection; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; -import java.io.File; -import java.util.concurrent.TimeUnit; - -import org.apache.activemq.artemis.cli.Artemis; -import org.apache.activemq.artemis.cli.commands.Run; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; -import org.junit.After; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -/** - * Test to validate that the CLI doesn't throw improper exceptions when invoked. - */ -public class ArtemisTest -{ - @Rule - public TemporaryFolder temporaryFolder; - - public ArtemisTest() - { - File parent = new File("./target/tmp"); - parent.mkdirs(); - temporaryFolder = new TemporaryFolder(parent); - } - - - @After - public void cleanup() - { - System.clearProperty("artemis.instance"); - Run.setEmbedded(false); - } - - @Test - public void invalidCliDoesntThrowException() - { - testCli("create"); - } - - @Test - public void invalidPathDoesntThrowException() - { - testCli("create","/rawr"); - } - - @Test - public void testSimpleRun() throws Exception - { - Run.setEmbedded(true); - Artemis.main("create", temporaryFolder.getRoot().getAbsolutePath(), "--force", "--silent-input", "--no-web"); - System.setProperty("artemis.instance", temporaryFolder.getRoot().getAbsolutePath()); - // Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol - Artemis.main("run"); - Assert.assertEquals(Integer.valueOf(70), Artemis.execute("produce", "--txSize", "50", "--messageCount", "70", "--verbose")); - Assert.assertEquals(Integer.valueOf(70), Artemis.execute("consume", "--txSize", "50", "--verbose", "--breakOnNull", "--receiveTimeout", "100")); - - ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); - Connection connection = cf.createConnection(); - Session session = connection.createSession(true, Session.SESSION_TRANSACTED); - MessageProducer producer = session.createProducer(ActiveMQDestination.createDestination("queue://TEST", ActiveMQDestination.QUEUE_TYPE)); - - TextMessage message = session.createTextMessage("Banana"); - message.setStringProperty("fruit", "banana"); - producer.send(message); - - for (int i = 0; i < 100; i++) - { - message = session.createTextMessage("orange"); - message.setStringProperty("fruit", "orange"); - producer.send(message); - } - session.commit(); - - connection.close(); - cf.close(); - - Assert.assertEquals(Integer.valueOf(1), Artemis.execute("browse", "--txSize", "50", "--verbose", "--filter", "fruit='banana'")); - - Assert.assertEquals(Integer.valueOf(100), Artemis.execute("browse", "--txSize", "50", "--verbose", "--filter", "fruit='orange'")); - - Assert.assertEquals(Integer.valueOf(101), Artemis.execute("browse", "--txSize", "50", "--verbose")); - - // should only receive 10 messages on browse as I'm setting messageCount=10 - Assert.assertEquals(Integer.valueOf(10), Artemis.execute("browse", "--txSize", "50", "--verbose", "--messageCount", "10")); - - // Nothing was consumed until here as it was only browsing, check it's receiving again - Assert.assertEquals(Integer.valueOf(1), Artemis.execute("consume", "--txSize", "50", "--verbose", "--breakOnNull", "--receiveTimeout", "100", "--filter", "fruit='banana'")); - - // Checking it was acked before - Assert.assertEquals(Integer.valueOf(100), Artemis.execute("consume", "--txSize", "50", "--verbose", "--breakOnNull", "--receiveTimeout", "100")); - - Artemis.execute("stop"); - Assert.assertTrue(Run.latchRunning.await(5, TimeUnit.SECONDS)); - - } - - private void testCli(String... args) - { - try - { - Artemis.main(args); - } - catch (Exception e) - { - e.printStackTrace(); - Assert.fail("Exception caught " + e.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/test/java/org/apache/activemq/artemis/test/FileBrokerTest.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/FileBrokerTest.java b/artemis-cli/src/test/java/org/apache/activemq/artemis/test/FileBrokerTest.java deleted file mode 100644 index bdbd562..0000000 --- a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/FileBrokerTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.activemq.artemis.test; - -import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; -import org.apache.activemq.artemis.dto.ServerDTO; -import org.apache.activemq.artemis.integration.FileBroker; -import org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl; -import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManagerImpl; -import org.junit.Assert; -import org.junit.Test; - -public class FileBrokerTest -{ - @Test - public void startWithJMS() throws Exception - { - ServerDTO serverDTO = new ServerDTO(); - serverDTO.configuration = "broker.xml"; - FileBroker broker = null; - try - { - broker = new FileBroker(serverDTO, new ActiveMQSecurityManagerImpl()); - broker.start(); - JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms"); - Assert.assertNotNull(jmsServerManager); - Assert.assertTrue(jmsServerManager.isStarted()); - //this tells us the jms server is activated - Assert.assertTrue(jmsServerManager.getJMSStorageManager().isStarted()); - ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core"); - Assert.assertNotNull(activeMQServer); - Assert.assertTrue(activeMQServer.isStarted()); - Assert.assertTrue(broker.isStarted()); - } - finally - { - if (broker != null) - { - broker.stop(); - } - } - } - - @Test - public void startWithoutJMS() throws Exception - { - ServerDTO serverDTO = new ServerDTO(); - serverDTO.configuration = "broker-nojms.xml"; - FileBroker broker = null; - try - { - broker = new FileBroker(serverDTO, new ActiveMQSecurityManagerImpl()); - broker.start(); - JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms"); - Assert.assertNull(jmsServerManager); - ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core"); - Assert.assertNotNull(activeMQServer); - Assert.assertTrue(activeMQServer.isStarted()); - Assert.assertTrue(broker.isStarted()); - } - finally - { - assert broker != null; - broker.stop(); - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/test/java/org/apache/activemq/artemis/test/StreamClassPathTest.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/StreamClassPathTest.java b/artemis-cli/src/test/java/org/apache/activemq/artemis/test/StreamClassPathTest.java deleted file mode 100644 index 98b4066..0000000 --- a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/StreamClassPathTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.activemq.artemis.test; - -import java.io.InputStream; - -import org.apache.activemq.artemis.cli.commands.Create; -import org.junit.Assert; -import org.junit.Test; - -public class StreamClassPathTest -{ - - /** Validate if all the known resources are available on the classpath for the jar */ - @Test - public void testFindStreams() throws Exception - { - openStream(Create.BIN_ARTEMIS_CMD); - openStream(Create.BIN_ARTEMIS_SERVICE_EXE); - openStream(Create.BIN_ARTEMIS_SERVICE_XML); - openStream(Create.ETC_ARTEMIS_PROFILE_CMD); - openStream(Create.BIN_ARTEMIS); - openStream(Create.BIN_ARTEMIS_SERVICE); - openStream(Create.ETC_ARTEMIS_PROFILE); - openStream(Create.ETC_LOGGING_PROPERTIES); - openStream(Create.ETC_BOOTSTRAP_XML); - openStream(Create.ETC_BROKER_XML); - openStream(Create.ETC_ARTEMIS_ROLES_PROPERTIES); - openStream(Create.ETC_ARTEMIS_USERS_PROPERTIES); - openStream(Create.ETC_REPLICATED_SETTINGS_TXT); - openStream(Create.ETC_REPLICATED_SETTINGS_TXT); - openStream(Create.ETC_SHARED_STORE_SETTINGS_TXT); - openStream(Create.ETC_CLUSTER_SECURITY_SETTINGS_TXT); - openStream(Create.ETC_CLUSTER_SETTINGS_TXT); - openStream(Create.ETC_CONNECTOR_SETTINGS_TXT); - openStream(Create.ETC_BOOTSTRAP_WEB_SETTINGS_TXT); - } - - - private void openStream(String source) throws Exception - { - Create create = new Create(); - InputStream in = create.openStream(source); - Assert.assertNotNull(source + " not found", in); - in.close(); - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java new file mode 100644 index 0000000..99c8f23 --- /dev/null +++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java @@ -0,0 +1,134 @@ +/* + * 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.activemq.cli.test; + +import javax.jms.Connection; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; +import java.io.File; +import java.util.concurrent.TimeUnit; + +import org.apache.activemq.artemis.cli.Artemis; +import org.apache.activemq.artemis.cli.commands.Run; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQDestination; +import org.junit.After; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Test to validate that the CLI doesn't throw improper exceptions when invoked. + */ +public class ArtemisTest +{ + @Rule + public TemporaryFolder temporaryFolder; + + public ArtemisTest() + { + File parent = new File("./target/tmp"); + parent.mkdirs(); + temporaryFolder = new TemporaryFolder(parent); + } + + + @After + public void cleanup() + { + System.clearProperty("artemis.instance"); + Run.setEmbedded(false); + } + + @Test + public void invalidCliDoesntThrowException() + { + testCli("create"); + } + + @Test + public void invalidPathDoesntThrowException() + { + testCli("create","/rawr"); + } + + @Test + public void testSimpleRun() throws Exception + { + Run.setEmbedded(true); + Artemis.main("create", temporaryFolder.getRoot().getAbsolutePath(), "--force", "--silent-input", "--no-web"); + System.setProperty("artemis.instance", temporaryFolder.getRoot().getAbsolutePath()); + // Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol + Artemis.main("run"); + Assert.assertEquals(Integer.valueOf(70), Artemis.execute("producer", "--txt-size", "50", "--message-count", "70", "--verbose")); + Assert.assertEquals(Integer.valueOf(70), Artemis.execute("consumer", "--txt-size", "50", "--verbose", "--break-on-null", "--receive-timeout", "100")); + + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); + Connection connection = cf.createConnection(); + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + MessageProducer producer = session.createProducer(ActiveMQDestination.createDestination("queue://TEST", ActiveMQDestination.QUEUE_TYPE)); + + TextMessage message = session.createTextMessage("Banana"); + message.setStringProperty("fruit", "banana"); + producer.send(message); + + for (int i = 0; i < 100; i++) + { + message = session.createTextMessage("orange"); + message.setStringProperty("fruit", "orange"); + producer.send(message); + } + session.commit(); + + connection.close(); + cf.close(); + + Assert.assertEquals(Integer.valueOf(1), Artemis.execute("browser", "--txt-size", "50", "--verbose", "--filter", "fruit='banana'")); + + Assert.assertEquals(Integer.valueOf(100), Artemis.execute("browser", "--txt-size", "50", "--verbose", "--filter", "fruit='orange'")); + + Assert.assertEquals(Integer.valueOf(101), Artemis.execute("browser", "--txt-size", "50", "--verbose")); + + // should only receive 10 messages on browse as I'm setting messageCount=10 + Assert.assertEquals(Integer.valueOf(10), Artemis.execute("browser", "--txt-size", "50", "--verbose", "--message-count", "10")); + + // Nothing was consumed until here as it was only browsing, check it's receiving again + Assert.assertEquals(Integer.valueOf(1), Artemis.execute("consumer", "--txt-size", "50", "--verbose", "--break-on-null", "--receive-timeout", "100", "--filter", "fruit='banana'")); + + // Checking it was acked before + Assert.assertEquals(Integer.valueOf(100), Artemis.execute("consumer", "--txt-size", "50", "--verbose", "--break-on-null", "--receive-timeout", "100")); + + Artemis.execute("stop"); + Assert.assertTrue(Run.latchRunning.await(5, TimeUnit.SECONDS)); + + } + + private void testCli(String... args) + { + try + { + Artemis.main(args); + } + catch (Exception e) + { + e.printStackTrace(); + Assert.fail("Exception caught " + e.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java new file mode 100644 index 0000000..5d86f6e --- /dev/null +++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java @@ -0,0 +1,81 @@ +/* + * 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.activemq.cli.test; + +import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; +import org.apache.activemq.artemis.dto.ServerDTO; +import org.apache.activemq.artemis.integration.FileBroker; +import org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl; +import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManagerImpl; +import org.junit.Assert; +import org.junit.Test; + +public class FileBrokerTest +{ + @Test + public void startWithJMS() throws Exception + { + ServerDTO serverDTO = new ServerDTO(); + serverDTO.configuration = "broker.xml"; + FileBroker broker = null; + try + { + broker = new FileBroker(serverDTO, new ActiveMQSecurityManagerImpl()); + broker.start(); + JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms"); + Assert.assertNotNull(jmsServerManager); + Assert.assertTrue(jmsServerManager.isStarted()); + //this tells us the jms server is activated + Assert.assertTrue(jmsServerManager.getJMSStorageManager().isStarted()); + ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core"); + Assert.assertNotNull(activeMQServer); + Assert.assertTrue(activeMQServer.isStarted()); + Assert.assertTrue(broker.isStarted()); + } + finally + { + if (broker != null) + { + broker.stop(); + } + } + } + + @Test + public void startWithoutJMS() throws Exception + { + ServerDTO serverDTO = new ServerDTO(); + serverDTO.configuration = "broker-nojms.xml"; + FileBroker broker = null; + try + { + broker = new FileBroker(serverDTO, new ActiveMQSecurityManagerImpl()); + broker.start(); + JMSServerManagerImpl jmsServerManager = (JMSServerManagerImpl) broker.getComponents().get("jms"); + Assert.assertNull(jmsServerManager); + ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core"); + Assert.assertNotNull(activeMQServer); + Assert.assertTrue(activeMQServer.isStarted()); + Assert.assertTrue(broker.isStarted()); + } + finally + { + assert broker != null; + broker.stop(); + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-cli/src/test/java/org/apache/activemq/cli/test/StreamClassPathTest.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/StreamClassPathTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/StreamClassPathTest.java new file mode 100644 index 0000000..632e2c0 --- /dev/null +++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/StreamClassPathTest.java @@ -0,0 +1,62 @@ +/* + * 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.activemq.cli.test; + +import java.io.InputStream; + +import org.apache.activemq.artemis.cli.commands.Create; +import org.junit.Assert; +import org.junit.Test; + +public class StreamClassPathTest +{ + + /** Validate if all the known resources are available on the classpath for the jar */ + @Test + public void testFindStreams() throws Exception + { + openStream(Create.BIN_ARTEMIS_CMD); + openStream(Create.BIN_ARTEMIS_SERVICE_EXE); + openStream(Create.BIN_ARTEMIS_SERVICE_XML); + openStream(Create.ETC_ARTEMIS_PROFILE_CMD); + openStream(Create.BIN_ARTEMIS); + openStream(Create.BIN_ARTEMIS_SERVICE); + openStream(Create.ETC_ARTEMIS_PROFILE); + openStream(Create.ETC_LOGGING_PROPERTIES); + openStream(Create.ETC_BOOTSTRAP_XML); + openStream(Create.ETC_BROKER_XML); + openStream(Create.ETC_ARTEMIS_ROLES_PROPERTIES); + openStream(Create.ETC_ARTEMIS_USERS_PROPERTIES); + openStream(Create.ETC_REPLICATED_SETTINGS_TXT); + openStream(Create.ETC_REPLICATED_SETTINGS_TXT); + openStream(Create.ETC_SHARED_STORE_SETTINGS_TXT); + openStream(Create.ETC_CLUSTER_SECURITY_SETTINGS_TXT); + openStream(Create.ETC_CLUSTER_SETTINGS_TXT); + openStream(Create.ETC_CONNECTOR_SETTINGS_TXT); + openStream(Create.ETC_BOOTSTRAP_WEB_SETTINGS_TXT); + } + + + private void openStream(String source) throws Exception + { + Create create = new Create(); + InputStream in = create.openStream(source); + Assert.assertNotNull(source + " not found", in); + in.close(); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java ---------------------------------------------------------------------- diff --git a/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java b/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java deleted file mode 100644 index dafd14e..0000000 --- a/artemis-web/src/test/java/org/apache/activemq/artemis/test/WebServerComponentTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.activemq.artemis.test; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import io.netty.bootstrap.Bootstrap; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.handler.codec.http.DefaultFullHttpRequest; -import io.netty.handler.codec.http.HttpClientCodec; -import io.netty.handler.codec.http.HttpContent; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpObject; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpVersion; -import io.netty.util.CharsetUtil; -import org.apache.activemq.artemis.component.WebServerComponent; -import org.apache.activemq.artemis.dto.WebServerDTO; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class WebServerComponentTest extends Assert -{ - static final String URL = System.getProperty("url", "http://localhost:8161/WebServerComponentTest.txt"); - private Bootstrap bootstrap; - private EventLoopGroup group; - - @Before - public void setupNetty() throws URISyntaxException - { - // Configure the client. - group = new NioEventLoopGroup(); - bootstrap = new Bootstrap(); - } - @Test - public void simpleServer() throws Exception - { - WebServerDTO webServerDTO = new WebServerDTO(); - webServerDTO.bind = "http://localhost:8161"; - webServerDTO.path = "webapps"; - WebServerComponent webServerComponent = new WebServerComponent(); - Assert.assertFalse(webServerComponent.isStarted()); - webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); - webServerComponent.start(); - // Make the connection attempt. - CountDownLatch latch = new CountDownLatch(1); - final ClientHandler clientHandler = new ClientHandler(latch); - bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer() - { - @Override - protected void initChannel(Channel ch) throws Exception - { - ch.pipeline().addLast(new HttpClientCodec()); - ch.pipeline().addLast(clientHandler); - } - }); - Channel ch = bootstrap.connect("localhost", 8161).sync().channel(); - - URI uri = new URI(URL); - // Prepare the HTTP request. - HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath()); - request.headers().set(HttpHeaders.Names.HOST, "localhost"); - - - // Send the HTTP request. - ch.writeAndFlush(request); - assertTrue(latch.await(5, TimeUnit.SECONDS)); - assertEquals(clientHandler.body, "12345"); - // Wait for the server to close the connection. - ch.close(); - Assert.assertTrue(webServerComponent.isStarted()); - webServerComponent.stop(); - Assert.assertFalse(webServerComponent.isStarted()); - } - - class ClientHandler extends SimpleChannelInboundHandler<HttpObject> - { - private CountDownLatch latch; - private String body; - - public ClientHandler(CountDownLatch latch) - { - this.latch = latch; - } - - @Override - public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) - { - if (msg instanceof HttpContent) - { - HttpContent content = (HttpContent) msg; - body = content.content().toString(CharsetUtil.UTF_8); - latch.countDown(); - } - } - - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) - { - cause.printStackTrace(); - ctx.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/63a17adb/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java ---------------------------------------------------------------------- diff --git a/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java new file mode 100644 index 0000000..5175c61 --- /dev/null +++ b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java @@ -0,0 +1,128 @@ +/* + * 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.activemq.cli.test; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.http.DefaultFullHttpRequest; +import io.netty.handler.codec.http.HttpClientCodec; +import io.netty.handler.codec.http.HttpContent; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpObject; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpVersion; +import io.netty.util.CharsetUtil; +import org.apache.activemq.artemis.component.WebServerComponent; +import org.apache.activemq.artemis.dto.WebServerDTO; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class WebServerComponentTest extends Assert +{ + static final String URL = System.getProperty("url", "http://localhost:8161/WebServerComponentTest.txt"); + private Bootstrap bootstrap; + private EventLoopGroup group; + + @Before + public void setupNetty() throws URISyntaxException + { + // Configure the client. + group = new NioEventLoopGroup(); + bootstrap = new Bootstrap(); + } + @Test + public void simpleServer() throws Exception + { + WebServerDTO webServerDTO = new WebServerDTO(); + webServerDTO.bind = "http://localhost:8161"; + webServerDTO.path = "webapps"; + WebServerComponent webServerComponent = new WebServerComponent(); + Assert.assertFalse(webServerComponent.isStarted()); + webServerComponent.configure(webServerDTO, "./src/test/resources/", "./src/test/resources/"); + webServerComponent.start(); + // Make the connection attempt. + CountDownLatch latch = new CountDownLatch(1); + final ClientHandler clientHandler = new ClientHandler(latch); + bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer() + { + @Override + protected void initChannel(Channel ch) throws Exception + { + ch.pipeline().addLast(new HttpClientCodec()); + ch.pipeline().addLast(clientHandler); + } + }); + Channel ch = bootstrap.connect("localhost", 8161).sync().channel(); + + URI uri = new URI(URL); + // Prepare the HTTP request. + HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath()); + request.headers().set(HttpHeaders.Names.HOST, "localhost"); + + + // Send the HTTP request. + ch.writeAndFlush(request); + assertTrue(latch.await(5, TimeUnit.SECONDS)); + assertEquals(clientHandler.body, "12345"); + // Wait for the server to close the connection. + ch.close(); + Assert.assertTrue(webServerComponent.isStarted()); + webServerComponent.stop(); + Assert.assertFalse(webServerComponent.isStarted()); + } + + class ClientHandler extends SimpleChannelInboundHandler<HttpObject> + { + private CountDownLatch latch; + private String body; + + public ClientHandler(CountDownLatch latch) + { + this.latch = latch; + } + + @Override + public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) + { + if (msg instanceof HttpContent) + { + HttpContent content = (HttpContent) msg; + body = content.content().toString(CharsetUtil.UTF_8); + latch.countDown(); + } + } + + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) + { + cause.printStackTrace(); + ctx.close(); + } + } +}
