Author: rgodfrey
Date: Fri Apr 13 08:48:34 2012
New Revision: 1325661

URL: http://svn.apache.org/viewvc?rev=1325661&view=rev
Log:
QPID-3917 : Fix failing BDB test, remove unusued readOnly flag

Modified:
    
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
    
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
    
qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java

Modified: 
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java?rev=1325661&r1=1325660&r2=1325661&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
 (original)
+++ 
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/AbstractBDBMessageStore.java
 Fri Apr 13 08:48:34 2012
@@ -156,8 +156,6 @@ public abstract class AbstractBDBMessage
 
     protected TransactionConfig _transactionConfig = new TransactionConfig();
 
-    private boolean _readOnly = false;
-
     private MessageStoreRecoveryHandler _messageRecoveryHandler;
 
     private TransactionLogRecoveryHandler _tlogRecoveryHandler;
@@ -239,53 +237,36 @@ public abstract class AbstractBDBMessage
 
         _storeLocation = storeLocation;
 
-        configure(environmentPath, false);
-    }
-
-    /**
-     * @param environmentPath location for the store to be created 
in/recovered from
-     * @param readonly if true then don't allow modifications to an existing 
store, and don't create a new store if none exists
-     * @return whether or not a new store environment was created
-     * @throws AMQStoreException
-     * @throws DatabaseException
-     */
-    protected void configure(File environmentPath, boolean readonly) throws 
AMQStoreException, DatabaseException
-    {
-        if (_stateManager.isInState(State.INITIAL))
-        {
-            // TODO - currently required for BDBUpgrade and BDBMessageStoreTest
-            _stateManager.stateTransition(State.INITIAL, State.CONFIGURING);
-        }
-
-        _readOnly = readonly;
-
         LOGGER.info("Configuring BDB message store");
 
-        setupStore(environmentPath, readonly);
+        setupStore(environmentPath);
     }
 
     /**
-     * Move the store state from CONFIGURING to ACTIVE.
+     * Move the store state from INITIAL to ACTIVE without actually recovering.
      *
      * This is required if you do not want to perform recovery of the store 
data
      *
      * @throws AMQStoreException if the store is not in the correct state
      */
-    public void start() throws AMQStoreException
+    void startWithNoRecover() throws AMQStoreException
     {
-        _stateManager.stateTransition(State.CONFIGURING, State.ACTIVE);
+        _stateManager.attainState(State.CONFIGURING);
+        _stateManager.attainState(State.CONFIGURED);
+        _stateManager.attainState(State.RECOVERING);
+        _stateManager.attainState(State.ACTIVE);
     }
 
-    protected void setupStore(File storePath, boolean readonly) throws 
DatabaseException, AMQStoreException
+    protected void setupStore(File storePath) throws DatabaseException, 
AMQStoreException
     {
-        _environment = createEnvironment(storePath, readonly);
+        _environment = createEnvironment(storePath);
 
         new Upgrader(_environment).upgradeIfNecessary();
 
-        openDatabases(readonly);
+        openDatabases();
     }
 
-    protected Environment createEnvironment(File environmentPath, boolean 
readonly) throws DatabaseException
+    protected Environment createEnvironment(File environmentPath) throws 
DatabaseException
     {
         LOGGER.info("BDB message store using environment path " + 
environmentPath.getAbsolutePath());
         EnvironmentConfig envConfig = new EnvironmentConfig();
@@ -306,7 +287,7 @@ public abstract class AbstractBDBMessage
         _transactionConfig.setReadCommitted(true);
 
         //This prevents background threads running which will potentially 
update the store.
-        envConfig.setReadOnly(readonly);
+        envConfig.setReadOnly(false);
         try
         {
             return new Environment(environmentPath, envConfig);
@@ -336,14 +317,14 @@ public abstract class AbstractBDBMessage
         return _environment;
     }
 
-    private void openDatabases(boolean readonly) throws DatabaseException
+    private void openDatabases() throws DatabaseException
     {
         DatabaseConfig dbConfig = new DatabaseConfig();
         dbConfig.setTransactional(true);
         dbConfig.setAllowCreate(true);
 
         //This is required if we are wanting read only access.
-        dbConfig.setReadOnly(readonly);
+        dbConfig.setReadOnly(false);
 
         _messageMetaDataDb = openDatabase(MESSAGEMETADATADB_NAME, dbConfig);
         _queueDb = openDatabase(QUEUEDB_NAME, dbConfig);
@@ -446,13 +427,10 @@ public abstract class AbstractBDBMessage
     {
         if (_environment != null)
         {
-            if(!_readOnly)
-            {
-                // Clean the log before closing. This makes sure it doesn't 
contain
-                // redundant data. Closing without doing this means the 
cleaner may not
-                // get a chance to finish.
-                _environment.cleanLog();
-            }
+            // Clean the log before closing. This makes sure it doesn't contain
+            // redundant data. Closing without doing this means the cleaner 
may not
+            // get a chance to finish.
+            _environment.cleanLog();
             _environment.close();
         }
     }

Modified: 
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java?rev=1325661&r1=1325660&r2=1325661&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
 (original)
+++ 
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
 Fri Apr 13 08:48:34 2012
@@ -50,18 +50,14 @@ public class BDBMessageStore extends Abs
     private final CommitThread _commitThread = new 
CommitThread("Commit-Thread");
 
     @Override
-    protected void setupStore(File storePath, boolean readonly) throws 
DatabaseException, AMQStoreException
+    protected void setupStore(File storePath) throws DatabaseException, 
AMQStoreException
     {
-        super.setupStore(storePath, readonly);
+        super.setupStore(storePath);
 
-        if (!readonly)
-        {
-            startCommitThread();
-        }
+        startCommitThread();
     }
 
-    @Override
-    protected Environment createEnvironment(File environmentPath, boolean 
readonly) throws DatabaseException
+    protected Environment createEnvironment(File environmentPath) throws 
DatabaseException
     {
         LOGGER.info("BDB message store using environment path " + 
environmentPath.getAbsolutePath());
         EnvironmentConfig envConfig = new EnvironmentConfig();
@@ -82,7 +78,7 @@ public class BDBMessageStore extends Abs
         _transactionConfig.setReadCommitted(true);
 
         //This prevents background threads running which will potentially 
update the store.
-        envConfig.setReadOnly(readonly);
+        envConfig.setReadOnly(false);
         try
         {
             return new Environment(environmentPath, envConfig);

Modified: 
qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java?rev=1325661&r1=1325660&r2=1325661&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
 (original)
+++ 
qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreTest.java
 Fri Apr 13 08:48:34 2012
@@ -20,6 +20,9 @@
  */
 package org.apache.qpid.server.store.berkeleydb;
 
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
 import org.apache.qpid.AMQStoreException;
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.framing.BasicContentHeaderProperties;
@@ -48,11 +51,6 @@ import org.apache.qpid.transport.Message
 import org.apache.qpid.transport.MessageProperties;
 import org.apache.qpid.transport.MessageTransfer;
 
-import java.io.File;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.List;
-
 /**
  * Subclass of MessageStoreTest which runs the standard tests from the 
superclass against
  * the BDB Store as well as additional tests specific to the DBB 
store-implementation.
@@ -123,7 +121,7 @@ public class BDBMessageStoreTest extends
         /*
          * reload the store only (read-only)
          */
-        bdbStore = reloadStoreReadOnly(bdbStore);
+        bdbStore = reloadStore(bdbStore);
 
         /*
          * Read back and validate the 0-8 message metadata and content
@@ -220,14 +218,14 @@ public class BDBMessageStoreTest extends
      * Use this method instead of reloading the virtual host like other tests 
in order
      * to avoid the recovery handler deleting the message for not being on a 
queue.
      */
-    private BDBMessageStore reloadStoreReadOnly(BDBMessageStore messageStore) 
throws Exception
+    private BDBMessageStore reloadStore(BDBMessageStore messageStore) throws 
Exception
     {
         messageStore.close();
-        File storePath = new 
File(String.valueOf(_config.getProperty("store.environment-path")));
 
         BDBMessageStore newStore = new BDBMessageStore();
-        newStore.configure(storePath, false);
-        newStore.start();
+        newStore.configure("", _config.subset("store"));
+
+        newStore.startWithNoRecover();
 
         return newStore;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to