SegPageIterTest.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/test/SegPageIterTest.cpp#9 $
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/SegPageIter.h"
00026 #include "fennel/test/SegStorageTestBase.h"
00027 #include "fennel/segment/Segment.h"
00028 #include "fennel/segment/SegPageLock.h"
00029 
00030 #include <boost/test/test_tools.hpp>
00031 
00032 using namespace fennel;
00033 
00034 class SegPageIterTest : virtual public SegStorageTestBase
00035 {
00036 public:
00037     explicit SegPageIterTest()
00038     {
00039         FENNEL_UNIT_TEST_CASE(SegPageIterTest,testUnboundedIter);
00040         FENNEL_UNIT_TEST_CASE(SegPageIterTest,testBoundedIter);
00041         FENNEL_UNIT_TEST_CASE(SegPageIterTest,testWithLock);
00042         FENNEL_UNIT_TEST_CASE(SegPageIterTest,testHighPrefetchRejects);
00043         FENNEL_UNIT_TEST_CASE(SegPageIterTest,testLowPrefetchRejects);
00044     }
00045 
00046     void testUnboundedIter()
00047     {
00048         testIter(FIRST_LINEAR_PAGE_ID,NULL_PAGE_ID,false,0);
00049     }
00050 
00051     void testBoundedIter()
00052     {
00053         testIter(
00054             Segment::getLinearPageId(3),
00055             Segment::getLinearPageId(51),
00056             false,
00057             0);
00058     }
00059 
00060     void testWithLock()
00061     {
00062         testIter(FIRST_LINEAR_PAGE_ID,NULL_PAGE_ID,true,0);
00063     }
00064 
00065     void testHighPrefetchRejects()
00066     {
00067         // High pre-fetch reject rate.  This will force frequent downward
00068         // throttles.
00069         testIter(FIRST_LINEAR_PAGE_ID,NULL_PAGE_ID,false,3);
00070     }
00071 
00072     void testLowPrefetchRejects()
00073     {
00074         // Low pre-fetch reject rate.  This will allow the rate to throttle
00075         // back up once it's throttled down.
00076         testIter(FIRST_LINEAR_PAGE_ID,NULL_PAGE_ID,false,123);
00077     }
00078 
00079     void testIter(PageId beginPageId,PageId endPageId,bool bLock,int rejectRate)
00080     {
00081         openStorage(DeviceMode::createNew);
00082 
00083         // reopen will interpret pages as already allocated
00084         closeStorage();
00085         openStorage(DeviceMode::load);
00086 
00087         SegmentAccessor segmentAccessor(pLinearSegment,pCache);
00088         SegPageLock pageLock(segmentAccessor);
00089         SegPageIter iter;
00090         iter.mapRange(segmentAccessor,beginPageId,endPageId);
00091         PageId pageId = beginPageId;
00092         for (uint i = 0; ; i++) {
00093             BOOST_CHECK_EQUAL(pageId,*iter);
00094             if (pageId == endPageId) {
00095                 break;
00096             }
00097             if (rejectRate > 0 && !(i % rejectRate)) {
00098                 iter.forcePrefetchReject();
00099             }
00100             if (bLock) {
00101                 pageLock.lockShared(pageId);
00102             }
00103             BOOST_CHECK(pageId != NULL_PAGE_ID);
00104             ++iter;
00105             pageId = pLinearSegment->getPageSuccessor(pageId);
00106         }
00107         iter.makeSingular();
00108         pageLock.unlock();
00109     }
00110 };
00111 
00112 FENNEL_UNIT_TEST_SUITE(SegPageIterTest);
00113 
00114 // End SegPageIterTest.cpp

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