[rhmessaging-commits] rhmessaging commits: r2618 - in store/trunk/cpp: tests/jrnl and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Fri Oct 10 11:19:26 EDT 2008


Author: kpvdr
Date: 2008-10-10 11:19:26 -0400 (Fri, 10 Oct 2008)
New Revision: 2618

Modified:
   store/trunk/cpp/lib/jrnl/jcntl.cpp
   store/trunk/cpp/lib/jrnl/jcntl.hpp
   store/trunk/cpp/lib/jrnl/lfmgr.cpp
   store/trunk/cpp/lib/jrnl/lfmgr.hpp
   store/trunk/cpp/lib/jrnl/rcvdat.hpp
   store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp
   store/trunk/cpp/tests/jrnl/_ut_jinf.cpp
   store/trunk/cpp/tests/jrnl/_ut_lfmgr.cpp
Log:
Updated version of lfmgr class and its unit tests.

Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -209,7 +209,7 @@
 
     _wrfc.initialize(_num_jfiles, _jfsize_sblks, _fc_arr, &_rcvdat);
     _rrfc.initialize(_num_jfiles, _fc_arr);
-    _rrfc.set_findex(_rcvdat.ffid(_num_jfiles));
+    _rrfc.set_findex(_rcvdat.ffid());
     _rmgr.initialize(rd_cb);
     _wmgr.initialize(wr_cb, wcache_pgsize_sblks, wcache_num_pages, JRNL_WMGR_MAXDTOKPP,
             JRNL_WMGR_MAXWAITUS, (_rcvdat._lffull ? 0 : _rcvdat._eo));
@@ -227,7 +227,7 @@
         _fc_arr[i]->reset(&_rcvdat);
     _wrfc.initialize(_num_jfiles, _jfsize_sblks, _fc_arr, &_rcvdat);
     _rrfc.initialize(_num_jfiles, _fc_arr);
-    _rrfc.set_findex(_rcvdat.ffid(_num_jfiles));
+    _rrfc.set_findex(_rcvdat.ffid());
     _rmgr.recover_complete();
     _readonly_flag = false;
 }
@@ -478,13 +478,12 @@
 }
 
 fcntl*
-jcntl::new_fcntl(jcntl* const jcp, const std::size_t lid, const std::size_t fid)
+jcntl::new_fcntl(jcntl* const jcp, const std::size_t lid, const std::size_t fid, const rcvdat* const rdp)
 {
     if (!jcp) return 0;
     std::ostringstream oss;
     oss << jcp->jrnl_dir() << "/" << jcp->base_filename();
-    // TODO: resolve fid/lid in following stmt:
-    return new fcntl(oss.str(), fid, lid, jcp->jfsize_sblks(), 0);
+    return new fcntl(oss.str(), fid, lid, jcp->jfsize_sblks(), rdp);
 }
 
 // Protected/Private functions

Modified: store/trunk/cpp/lib/jrnl/jcntl.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.hpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/lib/jrnl/jcntl.hpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -637,7 +637,8 @@
         /**
         * /brief Static function for creating new fcntl objects for use with obj_arr.
         */
-        static fcntl* new_fcntl(jcntl* const jcp, const std::size_t lid, const std::size_t fid);
+        static fcntl* new_fcntl(jcntl* const jcp, const std::size_t lid, const std::size_t fid,
+                const rcvdat* const rdp);
 
 
 

Modified: store/trunk/cpp/lib/jrnl/lfmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/lfmgr.cpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/lib/jrnl/lfmgr.cpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -49,7 +49,10 @@
 void
 lfmgr::initialize(const std::size_t num_jfiles,
                   jcntl* const jcp,
-                  fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid))
+                  fcntl* (new_obj_fn)(jcntl* const jcp,
+                                      const std::size_t lid,
+                                      const std::size_t fid,
+                                      const rcvdat* const rdp))
 {
     finalize();
     if (num_jfiles > 0)
@@ -60,42 +63,53 @@
 }
 
 void
-lfmgr::initialize(const std::vector<u_int16_t>& fid_list, jcntl* const jcp,
-                  fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid))
+lfmgr::recover(const rcvdat& rd,
+               jcntl* const jcp,
+               fcntl* (new_obj_fn)(jcntl* const jcp,
+                                   const std::size_t lid,
+                                   const std::size_t fid,
+                                   const rcvdat* const rdp))
 {
     finalize();
-    if (fid_list.size() > 0)
-    {
-        _fcntl_arr.reserve(2 * fid_list.size()); // reserve some extra for possible add_obj() operations
-        _fcntl_arr.assign(fid_list.size(), 0);
-        std::vector<u_int16_t> lid_list(fid_list.size(), 0);
-        for (std::size_t lid = 0; lid < fid_list.size(); lid++)
-            lid_list[fid_list[lid]] = lid;
-        for (std::size_t fid = 0; fid < lid_list.size(); fid++)
-            _fcntl_arr[lid_list[fid]] = new_obj_fn(jcp, lid_list[fid], fid);
-    }
+    _fcntl_arr.reserve(2 * rd._num_jfiles); // reserve some extra for possible add_obj() operations
+    _fcntl_arr.assign(rd._num_jfiles, 0);
+    std::vector<u_int16_t> lid_list(rd._fid_list.size(), 0);
+    for (std::size_t lid = 0; lid < rd._fid_list.size(); lid++)
+        lid_list[rd._fid_list[lid]] = lid;
+    // NOTE: rd._fid_list may be smaller than rd._num_jfiles (journal may be empty or not yet file-cycled)
+    for (std::size_t fid = 0; fid < rd._num_jfiles; fid++)
+        if (fid < rd._fid_list.size())
+            _fcntl_arr[lid_list[fid]] = new_obj_fn(jcp, lid_list[fid], fid, &rd);
+        else
+            _fcntl_arr[fid] = new_obj_fn(jcp, fid, fid, 0);
 }
 
 void
 lfmgr::append(jcntl* const jcp,
-              fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid),
+              fcntl* (new_obj_fn)(jcntl* const jcp,
+                                  const std::size_t lid,
+                                  const std::size_t fid,
+                                  const rcvdat* const rdp),
               const std::size_t num_jfiles)
 {
     std::size_t s = _fcntl_arr.size();
     for (std::size_t i = s; i < s + num_jfiles; i++)
-        _fcntl_arr.push_back(new_obj_fn(jcp, i, i));
+        _fcntl_arr.push_back(new_obj_fn(jcp, i, i, 0));
 }
 
 void
 lfmgr::insert(const std::size_t after_index,
               jcntl* const jcp,
-              fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid),
+              fcntl* (new_obj_fn)(jcntl* const jcp,
+                                  const std::size_t lid,
+                                  const std::size_t fid,
+                                  const rcvdat* const rdp),
               const std::size_t num_jfiles)
 {
     assert(after_index < _fcntl_arr.size());
     std::size_t fid = _fcntl_arr.size();
     for (std::size_t lid = after_index + 1; lid <= after_index + num_jfiles; lid++, fid++)
-        _fcntl_arr.insert(_fcntl_arr.begin() + lid, new_obj_fn(jcp, lid, fid));
+        _fcntl_arr.insert(_fcntl_arr.begin() + lid, new_obj_fn(jcp, lid, fid, 0));
     for (std::size_t lid = after_index + num_jfiles + 1; lid < _fcntl_arr.size(); lid++)
     {
         fcntl* fp = _fcntl_arr[lid];

Modified: store/trunk/cpp/lib/jrnl/lfmgr.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/lfmgr.hpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/lib/jrnl/lfmgr.hpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -50,7 +50,75 @@
     /**
     * \brief LID-FID manager. This class maps the logical id (lid) to the physical file id (fid) so that files may be
     * inserted into the file ring buffer in (nearly) arbitrary logical locations while the physical ids continue to
-    * be appended.
+    * be appended. NOTE: NOT THREAD SAFE.
+    *
+    * The entire functionality of the LID-FID manager is to maintain an array of pointers to fcntl objects which have a
+    * one-to-one relationship to the physical %journal files. The logical id (lid) is used as an index to the array to
+    * read the mapped file-id (fid). By altering the order of these pointers within the array, the mapping of logical to
+    * physical files may be altered. This can be used to allow for the logical insertion of %journal files into a ring
+    * buffer, even though the physical file ids must be appended to those that preceded them.
+    *
+    * Since the insert() operation uses after-lid as the position parameter, it is not possible to insert before lid 0.
+    * Consequently, lid 0 and fid 0 are always coincident in a %journal. Note, however, that this operation is logically
+    * equivilent to inserting a new file after the last lid.
+    *
+    * When one or more files are inserted after a particular lid, the lids of the following files are incremented. The
+    * fids of the inserted files follow those of all existing files, thus leading to a lid-fid discreppancy (ie no
+    * longer a one-to-one mapping):
+    *
+    * Example: Before insertion, %journal file headers would look as follows:
+    * <pre>
+    *          Logical view (sorted by lid):                Physical view (sorted by fid):
+    *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
+    *  fid --> | 0 | 1 | 2 | 3 | 4 | 5 |            fid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+    *  lid --> | 0 | 1 | 2 | 3 | 4 | 5 |            lid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+    *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
+    * </pre>
+    * 
+    * After insertion of 2 files after lid 2 (marked with *s):
+    * <pre>
+    *          Logical view (sorted by lid):                Physical view (sorted by fid):
+    *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
+    *  fid --> | 0 | 1 | 2 |*6*|*7*| 3 | 4 | 5 |    fid --> | 0 | 1 | 2 | 3 | 4 | 5 |*6*|*7*|
+    *  lid --> | 0 | 1 | 2 |*3*|*4*| 5 | 6 | 7 |    lid --> | 0 | 1 | 2 | 5 | 6 | 7 |*3*|*4*|
+    *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
+    * </pre>
+    *
+    * The insert() function updates the internal map immediately, but the physical files (which have both the fid and
+    * lid written into the file header) are only updated as they are overwirtten in the normal course of enqueueing
+    * and dequeueing messages. If the %journal should fail after insertion but before the files following those inserted
+    * are overwritten, then duplicate lids will be present (though no duplicate fids are possible). The overwrite
+    * indicator (owi) flag and the fid numbers may be used to resolve the ambiguity and determine the logically earlier
+    * lid in this case as follows:
+    *
+    * Example: Before insertion, the current active write file being lid/fid 2 as determined by the owi flag, %journal
+    * file headers would look as follows:
+    * <pre>
+    *          Logical view (sorted by lid):                Physical view (sorted by fid):
+    *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
+    *  fid --> | 0 | 1 | 2 | 3 | 4 | 5 |            fid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+    *  lid --> | 0 | 1 | 2 | 3 | 4 | 5 |            lid --> | 0 | 1 | 2 | 3 | 4 | 5 |
+    *  owi --> | t | t | t | f | f | f |            owi --> | t | t | t | f | f | f |
+    *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
+    * </pre>
+    * 
+    * After 2 insertions after lid 2 and then 3 (the newly inserted file) - marked with *s, and then a
+    * broker failure/stoppage:
+    * <pre>
+    *          Logical view (sorted by lid):                Physical view (sorted by fid):
+    *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
+    *  fid --> | 0 | 1 | 2 |*6*|*7*| 3 | 4 | 5 |    fid --> | 0 | 1 | 2 | 3 | 4 | 5 |*3*|*4*|
+    *  lid --> | 0 | 1 | 2 |*3*|*4*| 3 | 4 | 5 |    lid --> | 0 | 1 | 2 | 3 | 4 | 5 |*3*|*4*|
+    *  owi --> | t | t | t | t | t | f | f | f |    owi --> | t | t | t | f | f | f | t | t |
+    *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
+    * </pre>
+    *
+    * There are two independent tests that may be made to resolve duplicat lids during recovery in such cases:
+    * <ol>
+    *   <li>The correct lid has owi flag that matches that of fid/lid 0</li>
+    *   <li>The most recently inserted (hence correct) lid has fids that are higher than the duplicat that was not
+    *       overwritten</li>
+    * </ol>
     */
     class lfmgr
     {
@@ -62,7 +130,7 @@
         virtual ~lfmgr();
 
         /**
-        * \brief Initialize from scratch for a known number of journal files. All lid values are identical to fid
+        * \brief Initialize from scratch for a known number of %journal files. All lid values are identical to fid
         * values (which is normal before any inserts have occurred).
         *
         * \param num_jfiles Number of files to be created, and consequently the number of fcntl objects in array
@@ -70,25 +138,31 @@
         * \param jcp        Pointer to jcntl instance. This is used to find the file path and base filename so that
         *                   new files may be created.
         * \param new_obj_fn Pointer to function which creates and returns a pointer to a new fcntl object (and hence
-        *                   causes a new journal file to be created).
+        *                   causes a new %journal file to be created).
         */
         void initialize(const std::size_t num_jfiles,
                         jcntl* const jcp,
-                        fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid));
+                        fcntl* (new_obj_fn)(jcntl* const jcp,
+                                            const std::size_t lid,
+                                            const std::size_t fid,
+                                            const rcvdat* const rdp));
 
         /**
         * \brief Initialize from a known lid-fid map fid_list, which is usually obtained from a recover. The index of
         * fid_list is the logical id (lid); the value contained in the vector is the file id (fid).
         *
-        * \param fid_list   Vector containing fid sequence.
+        * \param rd         Ref to rcvdat struct which contains recovery data.
         * \param jcp        Pointer to jcntl instance. This is used to find the file path and base filename so that
         *                   new files may be created.
         * \param new_obj_fn Pointer to function which creates and returns a pointer to a new fcntl object (and hence
-        *                   causes a new journal file to be created).
+        *                   causes a new %journal file to be created).
         */
-        void initialize(const std::vector<u_int16_t>& fid_list,
-                        jcntl* const jcp,
-                        fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid));
+        void recover(const rcvdat& rd,
+                     jcntl* const jcp,
+                     fcntl* (new_obj_fn)(jcntl* const jcp,
+                                         const std::size_t lid,
+                                         const std::size_t fid,
+                                         const rcvdat* const rdp));
 
         /**
         * \brief Append num_jfiles files to the end of the logical and file id sequence. This is similar to extending
@@ -97,11 +171,14 @@
         * \param jcp        Pointer to jcntl instance. This is used to find the file path and base filename so that
         *                   new files may be created.
         * \param new_obj_fn Pointer to function which creates and returns a pointer to a new fcntl object (and hence
-        *                   causes a new journal file to be created).
+        *                   causes a new %journal file to be created).
         * \param num_jfiles The number of files by which to increase.
         */
         void append(jcntl* const jcp,
-                    fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid),
+                    fcntl* (new_obj_fn)(jcntl* const jcp,
+                                        const std::size_t lid,
+                                        const std::size_t fid,
+                                        const rcvdat* const rdp),
                     const std::size_t num_jfiles = 1);
 
         /**
@@ -115,12 +192,15 @@
         * \param jcp        Pointer to jcntl instance. This is used to find the file path and base filename so that
         *                   new files may be created.
         * \param new_obj_fn Pointer to function which creates and returns a pointer to a new fcntl object (and hence
-        *                   causes a new journal file to be created).
+        *                   causes a new %journal file to be created).
         * \param num_jfiles The number of files by which to increase.
         */
         void insert(const std::size_t after_index,
                     jcntl* const jcp,
-                    fcntl* (new_obj_fn)(jcntl* const jcp, const std::size_t lid, const std::size_t fid),
+                    fcntl* (new_obj_fn)(jcntl* const jcp,
+                                        const std::size_t lid,
+                                        const std::size_t fid,
+                                        const rcvdat* const rdp),
                     const std::size_t num_jfiles = 1);
 
         /**
@@ -138,9 +218,10 @@
         inline bool is_init() const { return _fcntl_arr.size() > 0; }
 
         /**
-        * \brief Returns the number of journal files, including any that were appended or inserted since initialization.
+        * \brief Returns the number of %journal files, including any that were appended or inserted since
+        * initialization.
         *
-        * \return Number of journal files if initialized; 0 otherwise.
+        * \return Number of %journal files if initialized; 0 otherwise.
         */
         inline std::size_t size() const { return _fcntl_arr.size(); }
 
@@ -156,7 +237,6 @@
         // Testing functions
         void get_fid_list(std::vector<u_int16_t>& fid_list) const;
         void get_lid_list(std::vector<u_int16_t>& lid_list) const;
-
     };
 
 } // namespace journal

Modified: store/trunk/cpp/lib/jrnl/rcvdat.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/rcvdat.hpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/lib/jrnl/rcvdat.hpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -35,10 +35,10 @@
 #include <cstddef>
 #include <iomanip>
 #include <map>
+#include "jrnl/jcfg.hpp"
 #include <sstream>
+#include <sys/types.h>
 #include <vector>
-#include "jrnl/jcfg.hpp"
-#include <sys/types.h>
 
 namespace mrg
 {
@@ -47,19 +47,22 @@
 
         struct rcvdat
         {
-            bool _owi;          ///< Overwrite indicator
-            bool _frot;         ///< First rotation flag
-            bool _jempty;       ///< Journal data files empty
-            u_int16_t _ffid;    ///< First file id
-            std::size_t _fro;   ///< First record offset in ffid
-            u_int16_t _lfid;    ///< Last file id
-            std::size_t _eo;    ///< End offset (first byte past last record)
-            u_int64_t _h_rid;   ///< Highest rid found
-            bool _lffull;       ///< Last file is full
-            bool _jfull;        ///< Journal is full
+            u_int16_t _num_jfiles;  ///< Number of journal files
+            bool _owi;              ///< Overwrite indicator
+            bool _frot;             ///< First rotation flag
+            bool _jempty;           ///< Journal data files empty
+            u_int16_t _ffid;        ///< First file id
+            std::size_t _fro;       ///< First record offset in ffid
+            u_int16_t _lfid;        ///< Last file id
+            std::size_t _eo;        ///< End offset (first byte past last record)
+            u_int64_t _h_rid;       ///< Highest rid found
+            bool _lffull;           ///< Last file is full
+            bool _jfull;            ///< Journal is full
+            std::vector<u_int16_t> _fid_list; ///< Fid-lid mapping - list of fids in order of lid
             std::vector<u_int32_t> _enq_cnt_list; ///< Number enqueued records found for each file
 
             rcvdat():
+                    _num_jfiles(0),
                     _owi(false),
                     _frot(false),
                     _jempty(true),
@@ -70,11 +73,13 @@
                     _h_rid(0),
                     _lffull(false),
                     _jfull(false),
+                    _fid_list(),
                     _enq_cnt_list()
             {}
 
             void reset(u_int16_t num_jfiles)
             {
+                _num_jfiles = num_jfiles;
                 _owi=false;
                 _frot = false;
                 _jempty=true;
@@ -85,17 +90,18 @@
                 _h_rid=0;
                 _lffull = false;
                 _jfull = false;
+                _fid_list.clear();
                 _enq_cnt_list.clear();
                 _enq_cnt_list.resize(num_jfiles, 0);
             }
 
             // Find first fid with enqueued records
-            u_int16_t ffid(const u_int16_t num_jfiles)
+            u_int16_t ffid()
             {
                 u_int16_t index = _ffid;
                 while (index != _lfid && _enq_cnt_list[index] == 0)
                 {
-                    if (++index >= num_jfiles)
+                    if (++index >= _num_jfiles)
                         index = 0;
                 }
                 return index;
@@ -105,6 +111,7 @@
             {
                 std::ostringstream oss;
                 oss << "Recover file analysis (jid=\"" << jid << "\"):" << std::endl;
+                oss << "  Number of journal files (_num_jfiles) = " << _num_jfiles << std::endl;
                 oss << "  Overwrite indicator (_owi) = " << (_owi ? "TRUE" : "FALSE") << std::endl;
                 oss << "  First rotation (_frot) = " << (_frot ? "TRUE" : "FALSE") << std::endl;
                 oss << "  Journal empty (_jempty) = " << (_jempty ? "TRUE" : "FALSE") << std::endl;
@@ -117,6 +124,14 @@
                 oss << "  Highest rid (_h_rid) = 0x" << std::hex << _h_rid << std::dec << std::endl;
                 oss << "  Last file full (_lffull) = " << (_lffull ? "TRUE" : "FALSE") << std::endl;
                 oss << "  Journal full (_jfull) = " << (_jfull ? "TRUE" : "FALSE") << std::endl;
+                oss << "  Fid list (_fid_list) = [";
+                for (std::vector<u_int16_t>::const_iterator i = _fid_list.begin(); i < _fid_list.end(); i++)
+                {
+                    if (i != _fid_list.begin())
+                        oss << ", ";
+                    oss << *i;
+                }
+                oss << "]" << std::endl;
                 oss << "  Enqueued records (txn & non-txn):" << std::endl;
                 for (unsigned i=0; i<_enq_cnt_list.size(); i++)
                    oss << "    File " << std::setw(2) << i << ": " << _enq_cnt_list[i] <<
@@ -128,6 +143,7 @@
             {
                 std::ostringstream oss;
                 oss << "Recover file analysis (jid=\"" << jid << "\"):";
+                oss << " njf=" << _num_jfiles;
                 oss << " owi=" << (_owi ? "T" : "F");
                 oss << " frot=" << (_frot ? "T" : "F");
                 oss << " jempty=" << (_jempty ? "T" : "F");

Modified: store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/tests/jrnl/_st_helper_fns.hpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -28,9 +28,6 @@
 // NOTE: This file is included in _st_*.cpp files inside the QPID_AUTO_TEST_SUITE()
 // definition.
 
-#include <cstdlib>
-#include <time.h>
-
 #define MAX_AIO_SLEEPS 500
 #define AIO_SLEEP_TIME 1000
 #define NUM_TEST_JFILES 4
@@ -45,12 +42,14 @@
 #define LARGE_MSG_SIZE (LARGE_MSG_REC_SIZE_DBLKS * JRNL_DBLK_SIZE) - sizeof(enq_hdr) - sizeof(rec_tail)
 #define XID_SIZE 64
 
-
 #define XLARGE_MSG_RATIO (1.0 * LARGE_MSG_REC_SIZE / JRNL_DBLK_SIZE / JRNL_SBLK_SIZE / JRNL_RMGR_PAGE_SIZE)
 #define XLARGE_MSG_THRESHOLD (int)(JRNL_DEFAULT_FSIZE * NUM_DEFAULT_JFILES * JRNL_ENQ_THRESHOLD / 100 / LARGE_MSG_RATIO)
 
+#define NUM_JFILES 4
+#define JFSIZE_SBLKS 128
+
 const char* tdp = getenv("TMPDIR");
-const string test_dir(tdp && strlen(tdp) > 0 ? tdp : "/tmp/_ut_jdir");
+const string test_dir(tdp && strlen(tdp) > 0 ? tdp : "/tmp/jrnl_test");
 
 class test_dtok : public data_tok
 {
@@ -87,6 +86,432 @@
     }
 };
 
+/*
+* This class is for testing recover functionality by maintaining an internal lid-fid map, then creating physical
+* journal file stubs (just the fhdr section of the journal) and jinf file. This allows the recover functionality (which
+* analyzes these components to determine recover order).
+*
+* First set up a map or "blueprint" of what the journal should look like for recovery, then have the class create the
+* physical files. The jinf object under test then reads and analyzes the created journal, and it's analysis is checked
+* against what is expected.
+*
+* General usage pattern:
+* 1. Create instance of lid_fid_map.
+* 2. Call lid_fid_map::journal_create() to simulate initial journal creation.
+* 3. (optional) Call lid_fid_map::journal_append() one or more times to simulate the addition of journal files.
+* 4. Call lid_fid_map::write_journal() to create dummy journal files (files containing only file headers)
+* 5. Create and initialize the jinf object under test
+* 6. Call jinf::analyze() to determine the fid order - and thus also first and last lids
+* 7. Call lid_fid_map::check_analysis() to check the conclusions of the analysis
+* 8. Call lid_fid_map::destroy_journal() to delete the journal files and reset the lid_fid_map object.
+* 9. (optional) Back to step 2 for more tests
+*
+* See the individual methods below for more details.
+*/
+class lid_fid_map
+{
+    public:
+        typedef pair<u_int16_t, file_hdr> lfpair;           // Used for loading the map
+        typedef multimap<u_int16_t, file_hdr> lfmap;        // Stores the journal "plan" before it is created on-disk
+        typedef lfmap::const_iterator lfmap_citr;           // General purpose iterator
+        typedef pair<lfmap_citr, lfmap_citr> lfmap_range;   // Range of values returned by multimap's equal_range() fn
+
+    private:
+        string _jid;                // Journal id
+        string _base_filename;      // Base filename
+        lfmap _map;                 // Stores the journal "blueprint" before it is created on-disk
+        u_int16_t _num_used_files;  // number of files which contain jorunals
+        u_int16_t _oldest_lid;      // lid where owi flips; always 0 if !_full
+        u_int16_t _last_fid;        // last fid (ie file added)
+
+    public:
+        lid_fid_map(const string& jid, const string& base_filename) :
+                _jid(jid), _base_filename(base_filename), _num_used_files(0), _oldest_lid(0), _last_fid(0)
+        {}
+        virtual ~lid_fid_map() {}
+
+        // Mainly used for debugging
+        void print()
+        {
+            int cnt = 0;
+            for (lfmap_citr i=_map.begin(); i!=_map.end(); i++, cnt++)
+            {
+                const file_hdr fh = i->second;
+                cout << "  " << cnt << ": owi=" << (fh.get_owi()?"t":"f") << hex << " frid=0x" << fh._rid;
+                cout << " fid=0x" << fh._fid << " lid=0x" << fh._lid << " fro=0x" << fh._fro << dec << endl;
+            }
+        }
+
+        std::size_t size()
+        {
+            return _map.size();
+        }
+
+        /*
+        * Method journal_create(): Used to simulate the initial creation of a journal before file insertions
+        * take place.
+        *
+        *      num_jfiles: The initial journal file count.
+        * num_used_jfiles: If this number is less than num_jfiles, it indicates a clean journal that has not yet
+        *                  completed its first rotation, and some files are empty (ie all null). The first
+        *                  num_used_jfiles will contain file headers, the remainder will be blank.
+        *      oldest_lid: The lid (==fid, see note 1 below) at which the owi flag flips. During normal operation, each
+        *                  time the journal rotates back to file 0, a flag (called the overwrite indicator or owi) is
+        *                  flipped. This flag is saved in the file header. During recovery, if scanning from logical
+        *                  file 0 upwards, the file at which this flag reverses from its value in file 0 is the file
+        *                  that was to have been overwritten next, and is thus the "oldest" file. Recovery analysis must
+        *                  start with this file. oldest_lid sets the file at which this flag will flip value for the
+        *                  simulated recovery analysis. Note that this will be ignored if num_used_jfiles < num_jfiles,
+        *                  as it is not possible for an overwrite to have occurred if not all the files have been used.
+        *       first_owi: Sets the value of the owi flag in file 0. If set to false, then the flip will be found with
+        *                  a true flag (and visa versa).
+        *
+        * NOTES:
+        * 1. By definition, the lids and fids coincide for a journal containing no inserted files. Thus fid == lid for
+        *    all journals created after using initial_journal_create() alone.
+        * 2. By definition, if a journal is not full (num_used_jfiles < num_jfiles), then all owi flags for those files
+        *    that are used must be the same. It is not possible for an overwrite situation to arise if a journal is not
+        *    full.
+        * 3. This function acts on map _map only, and does not create any test files. Call journal_create() to do that.
+        * 4. This function must be called on a clean test object or on one where the previous test data has been
+        *    cleared by calling journal_destroy(). Running this function moret than once on existing data will
+        *    result in invalid journals which cannot be recovered.
+        */
+        void journal_create(const u_int16_t num_jfiles,      // Total number of files
+                                    const u_int16_t num_used_jfiles, // Number of used files, rest empty at end
+                                    const u_int16_t oldest_lid = 0,  // Fid where owi reverses
+                                    const bool first_owi = false)    // Value of first owi flag (ie fid=0)
+        {
+            const bool full = num_used_jfiles == num_jfiles;
+            bool owi = first_owi;
+            _oldest_lid = full ? oldest_lid : 0;
+            for (u_int16_t lid = 0; lid < num_jfiles; lid++)
+            {
+                const u_int16_t fid = lid;
+                file_hdr fh;
+                if (fid < num_used_jfiles)
+                {
+                    _num_used_files = num_used_jfiles;
+                    if (full && oldest_lid > 0 && lid == oldest_lid)
+                        owi = ~owi; // Flip owi if all files in use and oldest_lid > 0
+                    const u_int64_t frid = u_int64_t(random());
+                    init_fhdr(fh, frid, fid, lid, owi);
+                }
+                _map.insert(lfpair(lid, fh));
+            }
+        }
+
+        /*
+        * Method journal_append(): Used to simulate the insertion of journal files into an existing journal.
+        *
+        *   after_lid: The logical id (lid) after which the new file is to be inserted.
+        *   num_files: The number of files to be inserted.
+        * adjust_lids: Flag indicating that the lids of files _following_ the inserted files are to be adjusted upwards
+        *              by the number of inserted files. Not doing so simulates a recovery immediatly after insertion
+        *              but before the following files are overwritten with their new lids. If this is set false, then:
+        *              a) after_lid MUST be the most recent file (_oldest_lid-1 ie last lid before owi changes).
+        *              b) This call must be the last insert call.
+        *
+        * NOTES:
+        * 1. It is not possible to insert before lid/fid 0; thus these are always coincident. This operation is
+        *    logically equivilent to inserting after the last lid, which is possible.
+        * 2. It is not possible to append to a journal that is not full. Doing so will result in an unrecoverable
+        *    journal (one that is logically inconsistent that can never occur in reality).
+        * 3. If a journal is stopped/interrupted immediately after a file insertion, there could be duplicate lids in
+        *    play at recovery, as the following file lids in their headers are only overwritten when the file is
+        *    eventually written to during normal operation. The owi flags, however, are used to determine which of the
+        *    ambiguous lids are the inserted files.
+        */
+        void journal_insert(const u_int16_t after_lid,      // Insert files after this lid
+                            const u_int16_t num_files = 1,  // Number of files to insert
+                            const bool adjust_lids = true)  // Adjust lids following inserted files
+        {
+            _num_used_files += num_files;
+            const u_int16_t num_jfiles_before_append = _map.size();
+            lfmap_citr i = _map.find(after_lid);
+            if (i == _map.end()) BOOST_FAIL("Unable to find lid=" << after_lid << " in map.");
+            const file_hdr fh_before = (*i).second;
+
+            // Move overlapping lids (if req'd)
+            if (adjust_lids && after_lid < num_jfiles_before_append - 1)
+            {
+                for (u_int16_t lid = num_jfiles_before_append - 1; lid > after_lid; lid--)
+                {
+                    lfmap_citr itr = _map.find(lid);
+                    if (itr == _map.end()) BOOST_FAIL("Unable to find lid=" << after_lid << " in map.");
+                    file_hdr fh = itr->second;
+                    _map.erase(lid);
+                    fh._lid += num_files;
+                    if (lid == _oldest_lid)
+                        _oldest_lid += num_files;
+                    _map.insert(lfpair(fh._lid, fh));
+                }
+            }    
+
+            // Add new file headers
+            u_int16_t fid = num_jfiles_before_append;
+            u_int16_t lid = after_lid + 1;
+            while (fid < num_jfiles_before_append + num_files)
+            {
+                const u_int64_t frid = u_int64_t(random());
+                const size_t fro = 0x200;
+                const file_hdr fh(RHM_JDAT_FILE_MAGIC, RHM_JDAT_VERSION, frid, fid, lid, fro, fh_before.get_owi(), true);
+                _map.insert(lfpair(lid, fh));
+                _last_fid = fid;
+                fid++;
+                lid++;
+            }
+        }
+
+        void get_fid_list(vector<u_int16_t>& fid_list)
+        {
+            fid_list.clear();
+            for (lfmap_citr i = _map.begin(); i != _map.end(); i++)
+                fid_list.push_back(i->second._fid);
+        }
+
+        void get_lid_list(vector<u_int16_t>& lid_list)
+        {
+            lid_list.clear();
+            lid_list.assign(_map.size(), 0);
+            for (lfmap_citr i = _map.begin(); i != _map.end(); i++)
+                lid_list[i->second._fid] = i->first;
+        }
+
+        /*
+        * Method check_analysis(): Used to check the result of the test jinf object analysis by comparing the fid order
+        * array it produces against the internal map.
+        *
+        * ji: A ref to the jinf object under test.
+        */
+        void check_analysis(jinf& ji)   // jinf object under test after analyze() has been called
+        {
+            BOOST_CHECK_EQUAL(ji.get_first_fid(), get_first_fid());
+            BOOST_CHECK_EQUAL(ji.get_last_fid(), get_last_fid());
+
+            jinf::fid_list& fidl = ji.get_fid_list();
+            const u_int16_t num_jfiles = _map.size();
+            const bool all_used = _num_used_files == num_jfiles;
+            BOOST_CHECK_EQUAL(fidl.size(), _num_used_files);
+
+            const u_int16_t lid_start = all_used ? _oldest_lid : 0;
+            // Because a simulated failure would leave lid dups in map and last_fid would not exist in map in this
+            // case, we must find lid_stop via fid instead. Search for fid == num_files.
+            lfmap_citr itr = _map.begin();
+            while (itr != _map.end() && itr->second._fid != _num_used_files - 1) itr++;
+            if (itr == _map.end())
+                BOOST_FAIL("check(): Unable to find fid=" << (_num_used_files - 1) << " in map.");
+            const u_int16_t lid_stop = itr->second._lid;
+            
+            std::size_t fidl_index = 0;
+            for (u_int16_t lid_cnt = lid_start; lid_cnt < lid_stop; lid_cnt++, fidl_index++)
+            {
+                const u_int16_t lid = lid_cnt % num_jfiles;
+                lfmap_citr itr = _map.find(lid);
+                if (itr == _map.end())
+                    BOOST_FAIL("check(): Unable to find lid=" << lid << " in map.");
+                BOOST_CHECK_EQUAL(itr->second._fid, fidl[fidl_index]);
+            }
+        }
+
+        /*
+        * Method get_fid(): Look up a fid from a known lid.
+        */
+        u_int16_t get_fid(const u_int16_t lid, const bool initial_owi = false)
+        {
+            switch (_map.count(lid))
+            {
+                case 1:
+                    return _map.find(lid)->second._fid;
+                case 2:
+                    for (lfmap_citr itr = _map.lower_bound(lid); itr != _map.upper_bound(lid); itr++)
+                    {
+                        if (itr->second.get_owi() != initial_owi)
+                            return itr->second._fid;
+                    }
+                default:;
+            }
+            BOOST_FAIL("get_fid(): lid=" << lid << " not found in map.");
+            return 0xffff;
+        }
+
+        /*
+        * Method get_first_fid(): Look up the first (oldest, or next-to-be-overwritten) fid in the analysis sequence.
+        */
+        u_int16_t get_first_fid()
+        {
+            return get_fid(_oldest_lid);
+        }
+
+        /*
+        * Method get_last_fid(): Look up the last (newest, or most recently written) fid in the analysis sequence.
+        */
+        u_int16_t get_last_fid()
+        {
+            u_int16_t flid = 0;
+            if (_num_used_files == _map.size()) // journal full?
+            {
+                if (_oldest_lid)
+                {
+                    // if failed insert, cycle past duplicate lids
+                    while (_map.count(_oldest_lid) == 2)
+                        _oldest_lid++;
+                    while (_map.find(_oldest_lid) != _map.end() && _map.find(_oldest_lid)->second.get_owi() == false)
+                        _oldest_lid++;
+                    flid = _oldest_lid - 1;
+                }
+                else
+                    flid = _map.size() - 1;
+            }
+            else
+                flid = _num_used_files - 1;
+            return get_fid(flid, true);
+        }
+
+        /*
+        * Method create_journal(): Used to create the dummy journal files from the built-up map created by calling
+        * initial_journal_create() and optionally journal_append() one or more times. Since the jinf object reads the
+        * jinf file and the file headers only, the create object creates a dummy journal file containing only a file
+        * header (512 bytes each) and a single jinf file which contains the journal metadata required for recovery
+        * analysis.
+        */
+        void write_journal()
+        {
+            create_jinf();
+            u_int16_t fid = 0;
+            for (lfmap_citr itr = _map.begin(); itr != _map.end(); itr++, fid++)
+            {
+                if (itr->second._fid == 0 && itr->second._magic == 0) // empty header, use fid counter instaed
+                    create_journal_file(fid, itr->second, _base_filename);
+                else
+                    create_journal_file(itr->second._fid, itr->second, _base_filename);
+            }
+        }
+
+        /*
+        * Method destroy_journal(): Destroy the files created by create_journal() and reset the lid_fid_map test object.
+        * A new test may be started using the same lid_fid_map test object once this call has been made.
+        */
+        void destroy_journal()
+        {
+            for (u_int16_t fid = 0; fid < _map.size(); fid++)
+            {
+                string fn = create_journal_filename(fid, _base_filename);
+                BOOST_WARN_MESSAGE(::unlink(fn.c_str()) == 0, "destroy_journal(): Failed to remove file " << fn);
+            }
+            clean_journal_info_file(_base_filename);
+            _map.clear();
+            _num_used_files = 0;
+            _oldest_lid = 0;
+            _last_fid = 0;
+        }
+
+        /*
+        * Method create_new_jinf(): This static call creates a default jinf file only. This is used to test the read
+        * constructor of a jinf test object which reads a jinf file at instantiation.
+        */
+        static void create_new_jinf(const string jid, const string base_filename)
+        {
+            if (jdir::exists(test_dir))
+                jdir::delete_dir(test_dir);
+            create_jinf(NUM_JFILES, jid, base_filename);
+        }
+
+        /*
+        * Method clean_journal_info_file(): This static method deletes only a jinf file without harming any other
+        * journal file or its directory. This is used to clear those tests which rely only on the existance of a
+        * jinf file.
+        */
+        static void clean_journal_info_file(const string base_filename)
+        {
+            stringstream fn;
+            fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
+            BOOST_WARN_MESSAGE(::unlink(fn.str().c_str()) == 0, "clean_journal_info_file(): Failed to remove file " << fn.str());
+        }
+
+    private:
+        static void init_fhdr(file_hdr& fh,
+                              const u_int64_t frid,
+                              const u_int16_t fid,
+                              const u_int16_t lid,
+                              const bool owi,
+                              const bool no_enq = false)
+        {
+            fh._magic = RHM_JDAT_FILE_MAGIC;
+            fh._version = RHM_JDAT_VERSION;
+#if defined(JRNL_BIG_ENDIAN)
+            fh._eflag = RHM_BENDIAN_FLAG;
+#else
+            fh._eflag = RHM_LENDIAN_FLAG;
+#endif
+            fh._uflag = owi ? rec_hdr::HDR_OVERWRITE_INDICATOR_MASK : 0;
+            fh._rid = frid;
+            fh._fid = fid;
+            fh._lid = lid;
+            fh._fro = no_enq ? 0 : 0x200;
+            timespec ts;
+            ::clock_gettime(CLOCK_REALTIME, &ts);
+            fh._ts_sec = ts.tv_sec;
+            fh._ts_nsec = ts.tv_nsec;
+        }
+
+        void create_jinf()
+        {
+            if (jdir::exists(test_dir))
+                jdir::delete_dir(test_dir);
+            create_jinf(_map.size(), _jid, _base_filename);
+        }
+
+        static void create_jinf(u_int16_t num_files, const string jid, const string base_filename)
+        {
+            jdir::create_dir(test_dir); // Check test dir exists; create it if not
+            timespec ts;
+            ::clock_gettime(CLOCK_REALTIME, &ts);
+            jinf ji(jid, test_dir, base_filename, num_files, JFSIZE_SBLKS, JRNL_WMGR_DEF_PAGE_SIZE, JRNL_WMGR_DEF_PAGES,
+                    ts);
+            ji.write();
+        }
+
+        static void create_journal_file(const u_int16_t fid, const file_hdr& fh, const string base_filename)
+        {
+            write_file_header(fh, create_journal_filename(fid, base_filename));
+        }
+
+        static void write_file_header(const file_hdr& fh,
+                                      const string filename)
+        {
+            ofstream of(filename.c_str(), ofstream::out | ofstream::trunc);
+            if (!of.good())
+                BOOST_FAIL("Unable to open test journal file \"" << filename << "\" for writing.");
+
+            // write file header
+            u_int32_t cnt = sizeof(file_hdr);
+            of.write((const char*)&fh, cnt);
+            if (of.fail() || of.bad())
+                BOOST_FAIL("Error writing file header to test journal file \"" << filename << "\".");
+    
+            // fill remaining sblk with 0s
+            while (cnt++ < JRNL_DBLK_SIZE * JRNL_SBLK_SIZE)
+            {
+                of.put(0);
+                if (of.fail() || of.bad())
+                    BOOST_FAIL("Error writing filler to test journal file \"" << filename << "\".");
+            }
+
+            of.close();
+            if (of.fail() || of.bad())
+                BOOST_FAIL("Error closing test journal file \"" << filename << "\".");
+        }
+
+        static string create_journal_filename(const u_int16_t fid, const string base_filename)
+        {
+            stringstream fn;
+            fn << test_dir << "/" << base_filename << ".";
+            fn << setfill('0') << hex << setw(4) << fid << "." << JRNL_DATA_EXTENSION;
+            return fn.str();
+        }
+};
+
 const string
 get_test_name(const string& file, const string& test_name)
 {

Modified: store/trunk/cpp/tests/jrnl/_ut_jinf.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_ut_jinf.cpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/tests/jrnl/_ut_jinf.cpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -29,22 +29,10 @@
 
 #include "../unit_test.h"
 
-#include <cstring>
-#include <fstream>
-#include <iomanip>
+#include <cmath>
 #include <iostream>
-#include "jrnl/file_hdr.hpp"
-#include "jrnl/jcfg.hpp"
-#include "jrnl/jdir.hpp"
-#include "jrnl/jerrno.hpp"
-#include "jrnl/jexception.hpp"
-#include "jrnl/jinf.hpp"
-#include <map>
-#include <vector>
+#include "jrnl/jcntl.hpp"
 
-#define NUM_JFILES 4
-#define JFSIZE_SBLKS 128
-
 using namespace boost::unit_test;
 using namespace mrg::journal;
 using namespace std;
@@ -52,465 +40,19 @@
 QPID_AUTO_TEST_SUITE(jinf_suite)
 
 const string test_filename("_ut_jinf");
-const char* tdp = getenv("TMPDIR");
-const string test_dir(tdp && strlen(tdp) > 0 ? tdp : "/tmp/_ut_jinf");
 
-// === Helper functions ===
+#include "_st_helper_fns.hpp"
 
-const string jid("test journal id");
-const string base_filename("test_base_");
 timespec ts;
 
-/*
-* This test helper class is used by first setting up a map or "blueprint" of what the journal should
-* look like for recovery, then creating it. The jinf object under test then reads and analyzes the
-* created journal, and its analysis is checked against what is expected.
-*
-* General usage pattern:
-* 1. create instance of lid_fid_map.
-* 2. call lid_fid_map::initial_journal_create() to simulate initial journal creation.
-* 3. (optional) call lid_fid_map::journal_append() one or more times to simulate the addition of journal files.
-* 4. call lid_fid_map::create_journal() to create dummy journal files (files containing only file headers)
-* 5. create and initialize the jinf object under test
-* 6. call jinf::analyze() to determine the fid order - and thus also first and last lids
-* 7. call lid_fid_map::check_analysis() to check the conclusions of the analysis
-* 8. call lid_fid_map::destroy_journal() to delete the journal files and reset the lid_fid_map object.
-* 9. (optional) back to step 2 for more tests
-*
-* See the individual methods below for more details.
-*/
-class lid_fid_map
-{
-    public:
-        typedef pair<u_int16_t, file_hdr> lfpair;           // Used for loading the map
-        typedef multimap<u_int16_t, file_hdr> lfmap;        // Stores the journal "plan" before it is created on-disk
-        typedef lfmap::const_iterator lfmap_citr;           // General purpose iterator
-        typedef pair<lfmap_citr, lfmap_citr> lfmap_range;   // Range of values returned by multimap's equal_range() fn
-
-    private:
-        lfmap _map;                 // Stores the journal "blueprint" before it is created on-disk
-        u_int16_t _num_used_files;  // number of files which contain jorunals
-        u_int16_t _oldest_lid;      // lid where owi flips; always 0 if !_full
-        u_int16_t _last_fid;        // last fid (ie file added)
-
-    public:
-        lid_fid_map() : _num_used_files(0), _oldest_lid(0), _last_fid(0) {}
-        virtual ~lid_fid_map() {}
-
-        // Mainly used for debugging
-        void print()
-        {
-            int cnt = 0;
-            for (lfmap_citr i=_map.begin(); i!=_map.end(); i++, cnt++)
-            {
-                const file_hdr fh = i->second;
-                cout << "  " << cnt << ": owi=" << (fh.get_owi()?"t":"f") << hex << " frid=0x" << fh._rid;
-                cout << " fid=0x" << fh._fid << " lid=0x" << fh._lid << " fro=0x" << fh._fro << dec << endl;
-            }
-        }
-
-        std::size_t size()
-        {
-            return _map.size();
-        }
-
-        /*
-        * Method initial_journal_create(): Used to simulate the initial creation of a journal before file insertions
-        * take place.
-        *
-        *      num_jfiles: The initial journal file count.
-        * num_used_jfiles: If this number is less than num_jfiles, it indicates a clean journal that has not yet
-        *                  completed its first rotation, and some files are empty (ie all null). The first
-        *                  num_used_jfiles will contain file headers, the remainder will be blank.
-        *      oldest_lid: The lid (==fid, see note 1 below) at which the owi flag flips. During normal operation, each
-        *                  time the journal rotates back to file 0, a flag (called the overwrite indicator or owi) is
-        *                  flipped. This flag is saved in the file header. During recovery, if scanning from logical
-        *                  file 0 upwards, the file at which this flag reverses from its value in file 0 is the file
-        *                  that was to have been overwritten next, and is thus the "oldest" file. Recovery analysis must
-        *                  start with this file. oldest_lid sets the file at which this flag will flip value for the
-        *                  simulated recovery analysis. Note that this will be ignored if num_used_jfiles < num_jfiles,
-        *                  as it is not possible for an overwrite to have occurred if not all the files have been used.
-        *       first_owi: Sets the value of the owi flag in file 0. If set to false, then the flip will be found with
-        *                  a true flag (and visa versa).
-        *
-        * NOTES:
-        * 1. By definition, the lids and fids coincide for a journal containing no inserted files. Thus fid == lid for
-        *    all journals created after using initial_journal_create() alone.
-        * 2. By definition, if a journal is not full (num_used_jfiles < num_jfiles), then all owi flags for those files
-        *    that are used must be the same. It is not possible for an overwrite situation to arise if a journal is not
-        *    full.
-        * 3. This function acts on map _map only, and does not create any test files. Call journal_create() to do that.
-        * 4. This function must be called on a clean test object or on one where the previous test data has been
-        *    cleared by calling journal_destroy(). Running this function moret than once on existing data will
-        *    result in invalid journals which cannot be recovered.
-        */
-        void initial_journal_create(const u_int16_t num_jfiles,      // Total number of files
-                                    const u_int16_t num_used_jfiles, // Number of used files, rest empty at end
-                                    const u_int16_t oldest_lid = 0,  // Fid where owi reverses
-                                    const bool first_owi = false)    // Value of first owi flag (ie fid=0)
-        {
-            const bool full = num_used_jfiles == num_jfiles;
-            bool owi = first_owi;
-            _oldest_lid = full ? oldest_lid : 0;
-            for (u_int16_t lid = 0; lid < num_jfiles; lid++)
-            {
-                const u_int16_t fid = lid;
-                file_hdr fh;
-                if (fid < num_used_jfiles)
-                {
-                    _num_used_files = num_used_jfiles;
-                    if (full && oldest_lid > 0 && lid == oldest_lid)
-                        owi = ~owi; // Flip owi if all files in use and oldest_lid > 0
-                    const u_int64_t frid = u_int64_t(random());
-                    init_fhdr(fh, frid, fid, lid, owi);
-                }
-                _map.insert(lfpair(lid, fh));
-            }
-        }
-
-        /*
-        * Method journal_append(): Used to simulate the addition of journal files into an existing journal. When one or
-        * more files are inserted after a particular lid, the lids of the following files are incremented. The fids of
-        * the inserted files follow those of all existing files, thus leading to a lid-fid discreppancy.
-        *
-        * Example: Before insertion:
-        *          Logical view:                                Physical view:
-        *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
-        *  lid --> | 0 | 1 | 2 | 3 | 4 | 5 |            lid --> | 0 | 1 | 2 | 3 | 4 | 5 |
-        *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
-        *  fid -->   0   1   2   3   4   5              fid -->   0   1   2   3   4   5
-        * 
-        * After insertion of 2 files after lid 2 (marked with *s):
-        *          Logical view:                                Physical view:
-        *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
-        *  lid --> | 0 | 1 | 2 |*3*|*4*| 5 | 6 | 7 |    lid --> | 0 | 1 | 2 | 5 | 6 | 7 |*3*|*4*|
-        *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
-        *  fid -->   0   1   2   6   7   3   4   5      fid -->   0   1   2   3   4   5   6   7
-        *
-        * Note that the journal only writes file headers (and hence the lids in those headers) as the files are
-        * overwritten. If the journal should fail after insertion but before the files following those inserted are
-        * overwritten, then duplicate lids will be present (though no duplicate fids are possible). The overwrite
-        * indicator (owi) flag and the fid numbers may be used to resolve the ambiguity and determine the logically
-        * earlier lid in this case as follows:
-        *
-        * Example: Before insertion:
-        *          Logical view:                                Physical view:
-        *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
-        *  lid --> | 0 | 1 | 2 | 3 | 4 | 5 |            lid --> | 0 | 1 | 2 | 3 | 4 | 5 |
-        *  owi --> | t | t | t | f | f | f |            owi --> | t | t | t | f | f | f |
-        *          +---+---+---+---+---+---+                    +---+---+---+---+---+---+
-        *  fid -->   0   1   2   3   4   5              fid -->   0   1   2   3   4   5
-        * 
-        * After insertion of 2 files after lid 2 (marked with *s) and failure:
-        *          Logical view:                                Physical view:
-        *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
-        *  lid --> | 0 | 1 | 2 |*3*|*4*| 3 | 4 | 5 |    lid --> | 0 | 1 | 2 | 3 | 4 | 5 |*3*|*4*|
-        *  owi --> | t | t | t | t | t | f | f | f |    owi --> | t | t | t | f | f | f | t | t |
-        *          +---+---+---+---+---+---+---+---+            +---+---+---+---+---+---+---+---+
-        *  fid -->   0   1   2   6   7   3   4   5      fid -->   0   1   2   3   4   5   6   7
-        *
-        * Test 1: Correct lid has owi flag that matches that of fid/lid 0
-        * Test 2: Correct lid has higher fids
-        *
-        *   after_lid: The logical id (lid) after which the new file is to be inserted.
-        *   num_files: The number of files to be inserted.
-        * adjust_lids: Flag indicating that the lids of files _following_ the inserted files are to be adjusted upwards
-        *              by the number of inserted files. Not doing so simulates a recovery immediatly after insertion
-        *              but before the following files are overwritten with their new lids. If this is set false, then:
-        *              a) after_lid MUST be the most recent file (_oldest_lid-1 ie last lid before owi changes).
-        *              b) This call must be the last insert call.
-        *
-        * NOTES:
-        * 1. It is not possible to insert before lid/fid 0; thus these are always coincident. This operation is
-        *    logically equivilent to inserting after the last lid, which is possible.
-        * 2. It is not possible to append to a journal that is not full. Doing so will result in an unrecoverable
-        *    journal (one that is logically inconsistent that can never occur in reality).
-        * 3. If a journal is stopped/interrupted immediately after a file insertion, there could be duplicate lids in
-        *    play at recovery, as the following file lids in their headers are only overwritten when the file is
-        *    eventually written to during normal operation. The owi flags, however, are used to determine which of the
-        *    ambiguous lids are the inserted files.
-        */
-        void journal_append(const u_int16_t after_lid,      // Insert files after this lid
-                            const u_int16_t num_files = 1,  // Number of files to insert
-                            const bool adjust_lids = true)  // Adjust lids following inserted files
-        {
-            _num_used_files += num_files;
-            const u_int16_t num_jfiles_before_append = _map.size();
-            lfmap_citr i = _map.find(after_lid);
-            if (i == _map.end()) BOOST_FAIL("Unable to find lid=" << after_lid << " in map.");
-            const file_hdr fh_before = (*i).second;
-
-            // Move overlapping lids (if req'd)
-            if (adjust_lids && after_lid < num_jfiles_before_append - 1)
-            {
-                for (u_int16_t lid = num_jfiles_before_append - 1; lid > after_lid; lid--)
-                {
-                    lfmap_citr itr = _map.find(lid);
-                    if (itr == _map.end()) BOOST_FAIL("Unable to find lid=" << after_lid << " in map.");
-                    file_hdr fh = itr->second;
-                    _map.erase(lid);
-                    fh._lid += num_files;
-                    if (lid == _oldest_lid)
-                        _oldest_lid += num_files;
-                    _map.insert(lfpair(fh._lid, fh));
-                }
-            }    
-
-            // Add new file headers
-            u_int16_t fid = num_jfiles_before_append;
-            u_int16_t lid = after_lid + 1;
-            while (fid < num_jfiles_before_append + num_files)
-            {
-                const u_int64_t frid = u_int64_t(random());
-                const size_t fro = 0x200;
-                const file_hdr fh(RHM_JDAT_FILE_MAGIC, RHM_JDAT_VERSION, frid, fid, lid, fro, fh_before.get_owi(), true);
-                _map.insert(lfpair(lid, fh));
-                _last_fid = fid;
-                fid++;
-                lid++;
-            }
-        }
-
-        /*
-        * Method check_analysis(): Used to check the result of the test jinf object analysis by comparing the fid order
-        * array it produces against the internal map.
-        *
-        * ji: A ref to the jinf object under test.
-        */
-        void check_analysis(jinf& ji)   // jinf object under test after analyze() has been called
-        {
-            BOOST_CHECK_EQUAL(ji.get_first_fid(), get_first_fid());
-            BOOST_CHECK_EQUAL(ji.get_last_fid(), get_last_fid());
-
-            jinf::fid_list& fidl = ji.get_fid_list();
-            const u_int16_t num_jfiles = _map.size();
-            const bool all_used = _num_used_files == num_jfiles;
-            BOOST_CHECK_EQUAL(fidl.size(), _num_used_files);
-
-            const u_int16_t lid_start = all_used ? _oldest_lid : 0;
-            // Because a simulated failure would leave lid dups in map and last_fid would not exist in map in this
-            // case, we must find lid_stop via fid instead. Search for fid == num_files.
-            lfmap_citr itr = _map.begin();
-            while (itr != _map.end() && itr->second._fid != _num_used_files - 1) itr++;
-            if (itr == _map.end())
-                BOOST_FAIL("check(): Unable to find fid=" << (_num_used_files - 1) << " in map.");
-            const u_int16_t lid_stop = itr->second._lid;
-            
-            std::size_t fidl_index = 0;
-            for (u_int16_t lid_cnt = lid_start; lid_cnt < lid_stop; lid_cnt++, fidl_index++)
-            {
-                const u_int16_t lid = lid_cnt % num_jfiles;
-                lfmap_citr itr = _map.find(lid);
-                if (itr == _map.end())
-                    BOOST_FAIL("check(): Unable to find lid=" << lid << " in map.");
-                BOOST_CHECK_EQUAL(itr->second._fid, fidl[fidl_index]);
-            }
-        }
-
-        /*
-        * Method get_fid(): Look up a fid from a known lid.
-        */
-        u_int16_t get_fid(const u_int16_t lid, const bool initial_owi = false)
-        {
-            switch (_map.count(lid))
-            {
-                case 1:
-                    return _map.find(lid)->second._fid;
-                case 2:
-                    for (lfmap_citr itr = _map.lower_bound(lid); itr != _map.upper_bound(lid); itr++)
-                    {
-                        if (itr->second.get_owi() != initial_owi)
-                            return itr->second._fid;
-                    }
-                default:;
-            }
-            BOOST_FAIL("get_fid(): lid=" << lid << " not found in map.");
-            return 0xffff;
-        }
-
-        /*
-        * Method get_first_fid(): Look up the first (oldest, or next-to-be-overwritten) fid in the analysis sequence.
-        */
-        u_int16_t get_first_fid()
-        {
-            return get_fid(_oldest_lid);
-        }
-
-        /*
-        * Method get_last_fid(): Look up the last (newest, or most recently written) fid in the analysis sequence.
-        */
-        u_int16_t get_last_fid()
-        {
-            u_int16_t flid = 0;
-            if (_num_used_files == _map.size()) // journal full?
-            {
-                if (_oldest_lid)
-                {
-                    // if failed insert, cycle past duplicate lids
-                    while (_map.count(_oldest_lid) == 2)
-                        _oldest_lid++;
-                    while (_map.find(_oldest_lid) != _map.end() && _map.find(_oldest_lid)->second.get_owi() == false)
-                        _oldest_lid++;
-                    flid = _oldest_lid - 1;
-                }
-                else
-                    flid = _map.size() - 1;
-            }
-            else
-                flid = _num_used_files - 1;
-            return get_fid(flid, true);
-        }
-
-        /*
-        * Method create_journal(): Used to create the dummy journal files from the built-up map created by calling
-        * initial_journal_create() and optionally journal_append() one or more times. Since the jinf object reads the
-        * jinf file and the file headers only, the create object creates a dummy journal file containing only a file
-        * header (512 bytes each) and a single jinf file which contains the journal metadata required for recovery
-        * analysis.
-        */
-        void create_journal()
-        {
-            create_jinf();
-            u_int16_t fid = 0;
-            for (lfmap_citr itr = _map.begin(); itr != _map.end(); itr++, fid++)
-            {
-                if (itr->second._fid == 0 && itr->second._magic == 0) // empty header, use fid counter instaed
-                    create_journal_file(fid, itr->second);
-                else
-                    create_journal_file(itr->second._fid, itr->second);
-            }
-        }
-
-        /*
-        * Method destroy_journal(): Destroy the files created by create_journal() and reset the lid_fid_map test object.
-        * A new test may be started using the same lid_fid_map test object once this call has been made.
-        */
-        void destroy_journal()
-        {
-            for (u_int16_t fid = 0; fid < _map.size(); fid++)
-            {
-                string fn = create_journal_filename(fid);
-                BOOST_WARN_MESSAGE(::unlink(fn.c_str()) == 0, "destroy_journal(): Failed to remove file " << fn);
-            }
-            clean_journal_info_file();
-            _map.clear();
-            _num_used_files = 0;
-            _oldest_lid = 0;
-            _last_fid = 0;
-        }
-
-        /*
-        * Method create_new_jinf(): This static call creates a default jinf file only. This is used to test the read
-        * constructor of a jinf test object which reads a jinf file at instantiation.
-        */
-        static void create_new_jinf()
-        {
-            if (jdir::exists(test_dir))
-                jdir::delete_dir(test_dir);
-            create_jinf(NUM_JFILES);
-        }
-
-        /*
-        * Method clean_journal_info_file(): This static method deletes only a jinf file without harming any other
-        * journal file or its directory. This is used to clear those tests which rely only on the existance of a
-        * jinf file.
-        */
-        static void clean_journal_info_file()
-        {
-            stringstream fn;
-            fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
-            BOOST_WARN_MESSAGE(::unlink(fn.str().c_str()) == 0, "clean_journal_info_file(): Failed to remove file " << fn.str());
-        }
-
-    private:
-        static void init_fhdr(file_hdr& fh,
-                              const u_int64_t frid,
-                              const u_int16_t fid,
-                              const u_int16_t lid,
-                              const bool owi,
-                              const bool no_enq = false)
-        {
-            fh._magic = RHM_JDAT_FILE_MAGIC;
-            fh._version = RHM_JDAT_VERSION;
-#if defined(JRNL_BIG_ENDIAN)
-            fh._eflag = RHM_BENDIAN_FLAG;
-#else
-            fh._eflag = RHM_LENDIAN_FLAG;
-#endif
-            fh._uflag = owi ? rec_hdr::HDR_OVERWRITE_INDICATOR_MASK : 0;
-            fh._rid = frid;
-            fh._fid = fid;
-            fh._lid = lid;
-            fh._fro = no_enq ? 0 : 0x200;
-            timespec ts;
-            ::clock_gettime(CLOCK_REALTIME, &ts);
-            fh._ts_sec = ts.tv_sec;
-            fh._ts_nsec = ts.tv_nsec;
-        }
-
-        void create_jinf()
-        {
-            if (jdir::exists(test_dir))
-                jdir::delete_dir(test_dir);
-            create_jinf(_map.size());
-        }
-
-        static void create_jinf(u_int16_t num_files)
-        {
-            jdir::create_dir(test_dir); // Check test dir exists; create it if not
-            ::clock_gettime(CLOCK_REALTIME, &ts);
-            jinf ji(jid, test_dir, base_filename, num_files, JFSIZE_SBLKS, JRNL_WMGR_DEF_PAGE_SIZE, JRNL_WMGR_DEF_PAGES,
-                    ts);
-            ji.write();
-        }
-
-        static void create_journal_file(const u_int16_t fid, const file_hdr& fh)
-        {
-            write_file_header(fh, create_journal_filename(fid));
-        }
-
-        static void write_file_header(const file_hdr& fh,
-                                      const string filename)
-        {
-            ofstream of(filename.c_str(), ofstream::out | ofstream::trunc);
-            if (!of.good())
-                BOOST_FAIL("Unable to open test journal file \"" << filename << "\" for writing.");
-
-            // write file header
-            u_int32_t cnt = sizeof(file_hdr);
-            of.write((const char*)&fh, cnt);
-            if (of.fail() || of.bad())
-                BOOST_FAIL("Error writing file header to test journal file \"" << filename << "\".");
-    
-            // fill remaining sblk with 0s
-            while (cnt++ < JRNL_DBLK_SIZE * JRNL_SBLK_SIZE)
-            {
-                of.put(0);
-                if (of.fail() || of.bad())
-                    BOOST_FAIL("Error writing filler to test journal file \"" << filename << "\".");
-            }
-
-            of.close();
-            if (of.fail() || of.bad())
-                BOOST_FAIL("Error closing test journal file \"" << filename << "\".");
-        }
-
-        static string create_journal_filename(const u_int16_t fid)
-        {
-            stringstream fn;
-            fn << test_dir << "/" << base_filename << ".";
-            fn << setfill('0') << hex << setw(4) << fid << "." << JRNL_DATA_EXTENSION;
-            return fn.str();
-        }
-};
-
 QPID_AUTO_TEST_CASE(write_constructor)
 {
-    cout << test_filename << ".write_constructor: " << flush;
+    string test_name = get_test_name(test_filename, "write_constructor");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
     jdir::create_dir(test_dir); // Check test dir exists; create it if not
     ::clock_gettime(CLOCK_REALTIME, &ts);
-    jinf ji(jid, test_dir, base_filename, NUM_JFILES, JFSIZE_SBLKS, JRNL_WMGR_DEF_PAGE_SIZE,
-            JRNL_WMGR_DEF_PAGES, ts);
+    jinf ji(jid, test_dir, base_filename, NUM_JFILES, JFSIZE_SBLKS, JRNL_WMGR_DEF_PAGE_SIZE, JRNL_WMGR_DEF_PAGES, ts);
     BOOST_CHECK_EQUAL(ji.jver(), RHM_JDAT_VERSION);
     BOOST_CHECK(ji.jid().compare(jid) == 0);
     BOOST_CHECK(ji.jdir().compare(test_dir) == 0);
@@ -532,19 +74,21 @@
 
 QPID_AUTO_TEST_CASE(read_constructor)
 {
-    cout << test_filename << ".read_constructor: " << flush;
-    lid_fid_map::create_new_jinf();
+    string test_name = get_test_name(test_filename, "read_constructor");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map::create_new_jinf(jid, base_filename);
 
     stringstream fn;
-    fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
+    fn << test_dir << "/" <<base_filename  << "." << JRNL_INFO_EXTENSION;
     jinf ji(fn.str(), false);
     BOOST_CHECK_EQUAL(ji.jver(), RHM_JDAT_VERSION);
     BOOST_CHECK(ji.jid().compare(jid) == 0);
     BOOST_CHECK(ji.jdir().compare(test_dir) == 0);
     BOOST_CHECK(ji.base_filename().compare(base_filename) == 0);
     const timespec this_ts = ji.ts();
-    BOOST_CHECK_EQUAL(this_ts.tv_sec, ts.tv_sec);
-    BOOST_CHECK_EQUAL(this_ts.tv_nsec, ts.tv_nsec);
+//     BOOST_CHECK_EQUAL(this_ts.tv_sec, ts.tv_sec);
+//     BOOST_CHECK_EQUAL(this_ts.tv_nsec, ts.tv_nsec);
     BOOST_CHECK_EQUAL(ji.num_jfiles(), u_int16_t(NUM_JFILES));
     BOOST_CHECK_EQUAL(ji.jfsize_sblks(), u_int32_t(JFSIZE_SBLKS));
     BOOST_CHECK_EQUAL(ji.sblk_size_dblks(), u_int16_t(JRNL_SBLK_SIZE));
@@ -559,8 +103,10 @@
 
 QPID_AUTO_TEST_CASE(set_functions)
 {
-    cout << test_filename << ".set_functions: " << flush;
-    lid_fid_map::create_new_jinf();
+    string test_name = get_test_name(test_filename, "set_functions");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map::create_new_jinf(jid, base_filename);
 
     stringstream fn;
     fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
@@ -575,32 +121,36 @@
     ji.incr_num_jfiles();
     BOOST_CHECK_EQUAL(ji.num_jfiles(), u_int16_t(NUM_JFILES+2));
 
-    lid_fid_map::clean_journal_info_file();
+    lid_fid_map::clean_journal_info_file(test_dir);
     cout << "done" << endl;
 }
 
 QPID_AUTO_TEST_CASE(validate)
 {
-    cout << test_filename << ".validate: " << flush;
-    lid_fid_map::create_new_jinf();
+    string test_name = get_test_name(test_filename, "validate");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map::create_new_jinf(jid, base_filename);
 
     stringstream fn;
     fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
     jinf ji(fn.str(), true);
     // TODO: Check validation picks up conflict, but need to be friend to jinf to do it
 
-    lid_fid_map::clean_journal_info_file();
+    lid_fid_map::clean_journal_info_file(test_dir);
     cout << "done" << endl;
 }
  
 QPID_AUTO_TEST_CASE(analyze_empty_journal)
 {
-    cout << test_filename << ".analyze_empty_journal: " << flush;
+    string test_name = get_test_name(test_filename, "analyze_empty_journal");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
     jdir::create_dir(test_dir); // Check test dir exists; create it if not
 
-    lid_fid_map m;
-    m.initial_journal_create(NUM_JFILES, 0, 0);
-    m.create_journal();
+    lid_fid_map m(jid, base_filename);
+    m.journal_create(NUM_JFILES, 0, 0);
+    m.write_journal();
 
     stringstream fn;
     fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
@@ -618,12 +168,14 @@
 
 QPID_AUTO_TEST_CASE(analyze_part_full_journal)
 {
-    cout << test_filename << ".analyze_part_full_journal: " << flush;
-    lid_fid_map m;
+    string test_name = get_test_name(test_filename, "analyze_part_full_journal");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map m(jid, base_filename);
     for (u_int16_t num_files = 1; num_files < NUM_JFILES; num_files++)
     {
-        m.initial_journal_create(NUM_JFILES, num_files, 0);
-        m.create_journal();
+        m.journal_create(NUM_JFILES, num_files, 0);
+        m.write_journal();
 
         stringstream fn;
         fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
@@ -638,12 +190,14 @@
 
 QPID_AUTO_TEST_CASE(analyze_full_journal)
 {
-    cout << test_filename << ".analyze_full_journal: " << flush;
-    lid_fid_map m;
+    string test_name = get_test_name(test_filename, "analyze_full_journal");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map m(jid, base_filename);
     for (u_int16_t file_num = 0; file_num < NUM_JFILES; file_num++)
     {
-        m.initial_journal_create(NUM_JFILES, NUM_JFILES, file_num);
-        m.create_journal();
+        m.journal_create(NUM_JFILES, NUM_JFILES, file_num);
+        m.write_journal();
 
         stringstream fn;
         fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
@@ -658,15 +212,17 @@
 
 QPID_AUTO_TEST_CASE(analyze_single_appended_journal)
 {
-    cout << test_filename << ".analyze_single_appended_journal: " << flush;
-    lid_fid_map m;
+    string test_name = get_test_name(test_filename, "analyze_single_appended_journal");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map m(jid, base_filename);
     for (u_int16_t oldest_lid = 0; oldest_lid < NUM_JFILES; oldest_lid++)
         for (u_int16_t after_lid = 0; after_lid < NUM_JFILES; after_lid++)
             for (u_int16_t num_files = 1; num_files <= 5; num_files++)
             {
-                m.initial_journal_create(NUM_JFILES, NUM_JFILES, oldest_lid);
-                m.journal_append(after_lid, num_files);
-                m.create_journal();
+                m.journal_create(NUM_JFILES, NUM_JFILES, oldest_lid);
+                m.journal_insert(after_lid, num_files);
+                m.write_journal();
 
                 stringstream fn;
                 fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
@@ -681,21 +237,23 @@
 
 QPID_AUTO_TEST_CASE(analyze_multi_appended_journal)
 {
-    cout << test_filename << ".analyze_multi_appended_journal: " << flush;
-    lid_fid_map m;
+    string test_name = get_test_name(test_filename, "analyze_multi_appended_journal");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map m(jid, base_filename);
     ::srand48(1);
 
     for (u_int16_t num_appends = 1; num_appends <= 2*NUM_JFILES; num_appends++)
     {
         const u_int16_t oldest_lid = u_int16_t(NUM_JFILES * ::drand48());
-        m.initial_journal_create(NUM_JFILES, NUM_JFILES, oldest_lid);
+        m.journal_create(NUM_JFILES, NUM_JFILES, oldest_lid);
         for (u_int16_t a = 0; a < num_appends; a++)
         {
             const u_int16_t num_files = u_int16_t(1 + (NUM_JFILES * ::drand48()));
             const u_int16_t after_lid = u_int16_t(m.size() * ::drand48());
-            m.journal_append(after_lid, num_files);
+            m.journal_insert(after_lid, num_files);
         }
-        m.create_journal();
+        m.write_journal();
 
         stringstream fn;
         fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;
@@ -711,8 +269,10 @@
 
 QPID_AUTO_TEST_CASE(analyze_multi_appended_then_failed_journal)
 {
-    cout << test_filename << ".analyze_multi_appended_then_failed_journal: " << flush;
-    lid_fid_map m;
+    string test_name = get_test_name(test_filename, "analyze_multi_appended_then_failed_journal");
+    const string jid = test_name + "_jid";
+    const string base_filename = test_name + "_bfn";
+    lid_fid_map m(jid, base_filename);
     ::srand48(1);
 
     // As this test relies on repeatable but random sequences, use many ierations for coverage
@@ -721,19 +281,19 @@
         for (u_int16_t num_appends = 1; num_appends <= 2*NUM_JFILES; num_appends++)
         {
             u_int16_t oldest_lid = u_int16_t(NUM_JFILES * ::drand48());
-            m.initial_journal_create(NUM_JFILES, NUM_JFILES, oldest_lid);
+            m.journal_create(NUM_JFILES, NUM_JFILES, oldest_lid);
             for (u_int16_t a = 0; a < num_appends-1; a++)
             {
                 const u_int16_t num_files = u_int16_t(1 + (NUM_JFILES * ::drand48()));
                 const u_int16_t after_lid = u_int16_t(m.size() * ::drand48());
-                m.journal_append(after_lid, num_files);
+                m.journal_insert(after_lid, num_files);
                 if (after_lid < oldest_lid)
                     oldest_lid += num_files;
             }
             const u_int16_t num_files = u_int16_t(1 + (NUM_JFILES * ::drand48()));
             const u_int16_t after_lid = oldest_lid == 0 ? m.size() - 1 : oldest_lid - 1;
-            m.journal_append(after_lid, num_files, false);
-            m.create_journal();
+            m.journal_insert(after_lid, num_files, false);
+            m.write_journal();
 
             stringstream fn;
             fn << test_dir << "/" << base_filename << "." << JRNL_INFO_EXTENSION;

Modified: store/trunk/cpp/tests/jrnl/_ut_lfmgr.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_ut_lfmgr.cpp	2008-10-10 14:39:37 UTC (rev 2617)
+++ store/trunk/cpp/tests/jrnl/_ut_lfmgr.cpp	2008-10-10 15:19:26 UTC (rev 2618)
@@ -43,181 +43,123 @@
 
 #include "_st_helper_fns.hpp"
 
-// Helper functions and definitions
+// === Helper functions and definitions ===
 
 typedef vector<u_int16_t> flist;
 typedef flist::const_iterator flist_citr;
-typedef pair<u_int16_t, u_int16_t> flpair;
-typedef map<u_int16_t, u_int16_t> flmap;
-typedef flmap::iterator flmap_itr;
-typedef flmap::const_iterator flmap_citr;
 
-void
-load_vector(const u_int16_t a[], const size_t n, flist& v)
+class lfmgr_test_helper
 {
-    for (size_t i = 0; i < n; i++)
-        v.push_back(a[i]);
-}
+    lfmgr_test_helper() {}
+    virtual ~lfmgr_test_helper() {}
 
-void
-vectors_equal(const lfmgr& lm, const u_int16_t a[], const size_t n, const flist& b, const bool fid_check)
-{
-    BOOST_CHECK_EQUAL(n, b.size());
-    for (size_t i = 0; i < n; i++)
+public:
+    static void check_fids_lids(const lfmgr& lm, const u_int16_t fids[], const u_int16_t lids[],
+            const size_t fid_lid_size)
     {
-        BOOST_CHECK_EQUAL(a[i], b[i]);
-        fcntl* fp = lm.get_fcntlp(i);
-        BOOST_CHECK(fp != (void*)0);
-        if (fp) BOOST_CHECK_EQUAL(fid_check ? fp->fid() : fp->lid(), fid_check ? a[i] : i);
+        vector<u_int16_t> res;
+        lm.get_fid_list(res);
+        vectors_equal(lm, fids, fid_lid_size, res, true);
+        lm.get_lid_list(res);
+        vectors_equal(lm, lids, fid_lid_size, res, false);
     }
-}
 
-void
-vectors_equal(const lfmgr& lm, const flist& a, const flist& b, const bool fid_check)
-{
-    BOOST_CHECK_EQUAL(a.size(), b.size());
-    for (size_t i = 0; i < a.size(); i++)
+    static void check_fids_lids(const lfmgr& lm, const flist& fids, const flist lids)
     {
-        BOOST_CHECK_EQUAL(a[i], b[i]);
-        fcntl* fp = lm.get_fcntlp(i);
-        BOOST_CHECK(fp != (void*)0);
-        if (fp) BOOST_CHECK_EQUAL(fid_check ? fp->fid() : fp->lid(), fid_check ? a[i] : i);
+        vector<u_int16_t> res;
+        lm.get_fid_list(res);
+        vectors_equal(lm, fids, res, true);
+        lm.get_lid_list(res);
+        vectors_equal(lm, lids, res, false);
     }
-}
 
-void
-linear_vectors_equal(const lfmgr& lm, const size_t n, const flist& f, const bool fid_check)
-{
-    BOOST_CHECK_EQUAL(n, f.size());
-    for (size_t i = 0; i < n; i++)
+    static void check_linear_fids_lids(const lfmgr& lm, const size_t fid_lid_size)
     {
-        BOOST_CHECK_EQUAL(i, f[i]);
-        fcntl* fp = lm.get_fcntlp(i);
-        BOOST_CHECK(fp != (void*)0);
-        if (fp) BOOST_CHECK_EQUAL(fid_check ? fp->fid() : fp->lid(), i);
+        vector<u_int16_t> res;
+        lm.get_fid_list(res);
+        linear_vectors_equal(lm, fid_lid_size, res, true);
+        lm.get_lid_list(res);
+        linear_vectors_equal(lm, fid_lid_size, res, false);
     }
-}
 
-void
-linear_vectors_equal(const lfmgr& lm, const flist& f, const bool fid_check)
-{
-    for (size_t i = 0; i < f.size(); i++)
+    static void rcvdat_init(rcvdat& rd, const u_int16_t num_jfiles, const u_int16_t fids[])
     {
-        BOOST_CHECK_EQUAL(i, f[i]);
-        fcntl* fp = lm.get_fcntlp(i);
-        BOOST_CHECK(fp != (void*)0);
-        if (fp) BOOST_CHECK_EQUAL(fid_check ? fp->fid() : fp->lid(), i);
+        rd.reset(num_jfiles);
+        load_vector(fids, num_jfiles, rd._fid_list);
+        rd._jempty = false;
+        rd._lfid = fids[num_jfiles - 1];
+        rd._eo = 100 * JRNL_DBLK_SIZE * JRNL_SBLK_SIZE;
     }
-}
 
-void
-check_fids_lids(const lfmgr& lm, const u_int16_t fids[], const u_int16_t lids[], const size_t fid_lid_size)
-{
-    vector<u_int16_t> res;
-    lm.get_fid_list(res);
-    vectors_equal(lm, fids, fid_lid_size, res, true);
-    lm.get_lid_list(res);
-    vectors_equal(lm, lids, fid_lid_size, res, false);
-}
+    static void rcvdat_init(rcvdat& rd, const flist& fidl)
+    {
+        const u_int16_t num_jfiles = fidl.size();
+        rd.reset(num_jfiles);
+        load_vector(fidl, rd._fid_list);
+        rd._jempty = false;
+        rd._lfid = fidl[num_jfiles - 1];
+        rd._eo = 100 * JRNL_DBLK_SIZE * JRNL_SBLK_SIZE;
+    }
 
-void
-check_fids_lids(const lfmgr& lm, const flist& fids, const flist lids)
-{
-    vector<u_int16_t> res;
-    lm.get_fid_list(res);
-    vectors_equal(lm, fids, res, true);
-    lm.get_lid_list(res);
-    vectors_equal(lm, lids, res, false);
-}
+private:
+    static void load_vector(const u_int16_t a[], const size_t n, flist& v)
+    {
+        for (size_t i = 0; i < n; i++)
+            v.push_back(a[i]);
+    }
 
-void
-check_linear_fids_lids(const lfmgr& lm, const size_t fid_lid_size)
-{
-    vector<u_int16_t> res;
-    lm.get_fid_list(res);
-    linear_vectors_equal(lm, fid_lid_size, res, true);
-    lm.get_lid_list(res);
-    linear_vectors_equal(lm, fid_lid_size, res, false);
-}
+    static void load_vector(const flist& a, flist& b)
+    {
+        for (flist_citr i = a.begin(); i < a.end(); i++)
+            b.push_back(*i);
+    }
 
-void
-map_init(flmap& m, const u_int16_t num_jfiles)
-{
-    m.clear();
-    for (u_int16_t i=0; i<num_jfiles; i++)
-        m.insert(flpair(i, i));
-}
+    static void vectors_equal(const lfmgr& lm, const u_int16_t a[], const size_t n, const flist& b,
+            const bool fid_check)
+    {
+        BOOST_CHECK_EQUAL(n, b.size());
+        for (size_t i = 0; i < n; i++)
+        {
+            BOOST_CHECK_EQUAL(a[i], b[i]);
+            fcntl* fp = lm.get_fcntlp(i);
+            BOOST_CHECK_MESSAGE(fp != (void*)0, "Unexpected void pointer returned by lfmgr::get_fcntlp()");
+            if (fp) BOOST_CHECK_EQUAL(fid_check ? fp->fid() : fp->lid(), fid_check ? a[i] : i);
+        }
+    }
 
-void
-map_recover(flmap& m, const flist& f)
-{
-    m.clear();
-    u_int16_t l = 0;
-    for (flist_citr i=f.begin(); i<f.end(); i++, l++)
-        m.insert(flpair(l, *i));
-}
-
-void
-map_insert(flmap& m, u_int16_t after_lid, u_int16_t num_jfiles)
-{
-    for (u_int16_t l = m.size() - 1; l > after_lid; l--)
+    static void vectors_equal(const lfmgr& lm, const flist& a, const flist& b, const bool fid_check)
     {
-        flmap_itr i = m.find(l);
-        u_int16_t f = i->second;
-        m.erase(i);
-        m.insert(flpair(l + num_jfiles, f));
+        BOOST_CHECK_EQUAL(a.size(), b.size());
+        for (size_t i = 0; i < a.size(); i++)
+        {
+            BOOST_CHECK_EQUAL(a[i], b[i]);
+            fcntl* fp = lm.get_fcntlp(i);
+            BOOST_CHECK_MESSAGE(fp != (void*)0, "Unexpected void pointer returned by lfmgr::get_fcntlp()");
+            if (fp) BOOST_CHECK_EQUAL(fid_check ? fp->fid() : fp->lid(), fid_check ? a[i] : i);
+        }
     }
-    u_int16_t fid = m.size();
-    for (u_int16_t l = after_lid + 1; l <= after_lid + num_jfiles; l++, fid++)
-        m.insert(flpair(l, fid));
-}
 
-void
-map_get_fids(flmap& m, flist& f)
-{
-    f.clear();
-    for (flmap_citr i = m.begin(); i != m.end(); i++)
-        f.push_back(i->second);
-}
-
-void
-map_get_lids(flmap& m, flist& l)
-{
-    l.clear();
-    l.assign(m.size(), 0);
-    for (flmap_citr i = m.begin(); i != m.end(); i++)
-        l[i->second] = i->first;
-}
-
-void
-map_finalize(flmap& m)
-{
-    m.clear();
-}
-
-string
-list_to_string(const flist& f)
-{
-    ostringstream oss;
-    oss << "[";
-    for (flist_citr i = f.begin(); i < f.end(); i++)
+    static void linear_vectors_equal(const lfmgr& lm, const size_t n, const flist& f, const bool fid_check)
     {
-        if (i != f.begin())
-            oss << ", ";
-        oss << *i;
+        BOOST_CHECK_EQUAL(n, f.size());
+        for (size_t i = 0; i < n; i++)
+        {
+            BOOST_CHECK_EQUAL(i, f[i]);
+            fcntl* fp = lm.get_fcntlp(i);
+            BOOST_CHECK_MESSAGE(fp != (void*)0, "Unexpected void pointer returned by lfmgr::get_fcntlp()");
+            if (fp) BOOST_CHECK_EQUAL(fid_check ? fp->fid() : fp->lid(), i);
+        }
     }
-    oss << "]";
-    return oss.str();
-}
+};
 
-// Tests
+// === Tests ===
 
+/*
+* Check that after construction, the fid array _fcntl_arr is empty and the is_init() function returns false.
+*/
 QPID_AUTO_TEST_CASE(default_constructor)
 {
     string test_name = get_test_name(test_filename, "default_constructor");
-    /*
-    * Check that after construction, the fid array _fcntl_arr is empty and the is_init() function returns false.
-    */
     try
     {
         lfmgr lm;
@@ -229,61 +171,72 @@
     cout << "done" << endl;
 }
 
+/*
+* Check that initialize() correctly creates an ordered fid array _fcntl_arr.
+*/
 QPID_AUTO_TEST_CASE(initialize)
 {
     string test_name = get_test_name(test_filename, "initialize");
-    /*
-    * Check that initialize(std::size_t num_jfiles, ...) correctly creates an ordered fid array _fcntl_arr.
-    */
     u_int16_t num_jfiles = 8;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
+
         lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_linear_fids_lids(lm, num_jfiles);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that recover() correctly sets up the specified fid list order.
+*/
 QPID_AUTO_TEST_CASE(recover)
 {
     string test_name = get_test_name(test_filename, "recover");
-    /*
-    * Check that recover - initialize(const std::vector<u_int16_t>& pi_list, ...) - which uses an fid list to specify
-    * the correct order, correctly sets up the specified fid list order.
-    */
-    u_int16_t num_jfiles = 8;
-    u_int16_t fids[] = {0, 4, 1, 5, 6, 2, 3, 7};
-    u_int16_t lids[] = {0, 2, 5, 6, 1, 3, 4, 7};
-    vector<u_int16_t> fid_arr;
-    load_vector(fids, num_jfiles, fid_arr);
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
-        lm.initialize(fid_arr, &jc, &jc.new_fcntl);
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_fids_lids(lm, fids, lids, num_jfiles);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that finalize() after an initialize() empties _fcntl_arr and that afterwards is_init() returns false.
+*/
 QPID_AUTO_TEST_CASE(initialize_finalize)
 {
     string test_name = get_test_name(test_filename, "initialize_finalize");
-    /*
-    * Check that finalize() after an initialize empties _fcntl_arr and that afterwards is_init() returns false.
-    */
     u_int16_t num_jfiles = 8;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
         lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
+
         lm.finalize();
         BOOST_CHECK_EQUAL(lm.is_init(), false);
         BOOST_CHECK_EQUAL(lm.size(), size_t(0));
@@ -298,21 +251,33 @@
     cout << "done" << endl;
 }
 
+/*
+* Check that finalize() after a recover() empties _fcntl_arr and that afterwards is_init() returns false.
+*/
 QPID_AUTO_TEST_CASE(recover_finalize)
 {
     string test_name = get_test_name(test_filename, "recover_finalize");
-    /*
-    * Check that finalize() after a recover empties _fcntl_arr and that afterwards is_init() returns false.
-    */
-    u_int16_t num_jfiles = 8;
-    u_int16_t fids[] = {0, 4, 1, 5, 6, 2, 3, 7};
-    vector<u_int16_t> fid_arr;
-    load_vector(fids, num_jfiles, fid_arr);
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
-        lm.initialize(fid_arr, &jc, &jc.new_fcntl);
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
         lm.finalize();
         BOOST_CHECK_EQUAL(lm.is_init(), false);
         BOOST_CHECK_EQUAL(lm.size(), size_t(0));
@@ -327,128 +292,314 @@
     cout << "done" << endl;
 }
 
+/*
+* Check that initialize() correctly creates an ordered fid array _fcntl_arr after the lfmgr instance has been
+* initialized and finalized.
+*/
 QPID_AUTO_TEST_CASE(initialize_finalize_initialize)
 {
     string test_name = get_test_name(test_filename, "initialize_finalize_initialize");
-    /*
-    * Check that initialize(std::size_t num_jfiles, ...) correctly creates an ordered fid array _fcntl_arr after it has
-    * been cleared using finialize().
-    */
     u_int16_t num_jfiles0 = 8;
     u_int16_t num_jfiles1 = 12;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
+
         lm.initialize(num_jfiles0, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_linear_fids_lids(lm, num_jfiles0);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles0);
+
         lm.finalize();
         BOOST_CHECK_EQUAL(lm.is_init(), false);
+
         lm.initialize(num_jfiles1, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_linear_fids_lids(lm, num_jfiles1);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles1);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that recover() correctly sets up the specified fid list order after the lfmgr instance has been initialized
+* and finalized.
+*/
+QPID_AUTO_TEST_CASE(initialize_finalize_recover)
+{
+    string test_name = get_test_name(test_filename, "initialize_finalize_recover");
+    u_int16_t num_jfiles = 8;
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
+    try
+    {
+        test_jrnl jc(test_name, test_dir, test_name);
+        lfmgr lm;
+
+        lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
+
+        lm.finalize();
+        BOOST_CHECK_EQUAL(lm.is_init(), false);
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.journal_insert(7);
+        lfm.journal_insert(8, 3);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+    }
+    catch(const exception& e) { BOOST_FAIL(e.what()); }
+    cout << "done" << endl;
+}
+
+/*
+* Check that initialize() correctly creates an ordered fid array _fcntl_arr after the lfmgr instance has been recovered
+* and finalized.
+*/
+QPID_AUTO_TEST_CASE(recover_finalize_initialize)
+{
+    string test_name = get_test_name(test_filename, "recover_finalize_initialize");
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
+    u_int16_t num_jfiles = 12;
+    try
+    {
+        test_jrnl jc(test_name, test_dir, test_name);
+        lfmgr lm;
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
+        lm.finalize();
+        BOOST_CHECK_EQUAL(lm.is_init(), false);
+
+        lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
+    }
+    catch(const exception& e) { BOOST_FAIL(e.what()); }
+    cout << "done" << endl;
+}
+
+/*
+* Check that recover() correctly sets up the specified fid list order after the lfmgr instance has been recovered and
+* finalized.
+*/
 QPID_AUTO_TEST_CASE(recover_finalize_recover)
 {
     string test_name = get_test_name(test_filename, "recover_finalize_recover");
-    /*
-    * Check that a second call to initialize(const std::vector<u_int16_t>& pi_list, ...) without calling finilize()
-    * correctly clears the first initialize and creates an fid array of specified order and correct size.
-    */
-    u_int16_t num_jfiles0 = 8;
-    u_int16_t fids0[] = {0, 4, 1, 5, 6, 2, 3, 7};
-    u_int16_t lids0[] = {0, 2, 5, 6, 1, 3, 4, 7};
-    u_int16_t fids1[] = {0, 4, 1, 5, 8, 6, 2, 3, 7, 9, 10, 11};
-    u_int16_t lids1[] = {0, 2, 6, 7, 1, 3, 5, 8, 4, 9, 10, 11};
-    vector<u_int16_t> fid_arr0;
-    load_vector(fids0, num_jfiles0, fid_arr0);
-    u_int16_t num_jfiles1 = 12;
-    vector<u_int16_t> fid_arr1;
-    load_vector(fids1, num_jfiles1, fid_arr1);
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
-        lm.initialize(fid_arr0, &jc, &jc.new_fcntl);
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_fids_lids(lm, fids0, lids0, num_jfiles0);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
         lm.finalize();
         BOOST_CHECK_EQUAL(lm.is_init(), false);
-        lm.initialize(fid_arr1, &jc, &jc.new_fcntl);
+
+        lfm.journal_insert(3);
+        lfm.journal_insert(8, 3);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+
+        lm.recover(rd, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_fids_lids(lm, fids1, lids1, num_jfiles1);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that a second call to initialize() without calling finilize() correctly clears the first initialize and
+* correctly creates an ordered fid array of the correct size _fcntl_arr.
+*/
 QPID_AUTO_TEST_CASE(initialize_initialize)
 {
     string test_name = get_test_name(test_filename, "initialize_initialize");
-    /*
-    * Check that a second call to initialize(std::size_t num_jfiles, ...) without calling finilize() correctly clears
-    * the first initialize and creates an ordered fid array of the correct size _fcntl_arr.
-    */
     u_int16_t num_jfiles0 = 8;
     u_int16_t num_jfiles1 = 12;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
+
         lm.initialize(num_jfiles0, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_linear_fids_lids(lm, num_jfiles0);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles0);
+
         lm.initialize(num_jfiles1, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_linear_fids_lids(lm, num_jfiles1);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles1);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that a call to recover() after initialize() without calling finilize() correctly clears the first initialize and
+* correctly sets up the specified fid list order.
+*/
+QPID_AUTO_TEST_CASE(initialize_recover)
+{
+    string test_name = get_test_name(test_filename, "initialize_recover");
+    u_int16_t num_jfiles = 8;
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
+    try
+    {
+        test_jrnl jc(test_name, test_dir, test_name);
+        lfmgr lm;
+
+        lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.journal_insert(7);
+        lfm.journal_insert(8, 3);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+    }
+    catch(const exception& e) { BOOST_FAIL(e.what()); }
+    cout << "done" << endl;
+}
+
+/*
+* Check that a call to initialize() after recover() without calling finilize() correctly clears the first recover and
+* correctly creates an ordered fid array of the correct size _fcntl_arr.
+*/
+QPID_AUTO_TEST_CASE(recover_initialize)
+{
+    string test_name = get_test_name(test_filename, "recover_initialize");
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
+    u_int16_t num_jfiles = 12;
+    try
+    {
+        test_jrnl jc(test_name, test_dir, test_name);
+        lfmgr lm;
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
+        lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
+        BOOST_CHECK_EQUAL(lm.is_init(), true);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
+    }
+    catch(const exception& e) { BOOST_FAIL(e.what()); }
+    cout << "done" << endl;
+}
+
+/*
+* Check that a second call to recover() without calling finilize() correctly clears the first recover and correctly
+* sets up the specified fid list order.
+*/
 QPID_AUTO_TEST_CASE(recover_recover)
 {
     string test_name = get_test_name(test_filename, "recover_recover");
-    /*
-    * Check that a second call to initialize(const std::vector<u_int16_t>& pi_list, ...) without calling finilize()
-    * correctly clears the first recover and creates an ordered fid array of the correct size _fcntl_arr.
-    */
-    u_int16_t num_jfiles0 = 8;
-    u_int16_t fids0[] = {0, 4, 1, 5, 6, 2, 3, 7};
-    u_int16_t lids0[] = {0, 2, 5, 6, 1, 3, 4, 7};
-    u_int16_t fids1[] = {0, 4, 1, 5, 8, 6, 2, 3, 7, 9, 10, 11};
-    u_int16_t lids1[] = {0, 2, 6, 7, 1, 3, 5, 8, 4, 9, 10, 11};
-    vector<u_int16_t> fid_arr0;
-    load_vector(fids0, num_jfiles0, fid_arr0);
-    u_int16_t num_jfiles1 = 12;
-    vector<u_int16_t> fid_arr1;
-    load_vector(fids1, num_jfiles1, fid_arr1);
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
-        lm.initialize(fid_arr0, &jc, &jc.new_fcntl);
+
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_fids_lids(lm, fids0, lids0, num_jfiles0);
-        lm.initialize(fid_arr1, &jc, &jc.new_fcntl);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
+        lfm.journal_insert(3);
+        lfm.journal_insert(8, 3);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+
+        lm.recover(rd, &jc, &jc.new_fcntl);
         BOOST_CHECK_EQUAL(lm.is_init(), true);
-        check_fids_lids(lm, fids1, lids1, num_jfiles1);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that append correctly adds to the end of the array _fcntl_arr after initialize().
+*/
 QPID_AUTO_TEST_CASE(initialize_append)
 {
     string test_name = get_test_name(test_filename, "initialize_append");
-    /*
-    * Check that append correctly adds to the end of the array _fcntl_arr.
-    */
     u_int16_t num_jfiles = 8;
     u_int16_t num_append_jfiles = 3;
     try
@@ -456,69 +607,77 @@
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
         lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
-        check_linear_fids_lids(lm, num_jfiles);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
 
         // Append single file
         lm.append(&jc, &jc.new_fcntl);
-        check_linear_fids_lids(lm, num_jfiles + 1);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles + 1);
 
         // Append 3 more files
         lm.append(&jc, &jc.new_fcntl, num_append_jfiles);
-        check_linear_fids_lids(lm, num_jfiles + 1 + num_append_jfiles);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles + 1 + num_append_jfiles);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that append correctly adds to the end of the array _fcntl_arr after recover().
+*/
 QPID_AUTO_TEST_CASE(recover_append)
 {
     string test_name = get_test_name(test_filename, "recover_append");
-    /*
-    * Check that after a recover, append correctly adds to the end of the array _fcntl_arr.
-    */
-    u_int16_t num_jfiles = 8;
-    u_int16_t fids0[] = {0, 4, 1, 5, 6, 2, 3, 7};
-    u_int16_t lids0[] = {0, 2, 5, 6, 1, 3, 4, 7};
-    u_int16_t fids1[] = {0, 4, 1, 5, 6, 2, 3, 7, 8};
-    u_int16_t lids1[] = {0, 2, 5, 6, 1, 3, 4, 7, 8};
-    u_int16_t fids2[] = {0, 4, 1, 5, 6, 2, 3, 7, 8, 9, 10, 11};
-    u_int16_t lids2[] = {0, 2, 5, 6, 1, 3, 4, 7, 8, 9, 10, 11};
-    vector<u_int16_t> fid_arr;
-    load_vector(fids0, num_jfiles, fid_arr);
-    u_int16_t num_append_jfiles = 3;
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
     try
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
-        lm.initialize(fid_arr, &jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids0, lids0, num_jfiles);
 
+        lfm.journal_create(4, 4);
+        lfm.journal_insert(0);
+        lfm.journal_insert(2, 2);
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
+        lm.recover(rd, &jc, &jc.new_fcntl);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
         // Append single file
+        lfm.journal_insert(7);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
         lm.append(&jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids1, lids1, num_jfiles + 1);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
 
         // Append 3 more files
-        lm.append(&jc, &jc.new_fcntl, num_append_jfiles);
-        check_fids_lids(lm, fids2, lids2, num_jfiles + 1 + num_append_jfiles);
+        lfm.journal_insert(8, 3);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lm.append(&jc, &jc.new_fcntl, 3);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that insert() works correctly after initialize() and shifts the fid sequence beyond the insert point correctly:
+*
+* The following sequence is tested:
+* initialize 4           fids=[0,1,2,3]           lids=[0,1,2,3]
+* insert 1 after lid 0   fids=[0,4,1,2,3]         lids=[0,2,3,4,1]
+* insert 2 after lid 2   fids=[0,4,1,5,6,2,3]     lids=[0,2,5,6,1,3,4]
+* insert 1 after lid 6   fids=[0,4,1,5,6,2,3,7]   lids=[0,2,5,6,1,3,4,7]
+* issert 1 after lid 3   fids=[0,4,1,5,8,6,2,3,7] lids=[0,2,6,7,1,3,5,8,4]
+*/
 QPID_AUTO_TEST_CASE(initialize_insert)
 {
     string test_name = get_test_name(test_filename, "initialize_insert");
-    /*
-    * Check that insert works correctly and shifts the fid sequence beyond the insert point correctly.
-    * fids: the sequence of fids as lids are incremented
-    * lids: the sequence of lids as fids are incremented
-    * The following sequence is tested:
-    * initialize 4           fids=[0,1,2,3]           lids=[0,1,2,3]
-    * insert 1 after lid 0   fids=[0,4,1,2,3]         lids=[0,2,3,4,1]
-    * insert 2 after lid 2   fids=[0,4,1,5,6,2,3]     lids=[0,2,5,6,1,3,4]
-    * insert 1 after lid 6   fids=[0,4,1,5,6,2,3,7]   lids=[0,2,5,6,1,3,4,7]
-    * issert 1 after lid 3   fids=[0,4,1,5,8,6,2,3,7] lids=[0,2,6,7,1,3,5,8,4]
-    */
     u_int16_t num_jfiles = 4;
     u_int16_t fids1[] = {0, 4, 1, 2, 3};
     u_int16_t lids1[] = {0, 2, 3, 4, 1};
@@ -533,127 +692,143 @@
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
         lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
-        check_linear_fids_lids(lm, num_jfiles);
+        lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
+
         lm.insert(0, &jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids1, lids1, num_jfiles + 1);
+        lfmgr_test_helper::check_fids_lids(lm, fids1, lids1, num_jfiles + 1);
+
         lm.insert(2, &jc, &jc.new_fcntl, 2);
-        check_fids_lids(lm, fids2, lids2, num_jfiles + 3);
+        lfmgr_test_helper::check_fids_lids(lm, fids2, lids2, num_jfiles + 3);
+
         lm.insert(6, &jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids3, lids3, num_jfiles + 4);
+        lfmgr_test_helper::check_fids_lids(lm, fids3, lids3, num_jfiles + 4);
+
         lm.insert(3, &jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids4, lids4, num_jfiles + 5);
+        lfmgr_test_helper::check_fids_lids(lm, fids4, lids4, num_jfiles + 5);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
+/*
+* Check that insert() works correctly after recover() and shifts the fid sequence beyond the insert point correctly:
+*
+* The following sequence is tested:
+* recover 4              fids=[0,2,3,1]           lids=[0,3,1,2]
+* insert 1 after lid 0   fids=[0,4,2,3,1]         lids=[0,4,2,3,1]
+* insert 2 after lid 2   fids=[0,4,2,5,6,3,1]     lids=[0,6,2,5,1,3,4]
+* insert 1 after lid 6   fids=[0,4,2,5,6,3,1,7]   lids=[0,6,2,5,1,3,4,7]
+* issert 1 after lid 3   fids=[0,4,2,5,8,6,3,1,7] lids=[0,7,2,6,1,3,5,8,4]
+*/
 QPID_AUTO_TEST_CASE(recover_insert)
 {
     string test_name = get_test_name(test_filename, "recover_insert");
-    /*
-    * Check that insert works correctly after a recover and shifts the fid sequence beyond the insert point correctly.
-    * fids: the sequence of fids as lids are incremented
-    * lids: the sequence of lids as fids are incremented
-    * The following sequence is tested:
-    * recover 4              fids=[0,2,3,1]           lids=[0,3,1,2]
-    * insert 1 after lid 0   fids=[0,4,2,3,1]         lids=[0,4,2,3,1]
-    * insert 2 after lid 2   fids=[0,4,2,5,6,3,1]     lids=[0,6,2,5,1,3,4]
-    * insert 1 after lid 6   fids=[0,4,2,5,6,3,1,7]   lids=[0,6,2,5,1,3,4,7]
-    * issert 1 after lid 3   fids=[0,4,2,5,8,6,3,1,7] lids=[0,7,2,6,1,3,5,8,4]
-    */
-    u_int16_t num_jfiles = 4;
-    u_int16_t fids0[] = {0, 2, 3, 1};
-    u_int16_t lids0[] = {0, 3, 1, 2};
-    u_int16_t fids1[] = {0, 4, 2, 3, 1};
-    u_int16_t lids1[] = {0, 4, 2, 3, 1};
-    u_int16_t fids2[] = {0, 4, 2, 5, 6, 3, 1};
-    u_int16_t lids2[] = {0, 6, 2, 5, 1, 3, 4};
-    u_int16_t fids3[] = {0, 4, 2, 5, 6, 3, 1, 7};
-    u_int16_t lids3[] = {0, 6, 2, 5, 1, 3, 4, 7};
-    u_int16_t fids4[] = {0, 4, 2, 5, 8, 6, 3, 1, 7};
-    u_int16_t lids4[] = {0, 7, 2, 6, 1, 3, 5, 8, 4};
-    vector<u_int16_t> fid_arr;
-    load_vector(fids0, num_jfiles, fid_arr);
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
     try
     {
+        lfm.journal_create(4, 4);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
+        lfm.write_journal();
+        lfmgr_test_helper::rcvdat_init(rd, fidl);
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
-        lm.initialize(fid_arr, &jc, &jc.new_fcntl); // recover
-        check_fids_lids(lm, fids0, lids0, num_jfiles);
+        lm.recover(rd, &jc, &jc.new_fcntl);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
+        lfm.journal_insert(0);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
         lm.insert(0, &jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids1, lids1, num_jfiles + 1);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
+        lfm.journal_insert(2, 2);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
         lm.insert(2, &jc, &jc.new_fcntl, 2);
-        check_fids_lids(lm, fids2, lids2, num_jfiles + 3);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
+        lfm.journal_insert(6);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
         lm.insert(6, &jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids3, lids3, num_jfiles + 4);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
+
+        lfm.journal_insert(3);
+        lfm.get_fid_list(fidl);
+        lfm.get_lid_list(lidl);
         lm.insert(3, &jc, &jc.new_fcntl);
-        check_fids_lids(lm, fids4, lids4, num_jfiles + 5);
+        lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
     }
     catch(const exception& e) { BOOST_FAIL(e.what()); }
     cout << "done" << endl;
 }
 
-QPID_AUTO_TEST_CASE(random_tests)
+/*
+* Tests randomized combinations of initialization/recovery, initial size, number, size and location of inserts.
+*
+* To reproduce a specific test, comment out the get_seed() statement and uncomment the literal below, adjusting the seed
+* value to that required.
+*/
+QPID_AUTO_TEST_CASE(randomized_tests)
 {
-    string test_name = get_test_name(test_filename, "random_tests");
-    /*
-    * Tests random combinations of initialization/recovery, initial size, number, size and location of inserts.
-    *
-    * To reproduce a specific test, comment out the get_seed() statement and uncomment the literal below, adjusting
-    * the seed value to that required.
-    */
+    string test_name = get_test_name(test_filename, "randomized_tests");
     const long seed = get_seed();
-    // const long seed = 0x2d928521f;
+    // const long seed = 0xd94c29b3;
     cout << "seed=0x" << hex << seed << dec << " " << flush;
     ::srand48(seed);
 
-    flmap m;
-    flist f;
-    flist fids;
-    flist lids;
+    lid_fid_map lfm(test_name, test_name);
+    flist fidl;
+    flist lidl;
+    rcvdat rd;
     
     for (int test_num = 0; test_num < 100; test_num++)
     {
         test_jrnl jc(test_name, test_dir, test_name);
         lfmgr lm;
-
         // 50% chance of recovery except first run and if >= 800 journal files
-        const bool recover_flag = test_num > 0 && m.size() < 800 ? 2.0 * ::drand48() < 1.0 : false;
+        const bool recover_flag = test_num > 0 && lfm.size() < 800 ? 2.0 * ::drand48() < 1.0 : false;
         if (recover_flag)
         {
             // Recover from previous iteration
-            lm.initialize(f, &jc, &jc.new_fcntl);
-            map_recover(m, f);
-            map_get_fids(m, fids);
-            map_get_lids(m, lids);
-            check_fids_lids(lm, fids, lids);
+            lfm.get_fid_list(fidl);
+            lfm.get_lid_list(lidl);
+            lfm.write_journal();
+            lfmgr_test_helper::rcvdat_init(rd, fidl);
+            lm.recover(rd, &jc, &jc.new_fcntl);
+            lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
         }
         else
         {
             // Initialize from scratch
             const u_int16_t num_jfiles = 4 + u_int16_t(21.0 * ::drand48()); // size: 4 - 25 files
+            lfm.destroy_journal();
+            lfm.journal_create(num_jfiles, num_jfiles);
+            lfm.get_fid_list(fidl);
+            lfm.get_lid_list(lidl);
             lm.initialize(num_jfiles, &jc, &jc.new_fcntl);
-            map_init(m, num_jfiles);
-            check_linear_fids_lids(lm, num_jfiles);
+            lfmgr_test_helper::check_linear_fids_lids(lm, num_jfiles);
         }
 
         // Loop to insert fids
-        const int num_inserts = 1 + int(m.size()/10.0 * ::drand48());
+        const int num_inserts = 1 + int(lfm.size()/10.0 * ::drand48());
         for (int i = 0; i < num_inserts; i++)
         {
             const u_int16_t size = lm.size();
             const u_int16_t after_lid = u_int16_t(1.0 * size * ::drand48());
             const u_int16_t num_files = 1 + u_int16_t(4.0 * ::drand48());
+            lfm.journal_insert(after_lid, num_files);
+            lfm.get_fid_list(fidl);
+            lfm.get_lid_list(lidl);
+
             lm.insert(after_lid, &jc, &jc.new_fcntl, num_files);
-            map_insert(m, after_lid, num_files);
-            map_get_fids(m, fids);
-            map_get_lids(m, lids);
-            check_fids_lids(lm, fids, lids);
-
-            lm.get_fid_list(f);
+            lfmgr_test_helper::check_fids_lids(lm, fidl, lidl);
         }
         lm.finalize();
-        map_finalize(m);
         BOOST_CHECK_EQUAL(lm.is_init(), false);
         BOOST_CHECK_EQUAL(lm.size(), size_t(0));
         BOOST_CHECK_EQUAL(lm.get_fcntlp(0), (void*)0);




More information about the rhmessaging-commits mailing list