LcsClusterReplaceExecStreamTest.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/test/LcsClusterReplaceExecStreamTest.cpp#4 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 LucidEra, Inc.
00005 // Copyright (C) 2005-2009 The Eigenbase Project
00006 //
00007 // This program is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU General Public License as published by the Free
00009 // Software Foundation; either version 2 of the License, or (at your option)
00010 // any later version approved by The Eigenbase Project.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 #include "fennel/common/CommonPreamble.h"
00023 #include "fennel/test/ExecStreamUnitTestBase.h"
00024 #include "fennel/test/SnapshotSegmentTestBase.h"
00025 #include "fennel/lucidera/colstore/LcsClusterReplaceExecStream.h"
00026 #include "fennel/lucidera/colstore/LcsRowScanExecStream.h"
00027 #include "fennel/btree/BTreeBuilder.h"
00028 #include "fennel/tuple/StandardTypeDescriptor.h"
00029 #include "fennel/segment/SnapshotRandomAllocationSegment.h"
00030 #include "fennel/segment/SegmentFactory.h"
00031 #include "fennel/exec/MockProducerExecStream.h"
00032 #include "fennel/exec/ValuesExecStream.h"
00033 #include "fennel/exec/ExecStreamEmbryo.h"
00034 #include "fennel/exec/DynamicParam.h"
00035 #include "fennel/cache/Cache.h"
00036 #include <stdarg.h>
00037 
00038 #include <boost/test/test_tools.hpp>
00039 
00040 using namespace fennel;
00041 
00047 class LcsClusterReplaceExecStreamTest :
00048     public ExecStreamUnitTestBase, public SnapshotSegmentTestBase
00049 {
00050     StandardTypeDescriptorFactory stdTypeFactory;
00051     TupleAttributeDescriptor attrDesc_int64;
00052     TupleAttributeDescriptor attrDesc_bitmap;
00053 
00054     PageId savedRootPageId;
00055     BTreeDescriptor btreeDescriptor;
00056 
00066     void loadCluster(
00067         uint nCols,
00068         uint nRows,
00069         SharedMockProducerExecStreamGenerator pInputGenerator);
00070 
00080     void verifyCluster(
00081         uint nCols,
00082         uint nRows,
00083         MockProducerExecStreamGenerator &resultGenerator);
00084 
00095     void replaceCluster(
00096         uint nCols,
00097         uint nRows,
00098         SharedMockProducerExecStreamGenerator pInputGenerator);
00099 
00116     void testClusterReplace(
00117         uint nCols,
00118         uint totalNumRows,
00119         uint numReplRows,
00120         SharedMockProducerExecStreamGenerator pOrigClusterInputGenerator,
00121         MockProducerExecStreamGenerator &origClusterResultGenerator,
00122         SharedMockProducerExecStreamGenerator pReplClusterInputGenerator,
00123         MockProducerExecStreamGenerator &replClusterResultGenerator);
00124 
00125     void testSingleColRepeatingSequence(
00126         uint nRows,
00127         uint inputSeqStart,
00128         uint replSeqStart,
00129         uint expectedSeqStart);
00130 
00131     void testMultiColClusterReplace(uint nCols, uint nRows);
00132 
00133     void initClusterAppendParams(
00134         LcsClusterAppendExecStreamParams &lcsAppendParams,
00135         uint nCols,
00136         bool replace);
00137 
00138 public:
00139     explicit LcsClusterReplaceExecStreamTest()
00140     {
00141         FENNEL_UNIT_TEST_CASE(
00142             LcsClusterReplaceExecStreamTest, testSingleColOddNumRows);
00143         FENNEL_UNIT_TEST_CASE(
00144             LcsClusterReplaceExecStreamTest, testSingleColEvenNumRows);
00145         FENNEL_UNIT_TEST_CASE(
00146             LcsClusterReplaceExecStreamTest, testSingleColSeqStartAt1);
00147         FENNEL_UNIT_TEST_CASE(
00148             LcsClusterReplaceExecStreamTest, testReplaceAllRows);
00149         FENNEL_UNIT_TEST_CASE(
00150             LcsClusterReplaceExecStreamTest, testReplaceNoRows);
00151         FENNEL_UNIT_TEST_CASE(
00152             LcsClusterReplaceExecStreamTest, test3ColClusterReplace);
00153     }
00154 
00155     void testSingleColOddNumRows();
00156     void testSingleColEvenNumRows();
00157     void testSingleColSeqStartAt1();
00158     void testReplaceAllRows();
00159     void testReplaceNoRows();
00160     void test3ColClusterReplace();
00161 
00162     virtual void testCaseSetUp();
00163     virtual void testCaseTearDown();
00164 
00165     virtual void openRandomSegment();
00166 };
00167 
00168 void LcsClusterReplaceExecStreamTest::testSingleColOddNumRows()
00169 {
00170     // Original cluster contains 5001 rows with values 0, 0, 2, 2, 4, 4, ...
00171     // Replace every other rid starting at rid 1 with the values 1, 3, 5, ...
00172     // Resulting cluster contains the values 0, 1, 2, 3, ...
00173     testSingleColRepeatingSequence(5001, 0, 1, 0);
00174 }
00175 
00176 void LcsClusterReplaceExecStreamTest::testSingleColEvenNumRows()
00177 {
00178     // Original cluster contains 4000 rows with values 0, 0, 2, 2, 4, 4, ...
00179     // Replace every other rid starting at rid 1 with the values 1, 3, 5, ...
00180     // Resulting cluster contains the values 0, 1, 2, 3, ...
00181     testSingleColRepeatingSequence(4000, 0, 1, 0);
00182 }
00183 
00184 void LcsClusterReplaceExecStreamTest::testSingleColSeqStartAt1()
00185 {
00186     // Original cluster contains 3000 rows with values 1, 1, 3, 3, 5, 5, ...
00187     // Replace every other rid starting at rid 0 with the values 0, 2, 4, ...
00188     // Resulting cluster contains the values 0, 1, 2, 3, ...
00189     testSingleColRepeatingSequence(3000, 1, 0, 0);
00190 }
00191 
00192 void LcsClusterReplaceExecStreamTest::testSingleColRepeatingSequence(
00193     uint nRows,
00194     uint inputSeqStart,
00195     uint replSeqStart,
00196     uint expectedSeqStart)
00197 {
00198     // Original cluster contains the values inputSeqStart, inputSeqStart+2, ...
00199     // Replace every other rid starting at rid replSeqStart with values
00200     // replaceSeqStart, replaceSeqStart+2, ...,
00201     // The replace cluster should have the sequence expectedSeqStart,
00202     // expectedSeqStart+1, ...
00203 
00204     SharedMockProducerExecStreamGenerator pOrigClusterInputGenerator =
00205         SharedMockProducerExecStreamGenerator(
00206             new StairCaseExecStreamGenerator(2, 2, inputSeqStart));
00207 
00208     StairCaseExecStreamGenerator origClusterResultGenerator =
00209         StairCaseExecStreamGenerator(2, 2, inputSeqStart);
00210 
00211     vector<boost::shared_ptr<ColumnGenerator<int64_t> > > columnGenerators;
00212     SharedInt64ColumnGenerator colGenerator =
00213         SharedInt64ColumnGenerator(new SeqColumnGenerator(replSeqStart, 2));
00214     columnGenerators.push_back(colGenerator);
00215     colGenerator =
00216         SharedInt64ColumnGenerator(new SeqColumnGenerator(replSeqStart, 2));
00217     columnGenerators.push_back(colGenerator);
00218     SharedMockProducerExecStreamGenerator pReplClusterInputGenerator =
00219         SharedMockProducerExecStreamGenerator(
00220             new CompositeExecStreamGenerator(columnGenerators));
00221 
00222     RampExecStreamGenerator replClusterResultGenerator(expectedSeqStart);
00223 
00224     testClusterReplace(
00225         1,
00226         nRows,
00227         nRows / 2,
00228         pOrigClusterInputGenerator,
00229         origClusterResultGenerator,
00230         pReplClusterInputGenerator,
00231         replClusterResultGenerator);
00232 }
00233 
00234 void LcsClusterReplaceExecStreamTest::testReplaceAllRows()
00235 {
00236     // Original cluster 2003 rows, all with the value 99.
00237     // Replace every row with the sequence 0, 1, 2, ...
00238 
00239     uint nRows = 2003;
00240 
00241     SharedMockProducerExecStreamGenerator pOrigClusterInputGenerator =
00242         SharedMockProducerExecStreamGenerator(
00243             new ConstExecStreamGenerator(99));
00244 
00245     ConstExecStreamGenerator origClusterResultGenerator =
00246         ConstExecStreamGenerator(99);
00247 
00248     vector<boost::shared_ptr<ColumnGenerator<int64_t> > > columnGenerators;
00249     SharedInt64ColumnGenerator colGenerator =
00250         SharedInt64ColumnGenerator(new SeqColumnGenerator(0, 1));
00251     columnGenerators.push_back(colGenerator);
00252     colGenerator =
00253         SharedInt64ColumnGenerator(new SeqColumnGenerator(0, 1));
00254     columnGenerators.push_back(colGenerator);
00255     SharedMockProducerExecStreamGenerator pReplClusterInputGenerator =
00256         SharedMockProducerExecStreamGenerator(
00257             new CompositeExecStreamGenerator(columnGenerators));
00258 
00259     RampExecStreamGenerator replClusterResultGenerator;
00260 
00261     testClusterReplace(
00262         1,
00263         nRows,
00264         nRows,
00265         pOrigClusterInputGenerator,
00266         origClusterResultGenerator,
00267         pReplClusterInputGenerator,
00268         replClusterResultGenerator);
00269 }
00270 
00271 void LcsClusterReplaceExecStreamTest::testReplaceNoRows()
00272 {
00273     // Original cluster contains 1007 rows with the sequence 0, 1, 2, ...
00274     // Replace no rows.
00275 
00276     uint nRows = 1007;
00277 
00278     SharedMockProducerExecStreamGenerator pOrigClusterInputGenerator =
00279         SharedMockProducerExecStreamGenerator(
00280             new RampExecStreamGenerator());
00281 
00282     RampExecStreamGenerator origClusterResultGenerator =
00283         RampExecStreamGenerator();
00284 
00285     // It doesn't matter what we use for these ColumnGenerators, since no
00286     // rows will be generated.
00287     vector<boost::shared_ptr<ColumnGenerator<int64_t> > > columnGenerators;
00288     SharedInt64ColumnGenerator colGenerator =
00289         SharedInt64ColumnGenerator(new SeqColumnGenerator(0, 1));
00290     columnGenerators.push_back(colGenerator);
00291     colGenerator =
00292         SharedInt64ColumnGenerator(new SeqColumnGenerator(0, 1));
00293     columnGenerators.push_back(colGenerator);
00294     SharedMockProducerExecStreamGenerator pReplClusterInputGenerator =
00295         SharedMockProducerExecStreamGenerator(
00296             new CompositeExecStreamGenerator(columnGenerators));
00297 
00298     RampExecStreamGenerator replClusterResultGenerator;
00299 
00300     testClusterReplace(
00301         1,
00302         nRows,
00303         0,
00304         pOrigClusterInputGenerator,
00305         origClusterResultGenerator,
00306         pReplClusterInputGenerator,
00307         replClusterResultGenerator);
00308 }
00309 
00310 void LcsClusterReplaceExecStreamTest::test3ColClusterReplace()
00311 {
00312     testMultiColClusterReplace(3, 800);
00313 }
00314 
00315 void LcsClusterReplaceExecStreamTest::testMultiColClusterReplace(
00316     uint nCols,
00317     uint nRows)
00318 {
00319     vector<boost::shared_ptr<ColumnGenerator<int64_t> > > columnGenerators;
00320     SharedInt64ColumnGenerator colGenerator;
00321 
00322     // For the original cluster, each column is a repeating sequence of
00323     // values n,n,n+2,n+2,n+4,n+4, ..., where n corresponds to the column
00324     // number, starting at 0
00325     for (uint i = 0; i < nCols; i++) {
00326         colGenerator =
00327             SharedInt64ColumnGenerator(new StairCaseColumnGenerator(2, 2, i));
00328         columnGenerators.push_back(colGenerator);
00329     }
00330     SharedMockProducerExecStreamGenerator pOrigClusterInputGenerator =
00331         SharedMockProducerExecStreamGenerator(
00332             new CompositeExecStreamGenerator(columnGenerators));
00333 
00334     columnGenerators.clear();
00335     for (uint i = 0; i < nCols; i++) {
00336         colGenerator =
00337             SharedInt64ColumnGenerator(new StairCaseColumnGenerator(2, 2, i));
00338         columnGenerators.push_back(colGenerator);
00339     }
00340     CompositeExecStreamGenerator origClusterResultGenerator =
00341         CompositeExecStreamGenerator(columnGenerators);
00342 
00343     // Replace every other row, starting at rid 1, with the values n+1, n+3, ...
00344     // where n is the column number.  The first column generator below is
00345     // for the rid sequence.
00346     columnGenerators.clear();
00347     colGenerator =
00348         SharedInt64ColumnGenerator(new SeqColumnGenerator(1, 2));
00349     columnGenerators.push_back(colGenerator);
00350     for (uint i = 1; i < nCols + 1; i++) {
00351         colGenerator = SharedInt64ColumnGenerator(new SeqColumnGenerator(i, 2));
00352         columnGenerators.push_back(colGenerator);
00353     }
00354     SharedMockProducerExecStreamGenerator pReplClusterInputGenerator =
00355         SharedMockProducerExecStreamGenerator(
00356             new CompositeExecStreamGenerator(columnGenerators));
00357 
00358     // Expected resulting cluster should have values n,n+1, ... where n is
00359     // the column number
00360     columnGenerators.clear();
00361     for (uint i = 0; i < nCols; i++) {
00362         colGenerator = SharedInt64ColumnGenerator(new SeqColumnGenerator(i));
00363         columnGenerators.push_back(colGenerator);
00364     }
00365     CompositeExecStreamGenerator replClusterResultGenerator =
00366         CompositeExecStreamGenerator(columnGenerators);
00367 
00368     testClusterReplace(
00369         nCols,
00370         nRows,
00371         nRows / 2,
00372         pOrigClusterInputGenerator,
00373         origClusterResultGenerator,
00374         pReplClusterInputGenerator,
00375         replClusterResultGenerator);
00376 }
00377 
00378 void LcsClusterReplaceExecStreamTest::testClusterReplace(
00379     uint nCols,
00380     uint totalNumRows,
00381     uint numReplRows,
00382     SharedMockProducerExecStreamGenerator pOrigClusterInputGenerator,
00383     MockProducerExecStreamGenerator &origClusterResultGenerator,
00384     SharedMockProducerExecStreamGenerator pReplClusterInputGenerator,
00385     MockProducerExecStreamGenerator &replClusterResultGenerator)
00386 {
00387     // Load the cluster and verify the load by scanning the resulting cluster
00388     loadCluster(nCols, totalNumRows, pOrigClusterInputGenerator);
00389     resetExecStreamTest();
00390     verifyCluster(nCols, totalNumRows, origClusterResultGenerator);
00391     resetExecStreamTest();
00392 
00393     // Commit the changes associated with the current txn and create a new
00394     // snapshot segment for the next txn
00395     SnapshotRandomAllocationSegment *pSnapshotSegment =
00396         SegmentFactory::dynamicCast<SnapshotRandomAllocationSegment *>(
00397             pSnapshotRandomSegment);
00398     pSnapshotSegment->commitChanges(currCsn);
00399     pSnapshotSegment->checkpoint(CHECKPOINT_FLUSH_ALL);
00400     currCsn = TxnId(1);
00401     pSnapshotRandomSegment2 =
00402         pSegmentFactory->newSnapshotRandomAllocationSegment(
00403             pVersionedRandomSegment,
00404             pVersionedRandomSegment,
00405             currCsn);
00406     setForceCacheUnmap(pSnapshotRandomSegment2);
00407     pRandomSegment = pSnapshotRandomSegment2;
00408 
00409     // Replace some sequence of rows from the cluster
00410     replaceCluster(nCols, numReplRows, pReplClusterInputGenerator);
00411 
00412     // Commit the changes and then verify that the resulting cluster contains
00413     // a combination of the original and replaced values.  It should be
00414     // 0, 1, 2, 3, ...
00415     pSnapshotSegment =
00416         SegmentFactory::dynamicCast<SnapshotRandomAllocationSegment *>(
00417             pSnapshotRandomSegment2);
00418     pSnapshotSegment->commitChanges(currCsn);
00419     pSnapshotSegment->checkpoint(CHECKPOINT_FLUSH_ALL);
00420     resetExecStreamTest();
00421     verifyCluster(nCols, totalNumRows, replClusterResultGenerator);
00422 }
00423 
00424 void LcsClusterReplaceExecStreamTest::loadCluster(
00425     uint nCols,
00426     uint nRows,
00427     SharedMockProducerExecStreamGenerator pInputGenerator)
00428 {
00429     MockProducerExecStreamParams mockParams;
00430     for (uint i = 0; i < nCols; i++) {
00431         mockParams.outputTupleDesc.push_back(attrDesc_int64);
00432     }
00433     mockParams.nRows = nRows;
00434     mockParams.pGenerator = pInputGenerator;
00435 
00436     ExecStreamEmbryo mockStreamEmbryo;
00437     mockStreamEmbryo.init(new MockProducerExecStream(), mockParams);
00438     mockStreamEmbryo.getStream()->setName("MockProducerExecStream");
00439 
00440     LcsClusterAppendExecStreamParams lcsAppendParams;
00441     initClusterAppendParams(lcsAppendParams, nCols, false);
00442 
00443     // setup temporary btree descriptor to get an empty page to start the btree
00444     btreeDescriptor.segmentAccessor.pSegment = lcsAppendParams.pSegment;
00445     btreeDescriptor.segmentAccessor.pCacheAccessor = pCache;
00446     btreeDescriptor.tupleDescriptor = lcsAppendParams.tupleDesc;
00447     btreeDescriptor.keyProjection = lcsAppendParams.keyProj;
00448     btreeDescriptor.rootPageId = NULL_PAGE_ID;
00449 
00450     BTreeBuilder builder(btreeDescriptor, pRandomSegment);
00451     builder.createEmptyRoot();
00452     savedRootPageId = builder.getRootPageId();
00453 
00454     lcsAppendParams.rootPageId = btreeDescriptor.rootPageId = savedRootPageId;
00455 
00456     ExecStreamEmbryo lcsAppendStreamEmbryo;
00457     lcsAppendStreamEmbryo.init(
00458         new LcsClusterAppendExecStream(),
00459         lcsAppendParams);
00460     lcsAppendStreamEmbryo.getStream()->setName("LcsClusterAppendExecStream");
00461 
00462     SharedExecStream pOutputStream = prepareTransformGraph(
00463         mockStreamEmbryo, lcsAppendStreamEmbryo);
00464 
00465     // set up a generator which can produce the expected output
00466     vector<boost::shared_ptr<ColumnGenerator<int64_t> > > columnGenerators;
00467     SharedInt64ColumnGenerator colGen =
00468         SharedInt64ColumnGenerator(new SeqColumnGenerator(nRows));
00469     columnGenerators.push_back(colGen);
00470     colGen = SharedInt64ColumnGenerator(new SeqColumnGenerator(0));
00471     columnGenerators.push_back(colGen);
00472 
00473     CompositeExecStreamGenerator expectedResultGenerator(columnGenerators);
00474 
00475     verifyOutput(*pOutputStream, 1, expectedResultGenerator);
00476 }
00477 
00478 void LcsClusterReplaceExecStreamTest::initClusterAppendParams(
00479     LcsClusterAppendExecStreamParams &lcsAppendParams,
00480     uint nCols,
00481     bool replace)
00482 {
00483     lcsAppendParams.scratchAccessor =
00484         pSegmentFactory->newScratchSegment(pCache, 10);
00485     lcsAppendParams.pCacheAccessor = pCache;
00486     lcsAppendParams.pSegment = pRandomSegment;
00487     lcsAppendParams.rootPageIdParamId = DynamicParamId(0);
00488 
00489     for (uint i = 0; i < nCols; i++) {
00490         lcsAppendParams.inputProj.push_back(i);
00491     }
00492     if (replace) {
00493         lcsAppendParams.inputProj.push_back(nCols);
00494     }
00495 
00496     // initialize the btree parameter portion of lcsAppendParams
00497     // BTree tuple desc only has one column
00498     (lcsAppendParams.tupleDesc).push_back(attrDesc_int64);
00499     (lcsAppendParams.tupleDesc).push_back(attrDesc_int64);
00500 
00501     // BTree key only has one column which is the first column.
00502     (lcsAppendParams.keyProj).push_back(0);
00503 
00504     // output only single row with 2 columns (# rows loaded, starting rid value)
00505     lcsAppendParams.outputTupleDesc.push_back(attrDesc_int64);
00506     lcsAppendParams.outputTupleDesc.push_back(attrDesc_int64);
00507 
00508     lcsAppendParams.pRootMap = 0;
00509 
00510     // Set up BTreeExecStreamParams using default values from BTreeDescriptor.
00511     lcsAppendParams.segmentId = btreeDescriptor.segmentId;
00512     lcsAppendParams.pageOwnerId = btreeDescriptor.pageOwnerId;
00513 }
00514 
00515 void LcsClusterReplaceExecStreamTest::verifyCluster(
00516     uint nCols,
00517     uint nRows,
00518     MockProducerExecStreamGenerator &resultGenerator)
00519 {
00520     // setup parameters into scan
00521     //  single cluster with only one column, project that single column
00522 
00523     LcsRowScanExecStreamParams scanParams;
00524     scanParams.hasExtraFilter = false;
00525     scanParams.isFullScan = true;
00526     scanParams.samplingMode = SAMPLING_OFF;
00527 
00528     struct LcsClusterScanDef clusterScanDef;
00529 
00530     for (uint i = 0; i < nCols; i++) {
00531         clusterScanDef.clusterTupleDesc.push_back(attrDesc_int64);
00532     }
00533     clusterScanDef.pSegment = btreeDescriptor.segmentAccessor.pSegment;
00534     clusterScanDef.pCacheAccessor =
00535         btreeDescriptor.segmentAccessor.pCacheAccessor;
00536     clusterScanDef.tupleDesc = btreeDescriptor.tupleDescriptor;
00537     clusterScanDef.keyProj = btreeDescriptor.keyProjection;
00538     clusterScanDef.rootPageId = btreeDescriptor.rootPageId;
00539     clusterScanDef.segmentId = btreeDescriptor.segmentId;
00540     clusterScanDef.pageOwnerId = btreeDescriptor.pageOwnerId;
00541 
00542     scanParams.lcsClusterScanDefs.push_back(clusterScanDef);
00543     for (uint i = 0; i < nCols; i++) {
00544         scanParams.outputTupleDesc.push_back(attrDesc_int64);
00545         scanParams.outputProj.push_back(i);
00546     }
00547 
00548     ValuesExecStreamParams valuesParams;
00549     ExecStreamEmbryo valuesStreamEmbryo;
00550     boost::shared_array<FixedBuffer> pBuffer;
00551 
00552     valuesParams.outputTupleDesc.push_back(attrDesc_int64);
00553     valuesParams.outputTupleDesc.push_back(attrDesc_bitmap);
00554     valuesParams.outputTupleDesc.push_back(attrDesc_bitmap);
00555 
00556     uint bufferSize = 16;
00557     pBuffer.reset(new FixedBuffer[bufferSize]);
00558     valuesParams.pTupleBuffer = pBuffer;
00559     valuesParams.bufSize = 0;
00560     valuesStreamEmbryo.init(new ValuesExecStream(), valuesParams);
00561     valuesStreamEmbryo.getStream()->setName("ValuesExecStream");
00562 
00563     ExecStreamEmbryo scanStreamEmbryo;
00564     scanStreamEmbryo.init(new LcsRowScanExecStream(), scanParams);
00565     scanStreamEmbryo.getStream()->setName("RowScanExecStream");
00566 
00567     SharedExecStream pOutputStream =
00568         prepareTransformGraph(valuesStreamEmbryo, scanStreamEmbryo);
00569 
00570     verifyOutput(*pOutputStream, nRows, resultGenerator);
00571 }
00572 
00573 void LcsClusterReplaceExecStreamTest::replaceCluster(
00574     uint nCols,
00575     uint nRows,
00576     SharedMockProducerExecStreamGenerator pGenerator)
00577 {
00578     MockProducerExecStreamParams mockParams;
00579     // +1 for the rid column
00580     for (uint i = 0; i < nCols + 1; i++) {
00581         mockParams.outputTupleDesc.push_back(attrDesc_int64);
00582     }
00583     mockParams.nRows = nRows;
00584     mockParams.pGenerator = pGenerator;
00585 
00586     ExecStreamEmbryo mockStreamEmbryo;
00587     mockStreamEmbryo.init(new MockProducerExecStream(), mockParams);
00588     mockStreamEmbryo.getStream()->setName("MockProducerExecStream");
00589 
00590     LcsClusterReplaceExecStreamParams lcsReplaceParams;
00591     initClusterAppendParams(lcsReplaceParams, nCols, true);
00592 
00593     btreeDescriptor.segmentAccessor.pSegment = lcsReplaceParams.pSegment;
00594     btreeDescriptor.segmentAccessor.pCacheAccessor = pCache;
00595     btreeDescriptor.tupleDescriptor = lcsReplaceParams.tupleDesc;
00596     btreeDescriptor.keyProjection = lcsReplaceParams.keyProj;
00597 
00598     lcsReplaceParams.rootPageId = btreeDescriptor.rootPageId = savedRootPageId;
00599 
00600     ExecStreamEmbryo lcsReplaceStreamEmbryo;
00601     lcsReplaceStreamEmbryo.init(
00602         new LcsClusterReplaceExecStream(),
00603         lcsReplaceParams);
00604     lcsReplaceStreamEmbryo.getStream()->setName("LcsClusterReplaceExecStream");
00605 
00606     SharedExecStream pOutputStream = prepareTransformGraph(
00607         mockStreamEmbryo, lcsReplaceStreamEmbryo);
00608 
00609     // set up a generator which can produce the expected output
00610     vector<boost::shared_ptr<ColumnGenerator<int64_t> > > columnGenerators;
00611     SharedInt64ColumnGenerator colGenerator =
00612         SharedInt64ColumnGenerator(new SeqColumnGenerator(nRows));
00613     columnGenerators.push_back(colGenerator);
00614     colGenerator = SharedInt64ColumnGenerator(new SeqColumnGenerator(0));
00615     columnGenerators.push_back(colGenerator);
00616 
00617     CompositeExecStreamGenerator expectedResultGenerator(columnGenerators);
00618 
00619     verifyOutput(*pOutputStream, 1, expectedResultGenerator);
00620 }
00621 
00622 void LcsClusterReplaceExecStreamTest::testCaseSetUp()
00623 {
00624     ExecStreamUnitTestBase::testCaseSetUp();
00625     SnapshotSegmentTestBase::testCaseSetUp();
00626 
00627     attrDesc_int64 = TupleAttributeDescriptor(
00628         stdTypeFactory.newDataType(STANDARD_TYPE_INT_64));
00629     attrDesc_bitmap = TupleAttributeDescriptor(
00630         stdTypeFactory.newDataType(STANDARD_TYPE_CHAR),
00631         true, pRandomSegment->getUsablePageSize() / 8);
00632 
00633     savedRootPageId = NULL_PAGE_ID;
00634 }
00635 
00636 void LcsClusterReplaceExecStreamTest::openRandomSegment()
00637 {
00638     // nothing to do since SnapshotSegmentTestBase::openSegmentStorage
00639     // has already set pRandomSegment to the snapshot segment.
00640 }
00641 
00642 void LcsClusterReplaceExecStreamTest::testCaseTearDown()
00643 {
00644     btreeDescriptor.segmentAccessor.reset();
00645     ExecStreamUnitTestBase::testCaseTearDown();
00646 }
00647 
00648 FENNEL_UNIT_TEST_SUITE(LcsClusterReplaceExecStreamTest);
00649 
00650 // End LcsClusterReplaceExecStreamTest.cpp

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