ExternalSortExecStreamTest.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/test/ExternalSortExecStreamTest.cpp#1 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2009-2009 SQLstream, Inc.
00006 // Copyright (C) 2004-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 2004-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/test/ExecStreamUnitTestBase.h"
00026 #include "fennel/sorter/ExternalSortExecStream.h"
00027 #include "fennel/tuple/StandardTypeDescriptor.h"
00028 #include "fennel/exec/MockProducerExecStream.h"
00029 #include "fennel/exec/ExecStreamEmbryo.h"
00030 #include "fennel/exec/ExecStreamScheduler.h"
00031 #include "fennel/exec/ExecStreamGraph.h"
00032 #include "fennel/cache/Cache.h"
00033 
00034 #include <boost/test/test_tools.hpp>
00035 
00036 using namespace fennel;
00037 
00038 class ExternalSortExecStreamTest : public ExecStreamUnitTestBase
00039 {
00040     void testImpl(
00041         uint nRows,
00042         SharedMockProducerExecStreamGenerator pGenerator,
00043         MockProducerExecStreamGenerator &verifier,
00044         bool storeFinalRun = false,
00045         bool stopEarly = false,
00046         bool desc = false);
00047 
00048 public:
00049     explicit ExternalSortExecStreamTest()
00050     {
00051         FENNEL_UNIT_TEST_CASE(
00052             ExternalSortExecStreamTest,testPresortedInMem);
00053         FENNEL_UNIT_TEST_CASE(
00054             ExternalSortExecStreamTest,testPresortedExternal);
00055         FENNEL_UNIT_TEST_CASE(
00056             ExternalSortExecStreamTest,testRandomInMem);
00057         FENNEL_UNIT_TEST_CASE(
00058             ExternalSortExecStreamTest,testRandomDescInMem);
00059         FENNEL_UNIT_TEST_CASE(
00060             ExternalSortExecStreamTest,testRandomExternal);
00061         FENNEL_UNIT_TEST_CASE(
00062             ExternalSortExecStreamTest,testRandomExternalStoreFinal);
00063         FENNEL_UNIT_TEST_CASE(
00064             ExternalSortExecStreamTest,testRandomExternalFault);
00065     }
00066 
00067     void testPresortedInMem();
00068     void testPresortedExternal();
00069     void testRandomInMem();
00070     void testRandomDescInMem();
00071     void testRandomExternal();
00072     void testRandomExternalStoreFinal();
00073     void testRandomExternalFault();
00074 
00075     virtual void testCaseSetUp();
00076 };
00077 
00078 void ExternalSortExecStreamTest::testCaseSetUp()
00079 {
00080     ExecStreamUnitTestBase::testCaseSetUp();
00081 
00082     // lower the cache availability to force external sorts for
00083     // the larger datasets
00084     ExecStreamResourceQuantity quantity;
00085     quantity.nCachePages = 10;
00086     pResourceGovernor->setResourceAvailability(
00087         quantity, EXEC_RESOURCE_CACHE_PAGES);
00088 
00089     ExecStreamResourceKnobs knob;
00090     knob.expectedConcurrentStatements = 1;
00091     pResourceGovernor->setResourceKnob(
00092         knob, EXEC_KNOB_EXPECTED_CONCURRENT_STATEMENTS);
00093 }
00094 
00095 void ExternalSortExecStreamTest::testRandomInMem()
00096 {
00097     SharedMockProducerExecStreamGenerator pGenerator(
00098         new PermutationGenerator(100));
00099     RampExecStreamGenerator verifier;
00100     testImpl(100, pGenerator, verifier);
00101 }
00102 
00103 void ExternalSortExecStreamTest::testRandomDescInMem()
00104 {
00105     SharedMockProducerExecStreamGenerator pGenerator(
00106         new PermutationGenerator(100));
00107     std::vector< boost::shared_ptr<ColumnGenerator<int64_t> > > colGens;
00108     colGens.push_back(
00109         boost::shared_ptr< ColumnGenerator<int64_t> >(
00110             new SeqColumnGenerator(99, -1)));
00111     CompositeExecStreamGenerator verifier(colGens);
00112     testImpl(100, pGenerator, verifier, false, false, true);
00113 }
00114 
00115 void ExternalSortExecStreamTest::testRandomExternal()
00116 {
00117     SharedMockProducerExecStreamGenerator pGenerator(
00118         new PermutationGenerator(10000));
00119     RampExecStreamGenerator verifier;
00120     testImpl(10000, pGenerator, verifier);
00121 }
00122 
00123 void ExternalSortExecStreamTest::testRandomExternalStoreFinal()
00124 {
00125     SharedMockProducerExecStreamGenerator pGenerator(
00126         new PermutationGenerator(10000));
00127     RampExecStreamGenerator verifier;
00128     testImpl(10000, pGenerator, verifier, true);
00129 }
00130 
00131 void ExternalSortExecStreamTest::testRandomExternalFault()
00132 {
00133     SharedMockProducerExecStreamGenerator pGenerator(
00134         new PermutationGenerator(10000));
00135     RampExecStreamGenerator verifier;
00136     // only read half the result set, and then abort
00137     testImpl(10000, pGenerator, verifier, true, true);
00138 }
00139 
00140 void ExternalSortExecStreamTest::testPresortedInMem()
00141 {
00142     SharedMockProducerExecStreamGenerator pGenerator(
00143         new RampExecStreamGenerator());
00144     testImpl(100, pGenerator, *pGenerator);
00145 }
00146 
00147 void ExternalSortExecStreamTest::testPresortedExternal()
00148 {
00149     SharedMockProducerExecStreamGenerator pGenerator(
00150         new RampExecStreamGenerator());
00151     testImpl(10000, pGenerator, *pGenerator);
00152 }
00153 
00154 void ExternalSortExecStreamTest::testImpl(
00155     uint nRows,
00156     SharedMockProducerExecStreamGenerator pGenerator,
00157     MockProducerExecStreamGenerator &verifier,
00158     bool storeFinalRun,
00159     bool stopEarly,
00160     bool desc)
00161 {
00162     StandardTypeDescriptorFactory stdTypeFactory;
00163     TupleAttributeDescriptor attrDesc(
00164         stdTypeFactory.newDataType(STANDARD_TYPE_INT_64));
00165 
00166     MockProducerExecStreamParams mockParams;
00167     mockParams.outputTupleDesc.push_back(attrDesc);
00168     mockParams.nRows = nRows;
00169     mockParams.pGenerator = pGenerator;
00170 
00171     ExecStreamEmbryo mockStreamEmbryo;
00172     mockStreamEmbryo.init(new MockProducerExecStream(),mockParams);
00173     mockStreamEmbryo.getStream()->setName("MockProducerExecStream");
00174 
00175     ExternalSortExecStreamParams sortParams;
00176     sortParams.outputTupleDesc.push_back(attrDesc);
00177     sortParams.distinctness = DUP_ALLOW;
00178     sortParams.estimatedNumRows = nRows;
00179     sortParams.earlyClose = false;
00180     sortParams.pTempSegment = pRandomSegment;
00181     sortParams.pCacheAccessor = pCache;
00182     // 10 total cache pages, 5% in reserve ==> 9 scratch pages per stream graph
00183     sortParams.scratchAccessor =
00184         pSegmentFactory->newScratchSegment(pCache, 9);
00185     sortParams.keyProj.push_back(0);
00186     sortParams.storeFinalRun = storeFinalRun;
00187     sortParams.descendingKeyColumns.push_back(desc);
00188 
00189     ExecStreamEmbryo sortStreamEmbryo;
00190     sortStreamEmbryo.init(
00191         ExternalSortExecStream::newExternalSortExecStream(),sortParams);
00192     sortStreamEmbryo.getStream()->setName("ExternalSortExecStream");
00193 
00194     SharedExecStream pOutputStream = prepareTransformGraph(
00195         mockStreamEmbryo, sortStreamEmbryo);
00196 
00197     verifyOutput(
00198         *pOutputStream,
00199         stopEarly ? (mockParams.nRows / 2) : mockParams.nRows,
00200         verifier,
00201         stopEarly);
00202 
00203     if (stopEarly) {
00204         // simulate error cleanup
00205         pScheduler->stop();
00206         pGraph->close();
00207     }
00208 
00209     BOOST_CHECK_EQUAL(0, pRandomSegment->getAllocatedSizeInPages());
00210 }
00211 
00212 FENNEL_UNIT_TEST_SUITE(ExternalSortExecStreamTest);
00213 
00214 // End ExternalSortExecStreamTest.cpp

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