You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2013/03/10 23:31:31 UTC

svn commit: r1454940 - in /qpid/trunk/qpid/java/broker/src: main/java/org/apache/qpid/server/ test/java/org/apache/qpid/server/

Author: robbie
Date: Sun Mar 10 22:31:31 2013
New Revision: 1454940

URL: http://svn.apache.org/r1454940
Log:
QPID-4390: move the work dir defaulting and configuration fully within BrokerOptions

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/test/java/org/apache/qpid/server/BrokerOptionsTest.java
    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
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java?rev=1454940&r1=1454939&r2=1454940&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 Sun Mar 10 22:31:31 2013
@@ -113,16 +113,6 @@ public class Broker
         String storeLocation = options.getConfigurationStoreLocation();
         String storeType = options.getConfigurationStoreType();
 
-        if (storeLocation == null)
-        {
-            String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK);
-            if (qpidWork == null)
-            {
-                qpidWork = new File(System.getProperty("user.dir"), "work").getAbsolutePath();
-            }
-            storeLocation = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_FILE + "." + storeType).getAbsolutePath();
-        }
-
         CurrentActor.get().message(BrokerMessages.CONFIG(storeLocation));
 
         File logConfigFile = getConfigFile(options.getLogConfigFile(), BrokerOptions.DEFAULT_LOG_CONFIG_FILE, qpidHome, false);

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=1454940&r1=1454939&r2=1454940&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 Sun Mar 10 22:31:31 2013
@@ -20,25 +20,30 @@
  */
 package org.apache.qpid.server;
 
+import java.io.File;
+
+import org.apache.qpid.server.configuration.BrokerProperties;
+
 public class BrokerOptions
 {
     public static final String DEFAULT_STORE_TYPE = "json";
-    public static final String DEFAULT_CONFIG_FILE = "config";
+    public static final String DEFAULT_CONFIG_NAME_PREFIX = "config";
     public static final String DEFAULT_LOG_CONFIG_FILE = "etc/log4j.xml";
 
     private String _logConfigFile;
     private Integer _logWatchFrequency = 0;
 
     private String _configurationStoreLocation;
-    private String _configurationStoreType = DEFAULT_STORE_TYPE;
+    private String _configurationStoreType;
 
     private String _initialConfigurationStoreLocation;
-    private String _initialConfigurationStoreType = DEFAULT_STORE_TYPE;
+    private String _initialConfigurationStoreType;
 
     private boolean _managementMode;
     private int _managementModeRmiPort;
     private int _managementModeConnectorPort;
     private int _managementModeHttpPort;
+    private String _workingDir;
 
     public String getLogConfigFile()
     {
@@ -64,26 +69,6 @@ public class BrokerOptions
         _logWatchFrequency = logWatchFrequency;
     }
 
-    public String getConfigurationStoreLocation()
-    {
-        return _configurationStoreLocation;
-    }
-
-    public void setConfigurationStoreLocation(String cofigurationStore)
-    {
-        _configurationStoreLocation = cofigurationStore;
-    }
-
-    public String getConfigurationStoreType()
-    {
-        return _configurationStoreType;
-    }
-
-    public void setConfigurationStoreType(String cofigurationStoreType)
-    {
-        _configurationStoreType = cofigurationStoreType;
-    }
-
     public void setInitialConfigurationStoreLocation(String initialConfigurationStore)
     {
         _initialConfigurationStoreLocation = initialConfigurationStore;
@@ -101,6 +86,11 @@ public class BrokerOptions
 
     public String getInitialConfigurationStoreType()
     {
+        if(_initialConfigurationStoreType == null)
+        {
+            return DEFAULT_STORE_TYPE;
+        }
+
         return _initialConfigurationStoreType;
     }
 
@@ -143,4 +133,93 @@ public class BrokerOptions
     {
         _managementModeHttpPort = managementModeHttpPort;
     }
-}
\ No newline at end of file
+
+    /**
+     * Get the broker configuration store type.
+     *
+     * @return the previously set store type, or if none was set the default: {@value #DEFAULT_STORE_TYPE}
+     */
+    public String getConfigurationStoreType()
+    {
+        if(_configurationStoreType == null)
+        {
+            return  DEFAULT_STORE_TYPE;
+        }
+
+        return _configurationStoreType;
+    }
+
+    /**
+     * Set the broker configuration store type.
+     *
+     * Passing null clears previously set values and returns to the default.
+     */
+    public void setConfigurationStoreType(String cofigurationStoreType)
+    {
+        _configurationStoreType = cofigurationStoreType;
+    }
+
+    /**
+     * Get the broker configuration store location.
+     *
+     * Defaults to {@value #DEFAULT_CONFIG_NAME_PREFIX}.{@literal <store type>} (see {@link BrokerOptions#getConfigurationStoreType()}) within the broker work directory (see {@link BrokerOptions#getWorkDir()}).
+     *
+     * @return the previously set configuration store location, or the default location if none was set.
+     */
+    public String getConfigurationStoreLocation()
+    {
+        if(_configurationStoreLocation == null)
+        {
+            String workDir = getWorkDir();
+            String storeType = getConfigurationStoreType();
+
+            return new File(workDir, DEFAULT_CONFIG_NAME_PREFIX + "." + storeType).getAbsolutePath();
+        }
+
+        return _configurationStoreLocation;
+    }
+
+    /**
+     * Set the absolute path to use for the broker configuration store.
+     *
+     * Passing null clears any previously set value and returns to the default.
+     */
+    public void setConfigurationStoreLocation(String cofigurationStore)
+    {
+        _configurationStoreLocation = cofigurationStore;
+    }
+
+    /**
+     * Get the broker work directory location.
+     *
+     * Defaults to the location set in the "QPID_WORK" system property if it is set, or the 'work' sub-directory
+     * of the user working directory ("user.dir" property) for the Java process if it is not.
+     *
+     * @return the previously set configuration store location, or the default location if none was set.
+     */
+    public String getWorkDir()
+    {
+        if(_workingDir == null)
+        {
+            String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK);
+            if (qpidWork == null)
+            {
+                return new File(System.getProperty("user.dir"), "work").getAbsolutePath();
+            }
+
+            return qpidWork;
+        }
+
+        return _workingDir;
+    }
+
+    /**
+     * Set the absolute path to use for the broker work directory.
+     *
+     * Passing null clears any previously set value and returns to the default.
+     */
+    public void setWorkDir(String workingDir)
+    {
+        _workingDir = workingDir;
+    }
+}

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java?rev=1454940&r1=1454939&r2=1454940&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java Sun Mar 10 22:31:31 2013
@@ -20,6 +20,8 @@
  */
 package org.apache.qpid.server;
 
+import java.io.File;
+
 import org.apache.qpid.test.utils.QpidTestCase;
 
 public class BrokerOptionsTest extends QpidTestCase
@@ -42,14 +44,39 @@ public class BrokerOptionsTest extends Q
         assertEquals("dby", _options.getConfigurationStoreType());
     }
 
-    public void testDefaultConfigurationStoreLocation()
+    public void testDefaultConfigurationStoreLocationWithQpidWork()
+    {
+        String qpidWork = "/test/value";
+        setTestSystemProperty("QPID_WORK", qpidWork);
+
+        String expectedPath = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + "." + BrokerOptions.DEFAULT_STORE_TYPE).getAbsolutePath();
+        assertEquals (expectedPath, _options.getConfigurationStoreLocation());
+    }
+
+    public void testDefaultConfigurationStoreLocationWithoutQpidWork()
     {
-        assertNull(_options.getConfigurationStoreLocation());
+        setTestSystemProperty("QPID_WORK", null);
+        String userDir = System.getProperty("user.dir");
+
+        String expectedPath = new File(userDir, "work/" + BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + "." + BrokerOptions.DEFAULT_STORE_TYPE).getAbsolutePath();
+        assertEquals (expectedPath, _options.getConfigurationStoreLocation());
+    }
+
+    public void testDefaultConfigurationStoreLocationWithQpidWorkAndDifferentStoreType()
+    {
+        String qpidWork = "/test/value";
+        setTestSystemProperty("QPID_WORK", qpidWork);
+
+        String storeType = "dby";
+        _options.setConfigurationStoreType(storeType);
+
+        String expectedPath = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + "." + storeType).getAbsolutePath();
+        assertEquals (expectedPath, _options.getConfigurationStoreLocation());
     }
 
     public void testOverriddenConfigurationStoreLocation()
     {
-        final String testConfigFile = "etc/mytestconfig.xml";
+        final String testConfigFile = "/my/test/store-location.dby";
         _options.setConfigurationStoreLocation(testConfigFile);
         assertEquals(testConfigFile, _options.getConfigurationStoreLocation());
     }
@@ -147,4 +174,28 @@ public class BrokerOptionsTest extends Q
         assertEquals(5555, _options.getManagementModeHttpPort());
     }
 
+    public void testDefaultWorkDirWithQpidWork()
+    {
+        String qpidWork = "/test/value";
+        setTestSystemProperty("QPID_WORK", qpidWork);
+
+        String expectedPath = new File(qpidWork).getAbsolutePath();
+        assertEquals (expectedPath, _options.getWorkDir());
+    }
+
+    public void testDefaultWorkDirWithoutQpidWork()
+    {
+        setTestSystemProperty("QPID_WORK", null);
+        String userDir = System.getProperty("user.dir");
+
+        String expectedPath = new File(userDir, "work").getAbsolutePath();
+        assertEquals (expectedPath, _options.getWorkDir());
+    }
+
+    public void testOverriddenWorkDir()
+    {
+        final String testWorkDir = "/my/test/work/dir";
+        _options.setWorkDir(testWorkDir);
+        assertEquals(testWorkDir, _options.getWorkDir());
+    }
 }

Modified: 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=1454940&r1=1454939&r2=1454940&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/MainTest.java Sun Mar 10 22:31:31 2013
@@ -20,7 +20,10 @@
  */
 package org.apache.qpid.server;
 
+import java.io.File;
+
 import org.apache.commons.cli.CommandLine;
+import org.apache.qpid.server.configuration.BrokerProperties;
 import org.apache.qpid.test.utils.QpidTestCase;
 
 /**
@@ -34,8 +37,13 @@ public class MainTest extends QpidTestCa
     {
         BrokerOptions options = startDummyMain("");
 
+        String qpidWork = "/qpid/work";
+        setTestSystemProperty(BrokerProperties.PROPERTY_QPID_WORK, qpidWork);
+
+        String expectedStorePath = new File(qpidWork, BrokerOptions.DEFAULT_CONFIG_NAME_PREFIX + ".json").getAbsolutePath();
+
         assertEquals("json", options.getConfigurationStoreType());
-        assertEquals(null, options.getConfigurationStoreLocation());
+        assertEquals(expectedStorePath, options.getConfigurationStoreLocation());
         assertEquals(null, options.getLogConfigFile());
         assertEquals(0, options.getLogWatchFrequency());
         assertEquals("json", options.getInitialConfigurationStoreType());



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org