activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject activemq-cli-tools git commit: AMQCLI-3 - tests and cleanup
Date Thu, 09 Mar 2017 14:50:48 GMT
Repository: activemq-cli-tools
Updated Branches:
  refs/heads/master 9723dbfb4 -> e3066fda8


AMQCLI-3 - tests and cleanup


Project: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/commit/e3066fda
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/tree/e3066fda
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/diff/e3066fda

Branch: refs/heads/master
Commit: e3066fda801b6043812fa8c90ab0d104c404bfe5
Parents: 9723dbf
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Thu Mar 9 09:50:14 2017 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Thu Mar 9 09:50:14 2017 -0500

----------------------------------------------------------------------
 .../activemq/cli/kahadb/exporter/Exporter.java  | 12 ++-
 .../cli/kahadb/exporter/ExporterCLITest.java    | 79 ++++++++++++++++++++
 pom.xml                                         |  1 +
 3 files changed, 88 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/e3066fda/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
index 5a9c9d6..9d7ba93 100644
--- a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
+++ b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
@@ -79,7 +79,7 @@ public class Exporter {
         @Option(name = {"--qp", "--queuePattern"}, type = OptionType.COMMAND, description
= "Queue Export Pattern")
         public String queuePattern;
 
-        @Option(name = {"--tp", "--queuePattern"}, type = OptionType.COMMAND, description
= "Topic Export Pattern")
+        @Option(name = {"--tp", "--topicPattern"}, type = OptionType.COMMAND, description
= "Topic Export Pattern")
         public String topicPattern;
 
         @Option(name = "-c", type = OptionType.COMMAND, description = "Compress output xml
file using gzip")
@@ -93,7 +93,7 @@ public class Exporter {
          */
         @Override
         public void run() {
-            LOG.info("Starting store export");
+            LOG.info("Starting KahaDB store export");
             try {
                 Exporter.exportStore(ExportConfigurationBuilder.newBuilder()
                         .setSource(new File(source))
@@ -101,9 +101,11 @@ public class Exporter {
                         .setQueuePattern(queuePattern)
                         .setTopicPattern(topicPattern)
                         .setCompress(compress)
+                        .setOverwrite(overwrite)
                         .build());
             } catch (Exception e) {
                 LOG.error(e.getMessage(), e);
+                throw new IllegalStateException(e.getMessage(), e);
             }
 
         }
@@ -118,7 +120,7 @@ public class Exporter {
          */
         @Override
         public void run() {
-            LOG.info("Exporting");
+            LOG.info("Starting MultiKahaDB store export");
             try {
                 Exporter.exportStore(ExportConfigurationBuilder.newBuilder()
                         .setMultiKaha(true)
@@ -127,9 +129,11 @@ public class Exporter {
                         .setQueuePattern(queuePattern)
                         .setTopicPattern(topicPattern)
                         .setCompress(compress)
+                        .setOverwrite(overwrite)
                         .build());
             } catch (Exception e) {
                 LOG.error(e.getMessage(), e);
+                throw new IllegalStateException(e.getMessage(), e);
             }
 
         }
@@ -137,7 +141,7 @@ public class Exporter {
 
     public static void exportStore(final ExportConfiguration config) throws Exception {
 
-        if (config.getTarget().exists()) {
+        if (!config.isOverwrite() && config.getTarget().exists()) {
             throw new IllegalStateException("File: " + config.getTarget() + " already exists");
         }
 

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/e3066fda/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterCLITest.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterCLITest.java
b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterCLITest.java
new file mode 100644
index 0000000..1200c0c
--- /dev/null
+++ b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterCLITest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.kahadb.exporter;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import io.airlift.airline.ParseOptionMissingException;
+
+@RunWith(Parameterized.class)
+public class ExporterCLITest {
+
+    @Rule
+    public TemporaryFolder temp = new TemporaryFolder();
+    private String type;
+
+    @Parameters(name = "type={0}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+                {"kahadb"},
+                {"mkahadb"}
+        });
+    }
+
+    public ExporterCLITest(String type) {
+        super();
+        this.type = type;
+    }
+
+    @Test(expected = ParseOptionMissingException.class)
+    public void testMissingsArgs() {
+        Exporter.main(new String[]{type});
+    }
+
+    @Test(expected = ParseOptionMissingException.class)
+    public void testMissingTarget() {
+        Exporter.main(new String[]{type, "-s", "file"});
+    }
+
+    @Test(expected = ParseOptionMissingException.class)
+    public void testMissingSource() {
+        Exporter.main(new String[]{type, "-t", "file"});
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testFileExists() throws IOException {
+        Exporter.main(new String[]{type, "-s", temp.newFolder().getAbsolutePath(),
+                "-t", temp.newFile().getAbsolutePath()});
+    }
+
+    @Test
+    public void testFileOverwrite() throws IOException {
+        Exporter.main(new String[]{type, "-s", temp.newFolder().getAbsolutePath(),
+                "-t", temp.newFile().getAbsolutePath(), "-f"});
+        //should be no exceptions
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/e3066fda/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 651d6a3..183a172 100644
--- a/pom.xml
+++ b/pom.xml
@@ -167,6 +167,7 @@
 
   <modules>
     <module>activemq-kahadb-exporter</module>
+    <module>assembly</module>
   </modules>
 
   <profiles>


Mime
View raw message