qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1146625 - in /qpid/trunk/qpid/java/broker/src: main/java/org/apache/qpid/server/Broker.java main/java/org/apache/qpid/server/BrokerOptions.java main/java/org/apache/qpid/server/Main.java test/java/org/apache/qpid/server/MainTest.java
Date Thu, 14 Jul 2011 10:01:19 GMT
Author: robbie
Date: Thu Jul 14 10:01:18 2011
New Revision: 1146625

URL: http://svn.apache.org/viewvc?rev=1146625&view=rev
Log:
QPID-2815: move conversion of logWatch argument into milliseconds into Broker, add a unit
test for the various argument parsing methods in Main.

Added:
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java?rev=1146625&r1=1146624&r2=1146625&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java Thu Jul 14
10:01:18 2011
@@ -366,7 +366,7 @@ public class Broker
                 // log4j expects the watch interval in milliseconds
                 try
                 {
-                    QpidLog4JConfigurator.configureAndWatch(logConfigFile.getPath(), logWatchTime);
+                    QpidLog4JConfigurator.configureAndWatch(logConfigFile.getPath(), logWatchTime
* 1000);
                 }
                 catch (Exception e)
                 {

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java?rev=1146625&r1=1146624&r2=1146625&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java Thu
Jul 14 10:01:18 2011
@@ -141,6 +141,10 @@ public class BrokerOptions
         return _logWatchFrequency;
     }
 
+    /**
+     * Set the frequency with which the log config file will be checked for updates.
+     * @param logWatchFrequency frequency in seconds
+     */
     public void setLogWatchFrequency(final int logWatchFrequency)
     {
         _logWatchFrequency = logWatchFrequency;

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java?rev=1146625&r1=1146624&r2=1146625&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java Thu Jul 14
10:01:18 2011
@@ -38,10 +38,8 @@ import org.apache.qpid.server.registry.A
  */
 public class Main
 {
-    private static Logger _logger;
-
-    protected final static Options options = new Options();
-    protected static CommandLine commandLine;
+    private final Options options = new Options();
+    private CommandLine commandLine;
 
     public static void main(String[] args)
     {
@@ -53,8 +51,11 @@ public class Main
             System.setProperty("log4j.defaultInitOverride", "true");
         }
 
-        //now that the override status is know, we can instantiate the Loggers
-        _logger = Logger.getLogger(Main.class);
+        new Main(args);
+    }
+
+    public Main(final String[] args)
+    {
         setOptions(options);
         if (parseCommandline(args))
         {
@@ -71,7 +72,7 @@ public class Main
         }
     }
 
-    protected static boolean parseCommandline(String[] args)
+    protected boolean parseCommandline(final String[] args)
     {
         try
         {
@@ -89,7 +90,7 @@ public class Main
         }
     }
 
-    protected static void setOptions(Options options)
+    protected void setOptions(final Options options)
     {
         Option help = new Option("h", "help", false, "print this message");
         Option version = new Option("v", "version", false, "print the version information
and exit");
@@ -164,7 +165,7 @@ public class Main
         options.addOption(sslport);
     }
 
-    protected static void execute() throws Exception
+    protected void execute() throws Exception
     {
         BrokerOptions options = new BrokerOptions();
         String configFile = commandLine.getOptionValue(BrokerOptions.CONFIG);
@@ -176,7 +177,7 @@ public class Main
         String logWatchConfig = commandLine.getOptionValue(BrokerOptions.WATCH);
         if(logWatchConfig != null)
         {
-            options.setLogWatchFrequency(Integer.parseInt(logWatchConfig) * 1000);
+            options.setLogWatchFrequency(Integer.parseInt(logWatchConfig));
         }
 
         String logConfig = commandLine.getOptionValue(BrokerOptions.LOG_CONFIG);
@@ -217,17 +218,23 @@ public class Main
             }
         }
         
+        startBroker(options);
+    }
+
+    protected void startBroker(final BrokerOptions options) throws Exception
+    {
         Broker broker = new Broker();
         broker.startup(options);
     }
 
-    protected static void shutdown(int status)
+    protected void shutdown(final int status)
     {
         ApplicationRegistry.remove();
         System.exit(status);
     }
 
-    private static void parsePortArray(BrokerOptions options, Object[] ports, boolean ssl)
throws InitException
+    private static void parsePortArray(final BrokerOptions options,final Object[] ports,
+                                       final boolean ssl) throws InitException
     {
         if(ports != null)
         {
@@ -252,7 +259,8 @@ public class Main
         }
     }
 
-    private static void parsePortArray(BrokerOptions options, Object[] ports, ProtocolExclusion
excludedProtocol) throws InitException
+    private static void parsePortArray(final BrokerOptions options, final Object[] ports,
+                                       final ProtocolExclusion excludedProtocol) throws InitException
     {
         if(ports != null)
         {

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java?rev=1146625&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java Thu Jul
14 10:01:18 2011
@@ -0,0 +1,143 @@
+package org.apache.qpid.server;
+
+import java.util.EnumSet;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+/**
+ * Test to verify the command line parsing within the Main class, by
+ * providing it a series of command line arguments and verifying the
+ * BrokerOptions emerging for use in starting the Broker instance.
+ */
+public class MainTest extends QpidTestCase
+{
+    public void testNoOptionsSpecified()
+    {
+        BrokerOptions options = startDummyMain("");
+
+        assertTrue(options.getPorts().isEmpty());
+        assertTrue(options.getSSLPorts().isEmpty());
+        assertEquals(null, options.getJmxPort());
+        assertEquals(null, options.getConfigFile());
+        assertEquals(null, options.getLogConfigFile());
+        assertEquals(null, options.getBind());
+
+        for(ProtocolExclusion pe : EnumSet.allOf(ProtocolExclusion.class))
+        {
+            assertEquals(0, options.getExcludedPorts(pe).size());
+        }
+    }
+
+    public void testPortOverriddenSingle()
+    {
+        BrokerOptions options = startDummyMain("-p 1234");
+
+        assertTrue(options.getPorts().contains(1234));
+        assertEquals(1, options.getPorts().size());
+        assertTrue(options.getSSLPorts().isEmpty());
+    }
+
+    public void testPortOverriddenMultiple()
+    {
+        BrokerOptions options = startDummyMain("-p 1234 -p 4321");
+
+        assertTrue(options.getPorts().contains(1234));
+        assertTrue(options.getPorts().contains(4321));
+        assertEquals(2, options.getPorts().size());
+        assertTrue(options.getSSLPorts().isEmpty());
+    }
+
+    public void testSSLPortOverriddenSingle()
+    {
+        BrokerOptions options = startDummyMain("-s 5678");
+
+        assertTrue(options.getSSLPorts().contains(5678));
+        assertEquals(1, options.getSSLPorts().size());
+        assertTrue(options.getPorts().isEmpty());
+    }
+
+    public void testSSLPortOverriddenMultiple()
+    {
+        BrokerOptions options = startDummyMain("-s 5678 -s 8765");
+
+        assertTrue(options.getSSLPorts().contains(5678));
+        assertTrue(options.getSSLPorts().contains(8765));
+        assertEquals(2, options.getSSLPorts().size());
+        assertTrue(options.getPorts().isEmpty());
+    }
+
+    public void testNonSSLandSSLPortsOverridden()
+    {
+        BrokerOptions options = startDummyMain("-p 5678 -s 8765");
+
+        assertTrue(options.getPorts().contains(5678));
+        assertTrue(options.getSSLPorts().contains(8765));
+        assertEquals(1, options.getPorts().size());
+        assertEquals(1, options.getSSLPorts().size());
+    }
+
+    public void testJMXportOverridden()
+    {
+        BrokerOptions options = startDummyMain("-m 3456");
+
+        assertEquals(Integer.valueOf(3456), options.getJmxPort());
+    }
+
+    public void testExclude0_10()
+    {
+        BrokerOptions options = startDummyMain("-p 3456 --exclude-0-10 3456");
+
+        assertTrue(options.getPorts().contains(3456));
+        assertEquals(1, options.getPorts().size());
+        assertTrue(options.getExcludedPorts(ProtocolExclusion.v0_10).contains(3456));
+        assertEquals(1, options.getExcludedPorts(ProtocolExclusion.v0_10).size());
+        assertEquals(0, options.getExcludedPorts(ProtocolExclusion.v0_9_1).size());
+    }
+
+    public void testConfig()
+    {
+        BrokerOptions options = startDummyMain("-c abcd/config.xml");
+
+        assertEquals("abcd/config.xml", options.getConfigFile());
+    }
+
+    public void testLogConfig()
+    {
+        BrokerOptions options = startDummyMain("-l wxyz/log4j.xml");
+
+        assertEquals("wxyz/log4j.xml", options.getLogConfigFile());
+    }
+
+    public void testLogWatch()
+    {
+        BrokerOptions options = startDummyMain("-w 9");
+
+        assertEquals(9, options.getLogWatchFrequency());
+    }
+
+    private BrokerOptions startDummyMain(String commandLine)
+    {
+        return (new TestMain(commandLine.split("\\s"))).getOptions();
+    }
+
+    private class TestMain extends Main
+    {
+        private BrokerOptions _options;
+
+        public TestMain(String[] args)
+        {
+            super(args);
+        }
+
+        @Override
+        protected void startBroker(BrokerOptions options)
+        {
+            _options = options;
+        }
+
+        public BrokerOptions getOptions()
+        {
+            return _options;
+        }
+    }
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message