SegPageEntryIterTest.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/test/SegPageEntryIterTest.cpp#4 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/segment/SegPageEntryIterImpl.h"
00026 #include "fennel/segment/MockSegPageEntryIterSource.h"
00027 #include "fennel/test/SegStorageTestBase.h"
00028 #include "fennel/segment/Segment.h"
00029 #include "fennel/segment/SegPageLock.h"
00030 
00031 #include <boost/test/test_tools.hpp>
00032 
00033 using namespace fennel;
00034 
00035 class SegPageEntryIterTest : virtual public SegStorageTestBase
00036 {
00037 public:
00038     explicit SegPageEntryIterTest()
00039     {
00040         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testUnboundedIter);
00041         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testBoundedIter);
00042         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testWithLock);
00043         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testNoPrefetch);
00044         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testReject);
00045         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testRejectNoPrefetch);
00046         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testQueueSize1);
00047         FENNEL_UNIT_TEST_CASE(SegPageEntryIterTest, testRejectQueueSize1);
00048     }
00049 
00050     void testUnboundedIter()
00051     {
00052         testIter(FIRST_LINEAR_PAGE_ID, NULL_PAGE_ID, false, -1, 0);
00053     }
00054 
00055     void testBoundedIter()
00056     {
00057         testIter(
00058             Segment::getLinearPageId(3),
00059             Segment::getLinearPageId(51),
00060             false,
00061             -1,
00062             0);
00063     }
00064 
00065     void testWithLock()
00066     {
00067         testIter(FIRST_LINEAR_PAGE_ID, NULL_PAGE_ID, true, -1, 0);
00068     }
00069 
00070     void testNoPrefetch()
00071     {
00072         testIter(FIRST_LINEAR_PAGE_ID, NULL_PAGE_ID, false, 0, 0);
00073     }
00074 
00075     void testReject()
00076     {
00077         testIter(FIRST_LINEAR_PAGE_ID, NULL_PAGE_ID, false, -1, 251);
00078     }
00079 
00080     void testRejectNoPrefetch()
00081     {
00082         testIter(FIRST_LINEAR_PAGE_ID, NULL_PAGE_ID, false, 0, 19);
00083     }
00084 
00085     void testQueueSize1()
00086     {
00087         testIter(FIRST_LINEAR_PAGE_ID, NULL_PAGE_ID, false, 1, 0);
00088     }
00089 
00090     void testRejectQueueSize1()
00091     {
00092         testIter(FIRST_LINEAR_PAGE_ID, NULL_PAGE_ID, false, 1, 7);
00093     }
00094 
00095     void testIter(
00096         PageId beginPageId, PageId endPageId, bool bLock, int queueSize,
00097         uint rejectRate)
00098     {
00099         char buf[10];
00100         if (queueSize >= 0) {
00101             sprintf(buf, "%d", queueSize);
00102             configMap.setStringParam(CacheParams::paramPrefetchPagesMax, buf);
00103             cacheParams.readConfig(configMap);
00104         }
00105         openStorage(DeviceMode::createNew);
00106 
00107         // reopen will interpret pages as already allocated
00108         closeStorage();
00109         openStorage(DeviceMode::load);
00110 
00111         SegmentAccessor segmentAccessor(pLinearSegment, pCache);
00112         SegPageLock pageLock(segmentAccessor);
00113         MockSegPageEntryIterSource prefetchSource(
00114             segmentAccessor, beginPageId);
00115         SegPageEntryIter<int> iter(20);
00116         iter.setPrefetchSource(prefetchSource);
00117         iter.mapRange(segmentAccessor, NULL_PAGE_ID, endPageId);
00118         PageId pageId = beginPageId;
00119         for (int i = 0; ; i++) {
00120             std::pair<PageId, int> &entry = *iter;
00121             BOOST_CHECK_EQUAL(pageId, entry.first);
00122             BOOST_CHECK_EQUAL(i, entry.second);
00123             if (pageId == endPageId) {
00124                 break;
00125             }
00126             if (bLock) {
00127                 pageLock.lockShared(pageId);
00128             }
00129             BOOST_CHECK(pageId != NULL_PAGE_ID);
00130             if (rejectRate > 0 && !(i % rejectRate)) {
00131                 iter.forcePrefetchReject();
00132             }
00133             ++iter;
00134             // MockSegPageEntryIterSource returns every other page twice
00135             if (i % 2) {
00136                 pageId = pLinearSegment->getPageSuccessor(pageId);
00137                 if (pageId != endPageId) {
00138                     pageId = pLinearSegment->getPageSuccessor(pageId);
00139                 }
00140             }
00141         }
00142         iter.makeSingular();
00143         pageLock.unlock();
00144 
00145         // reset back to default value
00146         if (queueSize >= 0) {
00147             sprintf(buf, "%d", CacheParams::defaultPrefetchPagesMax);
00148             configMap.setStringParam(CacheParams::paramPrefetchPagesMax, buf);
00149             cacheParams.readConfig(configMap);
00150         }
00151     }
00152 };
00153 
00154 FENNEL_UNIT_TEST_SUITE(SegPageEntryIterTest);
00155 
00156 // End SegPageEntryIterTest.cpp

Generated on Mon Jun 22 04:00:21 2009 for Fennel by  doxygen 1.5.1