00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00083
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
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
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
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