BTreeTxnTest Class Reference

Inheritance diagram for BTreeTxnTest:

ThreadedTestBase TestBase TraceTarget List of all members.

Public Member Functions

 BTreeTxnTest ()
virtual void testCaseSetUp ()
 Equivalent to JUnit TestCase.setUp; this is called before each test case method is invoked.
virtual void testCaseTearDown ()
 Equivalent to JUnit TestCase.tearDown; this is called after each test case method is invoked.
virtual void threadInit ()
virtual void threadTerminate ()
virtual bool testThreadedOp (int iOp)
 Test implementation must be supplied by derived test class.
TestSuitereleaseTestSuite ()
void beforeTestCase (std::string testCaseName)
void afterTestCase (std::string testCaseName)
virtual void notifyTrace (std::string source, TraceLevel level, std::string message)
 Receives notification when a trace event occurs.
virtual TraceLevel getSourceTraceLevel (std::string source)
 Gets the level at which a particular source should be traced.

Static Public Member Functions

static void readParams (int argc, char **argv)
 Parses the command line.

Static Public Attributes

static ParamName paramTestSuiteName
static ParamName paramTraceFileName
static ParamName paramDictionaryFileName
static ParamName paramTraceLevel
static ParamName paramStatsFileName
static ParamName paramTraceStdout
static ParamName paramDegreeOfParallelism
static ConfigMap configMap
 Configuration parameters.

Protected Member Functions

void runThreadedTestCase ()
 Executes specified test threads.
void snooze (uint nSeconds)

Protected Attributes

uint nSeconds
 Duration of multi-threaded test.
std::vector< int > threadCounts
 Number of threads to run for each type of operation.
TestSuitepTestSuite
 Boost test suite.
boost::shared_ptr< TestBasepTestObj
std::ofstream traceStream
 Output file stream for tracing.
StrictMutex traceMutex
 Protects traceStream.
std::string testName
 Name of test.
TraceLevel traceLevel
 Level at which to trace test execution.
FileStatsTarget statsTarget
 Output for stats.
StatsTimer statsTimer
 Timer for stats collection.
bool traceStdout
 Copy trace output to stdout.
bool traceFile
 Copy trace output to file.
TestCaseGroup defaultTests
TestCaseGroup extraTests

Static Protected Attributes

static bool runAll
 Run all test cases, including the extra tests.
static std::string runSingle
 Run only the test case of this name.

Private Types

enum  OpType {
  OP_INSERT, OP_DELETE, OP_SCAN, OP_CHECKPOINT,
  OP_MAX
}
 The various operations that can be run in the multi-threaded test. More...

Private Member Functions

void testTxns ()
void insertTxn ()
void deleteTxn ()
void scanTxn ()
void testCheckpoint ()
void endTxn (SharedLogicalTxn pTxn)
uint generateRandomNumber (uint iMax)
void createTree ()
RecordNum verifyTree ()
BTreeReadergetReader ()
BTreeWritergetWriter ()
TupleDatagetKeyData ()
void bindKey (int32_t &key)

Private Attributes

SharedCache pCache
SharedDatabase pDatabase
BTreeDescriptor treeDescriptor
boost::thread_specific_ptr<
TestThreadData
pTestThreadData
PageId rootPageId
bool testRollback
uint iKeyMax
uint nInsertsPerTxn
uint nDeletesPerTxn
uint nKeysPerScan
uint nSecondsBetweenCheckpoints

Classes

struct  Record
struct  TestThreadData

Detailed Description

Definition at line 49 of file BTreeTxnTest.cpp.


Member Enumeration Documentation

enum BTreeTxnTest::OpType [private]

The various operations that can be run in the multi-threaded test.

Enumerator:
OP_INSERT 
OP_DELETE 
OP_SCAN 
OP_CHECKPOINT 
OP_MAX 

Definition at line 63 of file BTreeTxnTest.cpp.

00063                 {
00064         OP_INSERT,
00065         OP_DELETE,
00066         OP_SCAN,
00067         OP_CHECKPOINT,
00068         OP_MAX
00069     };


Constructor & Destructor Documentation

BTreeTxnTest::BTreeTxnTest (  )  [explicit]

Definition at line 123 of file BTreeTxnTest.cpp.

References TestBase::configMap, ConfigMap::getIntParam(), iKeyMax, nDeletesPerTxn, nInsertsPerTxn, nKeysPerScan, ThreadedTestBase::nSeconds, nSecondsBetweenCheckpoints, OP_CHECKPOINT, OP_DELETE, OP_INSERT, OP_MAX, OP_SCAN, testRollback, testTxns(), and ThreadedTestBase::threadCounts.

00124 {
00125     nInsertsPerTxn = configMap.getIntParam("insertsPerTxn",5);
00126     nDeletesPerTxn = configMap.getIntParam("deletesPerTxn",5);
00127     nKeysPerScan = configMap.getIntParam("keysPerScan",5);
00128     iKeyMax = configMap.getIntParam("maxKey",1000000);
00129     nSecondsBetweenCheckpoints = configMap.getIntParam("checkpointInterval",20);
00130     testRollback = configMap.getIntParam(
00131         "testRollback",1);
00132 
00133     threadCounts.resize(OP_MAX,-1);
00134 
00135     threadCounts[OP_INSERT] = configMap.getIntParam(
00136         "insertThreads",-1);
00137     threadCounts[OP_DELETE] = configMap.getIntParam(
00138         "deleteThreads",-1);
00139     threadCounts[OP_SCAN] = configMap.getIntParam(
00140         "scanThreads",-1);
00141 
00142     if (nSecondsBetweenCheckpoints < nSeconds) {
00143         threadCounts[OP_CHECKPOINT] = 1;
00144     } else {
00145         threadCounts[OP_CHECKPOINT] = 0;
00146     }
00147 
00148     FENNEL_UNIT_TEST_CASE(BTreeTxnTest,testTxns);
00149 }


Member Function Documentation

void BTreeTxnTest::testTxns (  )  [private]

Definition at line 259 of file BTreeTxnTest.cpp.

References StatsTimer::addSource(), CHECKPOINT_DISCARD, TestBase::configMap, DeviceMode::load, Database::newDatabase(), pCache, pDatabase, SegmentAccessor::pSegment, SegmentAccessor::reset(), ThreadedTestBase::runThreadedTestCase(), BTreeDescriptor::segmentAccessor, StatsTimer::start(), TestBase::statsTimer, StatsTimer::stop(), treeDescriptor, and verifyTree().

Referenced by BTreeTxnTest().

00260 {
00261     runThreadedTestCase();
00262     RecordNum nEntries = verifyTree();
00263     pDatabase->checkpointImpl(CHECKPOINT_DISCARD);
00264 
00265     statsTimer.stop();
00266     pDatabase.reset();
00267     pDatabase = Database::newDatabase(
00268         pCache,
00269         configMap,
00270         DeviceMode::load,
00271         shared_from_this());
00272     BOOST_CHECK(pDatabase->isRecoveryRequired());
00273 
00274     StandardTypeDescriptorFactory typeFactory;
00275     SegmentAccessor scratchAccessor =
00276         pDatabase->getSegmentFactory()->newScratchSegment(
00277             pCache,
00278             1);
00279     SegmentAccessor segmentAccessor(pDatabase->getDataSegment(),pCache);
00280     BTreeRecoveryFactory btreeRecoveryFactory(
00281         segmentAccessor,
00282         scratchAccessor,
00283         typeFactory);
00284     segmentAccessor.reset();
00285     scratchAccessor.reset();
00286     pDatabase->recover(btreeRecoveryFactory);
00287 
00288     // Don't restart the stats timer until after recovery has completed.
00289     statsTimer.addSource(pDatabase);
00290     statsTimer.start();
00291 
00292     treeDescriptor.segmentAccessor.pSegment = pDatabase->getDataSegment();
00293     RecordNum nEntriesRecovered = verifyTree();
00294 
00295     // FIXME jvs 8-Mar-2004:  Turn this back on once NOTE above is taken
00296     // care of.  Tautological checks are just to shut warnings up.
00297 
00298     // BOOST_CHECK_EQUAL(nEntries,nEntriesRecovered);
00299     BOOST_CHECK_EQUAL(nEntries,nEntries);
00300     BOOST_CHECK_EQUAL(nEntriesRecovered,nEntriesRecovered);
00301 }

void BTreeTxnTest::insertTxn (  )  [private]

Definition at line 303 of file BTreeTxnTest.cpp.

References DUP_DISCARD, endTxn(), generateRandomNumber(), getWriter(), iKeyMax, BTreeWriter::insertTupleFromBuffer(), nInsertsPerTxn, pCache, pDatabase, and pTestThreadData.

Referenced by testThreadedOp().

00304 {
00305     SharedLogicalTxn pTxn = pDatabase->getTxnLog()->newLogicalTxn(pCache);
00306     pTxn->addParticipant(pTestThreadData->pWriter);
00307     BTreeWriter &writer = getWriter();
00308     for (uint i = 0; i < nInsertsPerTxn; ++i) {
00309         Record record;
00310         record.key = generateRandomNumber(iKeyMax);
00311         record.value = generateRandomNumber(iKeyMax);
00312         // TODO:  test with and without duplicates
00313         writer.insertTupleFromBuffer(
00314             reinterpret_cast<PConstBuffer>(&record),DUP_DISCARD);
00315     }
00316     endTxn(pTxn);
00317 }

void BTreeTxnTest::deleteTxn (  )  [private]

Definition at line 319 of file BTreeTxnTest.cpp.

References bindKey(), BTreeWriter::deleteCurrent(), DUP_SEEK_ANY, BTreeReader::endSearch(), endTxn(), generateRandomNumber(), getKeyData(), getWriter(), iKeyMax, nDeletesPerTxn, pCache, pDatabase, pTestThreadData, and BTreeReader::searchForKey().

Referenced by testThreadedOp().

00320 {
00321     SharedLogicalTxn pTxn = pDatabase->getTxnLog()->newLogicalTxn(pCache);
00322     pTxn->addParticipant(pTestThreadData->pWriter);
00323     BTreeWriter &writer = getWriter();
00324     for (uint i = 0; i < nDeletesPerTxn; ++i) {
00325         int32_t key = generateRandomNumber(iKeyMax);
00326         bindKey(key);
00327         if (writer.searchForKey(getKeyData(),DUP_SEEK_ANY)) {
00328             writer.deleteCurrent();
00329         }
00330         writer.endSearch();
00331     }
00332     endTxn(pTxn);
00333 }

void BTreeTxnTest::scanTxn (  )  [private]

Definition at line 335 of file BTreeTxnTest.cpp.

References bindKey(), DUP_SEEK_ANY, BTreeReader::endSearch(), generateRandomNumber(), getKeyData(), getReader(), iKeyMax, nKeysPerScan, BTreeReader::searchForKey(), and BTreeReader::searchNext().

Referenced by testThreadedOp().

00336 {
00337     BTreeReader &reader = getReader();
00338     int32_t key = generateRandomNumber(iKeyMax);
00339     bindKey(key);
00340     if (reader.searchForKey(getKeyData(),DUP_SEEK_ANY)) {
00341         for (uint i = 0; i < nKeysPerScan; ++i) {
00342             if (!reader.searchNext()) {
00343                 break;
00344             }
00345         }
00346     }
00347     reader.endSearch();
00348 }

void BTreeTxnTest::testCheckpoint (  )  [private]

Definition at line 395 of file BTreeTxnTest.cpp.

References CHECKPOINT_FLUSH_ALL, CHECKPOINT_FLUSH_FUZZY, TestBase::configMap, ConfigMap::getIntParam(), nSecondsBetweenCheckpoints, pDatabase, and TestBase::snooze().

Referenced by testThreadedOp().

00396 {
00397     snooze(nSecondsBetweenCheckpoints);
00398     CheckpointType checkpointType;
00399     if (configMap.getIntParam("fuzzyCheckpoint",1)) {
00400         checkpointType = CHECKPOINT_FLUSH_FUZZY;
00401     } else {
00402         checkpointType = CHECKPOINT_FLUSH_ALL;
00403     }
00404     pDatabase->requestCheckpoint(checkpointType,false);
00405 }

void BTreeTxnTest::endTxn ( SharedLogicalTxn  pTxn  )  [private]

Definition at line 350 of file BTreeTxnTest.cpp.

References generateRandomNumber(), and testRollback.

Referenced by deleteTxn(), and insertTxn().

00351 {
00352     if (testRollback) {
00353         if (generateRandomNumber(2)) {
00354             pTxn->commit();
00355         } else {
00356             pTxn->rollback();
00357         }
00358     } else {
00359         pTxn->commit();
00360     }
00361 }

uint BTreeTxnTest::generateRandomNumber ( uint  iMax  )  [private]

Definition at line 235 of file BTreeTxnTest.cpp.

References pTestThreadData.

Referenced by deleteTxn(), endTxn(), insertTxn(), and scanTxn().

00236 {
00237     return pTestThreadData->randomNumberGenerator(iMax);
00238 }

void BTreeTxnTest::createTree (  )  [private]

Definition at line 193 of file BTreeTxnTest.cpp.

References BTreeDescriptor::keyProjection, StandardTypeDescriptorFactory::newDataType(), pCache, SegmentAccessor::pCacheAccessor, pDatabase, SegmentAccessor::pSegment, rootPageId, BTreeDescriptor::rootPageId, BTreeDescriptor::segmentAccessor, STANDARD_TYPE_INT_32, treeDescriptor, and BTreeDescriptor::tupleDescriptor.

Referenced by testCaseSetUp().

00194 {
00195     TupleDescriptor &tupleDesc = treeDescriptor.tupleDescriptor;
00196     StandardTypeDescriptorFactory stdTypeFactory;
00197     TupleAttributeDescriptor attrDesc(
00198         stdTypeFactory.newDataType(STANDARD_TYPE_INT_32));
00199     tupleDesc.push_back(attrDesc);
00200     tupleDesc.push_back(attrDesc);
00201     TupleProjection &keyProj = treeDescriptor.keyProjection;
00202     keyProj.push_back(0);
00203 
00204     treeDescriptor.segmentAccessor.pSegment = pDatabase->getDataSegment();
00205     treeDescriptor.segmentAccessor.pCacheAccessor = pCache;
00206     treeDescriptor.rootPageId = rootPageId;
00207 
00208     BTreeBuilder builder(treeDescriptor,pDatabase->getDataSegment());
00209     builder.createEmptyRoot();
00210     treeDescriptor.rootPageId = builder.getRootPageId();
00211 }

RecordNum BTreeTxnTest::verifyTree (  )  [private]

Definition at line 407 of file BTreeTxnTest.cpp.

References BTreeVerifier::getStatistics(), BTreeStatistics::nLeafNodes, BTreeStatistics::nLevels, BTreeStatistics::nNonLeafNodes, BTreeStatistics::nTuples, treeDescriptor, and BTreeVerifier::verify().

Referenced by testTxns().

00408 {
00409     BTreeVerifier verifier(treeDescriptor);
00410     verifier.verify(false);
00411 
00412     BTreeStatistics const &stats = verifier.getStatistics();
00413     BOOST_MESSAGE("height = " << stats.nLevels);
00414     BOOST_MESSAGE("record count = " << stats.nTuples);
00415     BOOST_MESSAGE("leaf nodes = " << stats.nLeafNodes);
00416     BOOST_MESSAGE("nonleaf nodes = " << stats.nNonLeafNodes);
00417     return stats.nTuples;
00418 }

BTreeReader & BTreeTxnTest::getReader (  )  [private]

Definition at line 240 of file BTreeTxnTest.cpp.

References pTestThreadData.

Referenced by scanTxn(), and threadInit().

00241 {
00242     return *(pTestThreadData->pReader);
00243 }

BTreeWriter & BTreeTxnTest::getWriter (  )  [private]

Definition at line 250 of file BTreeTxnTest.cpp.

References pTestThreadData.

Referenced by deleteTxn(), and insertTxn().

00251 {
00252     return *(pTestThreadData->pWriter);
00253 }

TupleData & BTreeTxnTest::getKeyData (  )  [private]

Definition at line 245 of file BTreeTxnTest.cpp.

References pTestThreadData.

Referenced by bindKey(), deleteTxn(), and scanTxn().

00246 {
00247     return pTestThreadData->keyData;
00248 }

void BTreeTxnTest::bindKey ( int32_t key  )  [private]

Definition at line 390 of file BTreeTxnTest.cpp.

References getKeyData().

Referenced by deleteTxn(), and scanTxn().

00391 {
00392     getKeyData()[0].pData = reinterpret_cast<PConstBuffer>(&key);
00393 }

void BTreeTxnTest::testCaseSetUp (  )  [virtual]

Equivalent to JUnit TestCase.setUp; this is called before each test case method is invoked.

Default is no-op.

Reimplemented from TestBase.

Definition at line 151 of file BTreeTxnTest.cpp.

References StatsTimer::addSource(), TestBase::configMap, DeviceMode::createNew, createTree(), ConfigMap::isParamSet(), Cache::newCache(), Database::newDatabase(), NULL_PAGE_ID, Database::paramDatabaseDir, pCache, pDatabase, CacheParams::readConfig(), rootPageId, ConfigMap::setStringParam(), StatsTimer::start(), and TestBase::statsTimer.

00152 {
00153     // TODO:  cleanup
00154 
00155     configMap.setStringParam(
00156         Database::paramDatabaseDir,".");
00157     configMap.setStringParam(
00158         "databaseInitSize","1000");
00159     configMap.setStringParam(
00160         "tempInitSize","1000");
00161     configMap.setStringParam(
00162         "databaseShadowLogInitSize","2000");
00163     if (!configMap.isParamSet("databaseTxnLogInitSize")) {
00164         configMap.setStringParam(
00165             "databaseTxnLogInitSize","2000");
00166     }
00167 
00168     CacheParams cacheParams;
00169     cacheParams.readConfig(configMap);
00170     pCache = Cache::newCache(cacheParams);
00171     pDatabase = Database::newDatabase(
00172         pCache,
00173         configMap,
00174         DeviceMode::createNew,
00175         shared_from_this());
00176 
00177     statsTimer.addSource(pDatabase);
00178     statsTimer.start();
00179 
00180     rootPageId = NULL_PAGE_ID;
00181     createTree();
00182     pDatabase->checkpointImpl();
00183 }

void BTreeTxnTest::testCaseTearDown (  )  [virtual]

Equivalent to JUnit TestCase.tearDown; this is called after each test case method is invoked.

Default is no-op.

Reimplemented from TestBase.

Definition at line 185 of file BTreeTxnTest.cpp.

References pCache, pDatabase, TestBase::statsTimer, and StatsTimer::stop().

00186 {
00187     statsTimer.stop();
00188 
00189     pDatabase.reset();
00190     pCache.reset();
00191 }

void BTreeTxnTest::threadInit (  )  [virtual]

Reimplemented from ThreadedTestBase.

Definition at line 213 of file BTreeTxnTest.cpp.

References getReader(), pCache, pDatabase, pTestThreadData, ThreadedTestBase::threadInit(), and treeDescriptor.

00214 {
00215     ThreadedTestBase::threadInit();
00216     pTestThreadData.reset(new TestThreadData());
00217     pTestThreadData->pReader.reset(new BTreeReader(treeDescriptor));
00218     pTestThreadData->keyData.compute(getReader().getKeyDescriptor());
00219 
00220     SegmentAccessor scratchAccessor =
00221         pDatabase->getSegmentFactory()->newScratchSegment(
00222             pCache,
00223             1);
00224 
00225     pTestThreadData->pWriter.reset(
00226         new BTreeWriter(treeDescriptor,scratchAccessor));
00227 }

void BTreeTxnTest::threadTerminate (  )  [virtual]

Reimplemented from ThreadedTestBase.

Definition at line 229 of file BTreeTxnTest.cpp.

References pTestThreadData, and ThreadedTestBase::threadTerminate().

00230 {
00231     pTestThreadData.reset();
00232     ThreadedTestBase::threadTerminate();
00233 }

bool BTreeTxnTest::testThreadedOp ( int  iOp  )  [virtual]

Test implementation must be supplied by derived test class.

Parameters:
iOp operation type to test
Returns:
true if test should run again

Implements ThreadedTestBase.

Definition at line 363 of file BTreeTxnTest.cpp.

References deleteTxn(), insertTxn(), OP_CHECKPOINT, OP_DELETE, OP_INSERT, OP_MAX, OP_SCAN, pDatabase, scanTxn(), and testCheckpoint().

00364 {
00365     SXMutexSharedGuard checkpointSharedGuard(
00366         pDatabase->getCheckpointThread()->getActionMutex(),false);
00367     assert(iOp < OP_MAX);
00368     OpType op = static_cast<OpType>(iOp);
00369     switch (op) {
00370     case OP_INSERT:
00371         checkpointSharedGuard.lock();
00372         insertTxn();
00373         break;
00374     case OP_DELETE:
00375         checkpointSharedGuard.lock();
00376         deleteTxn();
00377         break;
00378     case OP_SCAN:
00379         scanTxn();
00380         break;
00381     case OP_CHECKPOINT:
00382         testCheckpoint();
00383         break;
00384     default:
00385         permAssert(false);
00386     }
00387     return true;
00388 }

void ThreadedTestBase::runThreadedTestCase (  )  [protected, inherited]

Executes specified test threads.

Definition at line 43 of file ThreadedTestBase.cpp.

References ThreadedTestBase::bDone, ThreadedTestBase::defaultThreadCount, ThreadedTestBase::nSeconds, ThreadedTestBase::pStartBarrier, TestBase::snooze(), ThreadPoolBase::start(), ThreadPoolBase::stop(), ThreadPool< Task >::submitTask(), and ThreadedTestBase::threadCounts.

Referenced by PagingTestBase::testMultipleThreads(), and testTxns().

00044 {
00045     bDone = false;
00046 
00047     // materialize default thread counts
00048     std::replace_if(
00049         threadCounts.begin(),
00050         threadCounts.end(),
00051         std::bind2nd(std::equal_to<int>(),-1),
00052         defaultThreadCount);
00053 
00054     // calculate how many threads are needed
00055     int nThreads = std::accumulate(
00056         threadCounts.begin(),
00057         threadCounts.end(),
00058         0);
00059 
00060     // initialize a barrier to make sure they all start at once
00061     pStartBarrier.reset(new boost::barrier(nThreads));
00062 
00063     // fire 'em up
00064     ThreadPool<ThreadedTestBaseTask> threadPool;
00065     threadPool.start(nThreads);
00066 
00067     // and distribute the tasks
00068     for (uint i = 0; i < threadCounts.size(); ++i) {
00069         for (int j = 0; j < threadCounts[i]; ++j) {
00070             ThreadedTestBaseTask task(*this,i);
00071             threadPool.submitTask(task);
00072         }
00073     }
00074 
00075     // run the tests for the requested duration
00076     snooze(nSeconds);
00077 
00078     // tell threads to quit and then wait for them to finish up
00079     bDone = true;
00080     threadPool.stop();
00081 }

void TestBase::snooze ( uint  nSeconds  )  [protected, inherited]

Definition at line 263 of file TestBase.cpp.

Referenced by DatabaseTest::executeForceTxn(), ThreadedTestBase::runThreadedTestCase(), PagingTestBase::testCacheResize(), testCheckpoint(), PagingTestBase::testCheckpointGuarded(), PagingTestBase::testPrefetch(), and PagingTestBase::testPrefetchBatch().

00264 {
00265 #ifdef __MSVC__
00266     ::_sleep(nSeconds*1000);
00267 #else
00268     ::sleep(nSeconds);
00269 #endif
00270 }

void TestBase::readParams ( int  argc,
char **  argv 
) [static, inherited]

Parses the command line.

format: [-v] [-t TEST | -all] {param=val}* [CONFIGFILE | -] Normally, the test program runs the default test cases. With the option "-all", runs the extra test cases as well. With the option "-t TEST", runs only the single test case named TEST. CONFIGFILE is read to load configuration parameters. Configuration parameters can also be set ad hoc, from the command line, as pairs name=val. These take precedence.

Definition at line 108 of file TestBase.cpp.

References TestBase::configMap, ConfigMap::dumpParams(), ConfigMap::isParamSet(), ConfigMap::mergeFrom(), TestBase::paramDictionaryFileName, ConfigMap::readParams(), TestBase::runAll, TestBase::runSingle, ConfigMap::setStringParam(), and verbose.

00109 {
00110     bool verbose = false;
00111     ConfigMap adhocMap;
00112 
00113     for (int i = 1; i < argc; ++i) {
00114         std::string arg = argv[i];
00115         if (argv[i][0] == '-') {
00116             if (arg == "-v") {
00117                 verbose = true;
00118             } else if (arg == "-") {
00119                 configMap.readParams(std::cin);
00120             } else if (arg == "-all") {
00121                 runAll = true;
00122             } else if (arg == "-t") {   // -t TEST
00123                 permAssert(i + 1 < argc);
00124                 runSingle = argv[++i];
00125             } else if (arg[1] == 't') { // allow -tTEST
00126                 runSingle = arg.substr(2);
00127             }
00128         } else {
00129             int i = arg.find("=");
00130             if ((0 < i) && (i < arg.size())) {
00131                 // an ad hoc parameter
00132                 std::string key = arg.substr(0,i);
00133                 std::string val = arg.substr(i + 1);
00134                 adhocMap.setStringParam(key,val);
00135             } else {
00136                 // a config file name
00137                 std::ifstream configFile(arg.c_str());
00138                 assert(configFile.good());
00139                 configMap.readParams(configFile);
00140             }
00141         }
00142     }
00143     configMap.mergeFrom(adhocMap);
00144 
00145     // set a default dictionary file location for use by tests that need a
00146     // small non-random sorted data set
00147     if (!configMap.isParamSet(paramDictionaryFileName)) {
00148         std::string dictFileName = "dictWords";
00149         configMap.setStringParam(paramDictionaryFileName,dictFileName);
00150     }
00151 
00152     if (verbose) {
00153         configMap.dumpParams(std::cout);
00154     }
00155 }

TestSuite * TestBase::releaseTestSuite (  )  [inherited]

Definition at line 157 of file TestBase.cpp.

References TestBase::TestCaseGroup::addAllToTestSuite(), TestBase::defaultTests, TestBase::extraTests, TestBase::TestCaseGroup::findTest(), TestBase::pTestObj, TestBase::pTestSuite, TestBase::runAll, TestBase::runSingle, and TestBase::testName.

00158 {
00159     assert(pTestObj);
00160     assert(pTestObj.use_count() > 1);
00161 
00162     // release self-reference now that all test cases have been registered
00163     pTestObj.reset();
00164 
00165     TestSuite* pTestSuite = BOOST_TEST_SUITE(testName.c_str());
00166 
00167     if (runSingle.size()) {
00168         test_unit *p =  defaultTests.findTest(runSingle);
00169         if (!p) {
00170             p = extraTests.findTest(runSingle);
00171         }
00172         if (!p) {
00173             std::cerr << "test " << runSingle << " not found\n";
00174             exit(2);
00175         }
00176         pTestSuite->add(p);
00177     } else {
00178         defaultTests.addAllToTestSuite(pTestSuite);
00179         if (runAll) {
00180             extraTests.addAllToTestSuite(pTestSuite);
00181         }
00182     }
00183     return pTestSuite;
00184 }

void TestBase::beforeTestCase ( std::string  testCaseName  )  [inherited]

Definition at line 214 of file TestBase.cpp.

References TestBase::configMap, TraceSource::initTraceSource(), AutoBacktrace::install(), TestBase::notifyTrace(), AutoBacktrace::setOutputStream(), AutoBacktrace::setTraceTarget(), TestBase::testName, and TRACE_INFO.

00215 {
00216     notifyTrace(testName,TRACE_INFO,"ENTER:  " + testCaseName);
00217 
00218     // Install the AutoBacktrace signal handler now, after
00219     // boost::execution_monitor::catch_signals() has installed its own, so that
00220     // on SIGABRT AutoBacktrace goes first, prints the backtrace, then chains
00221     // to boost, which handles the error.
00222     AutoBacktrace::setOutputStream();
00223     AutoBacktrace::setTraceTarget(shared_from_this());
00224     AutoBacktrace::install();
00225     configMap.initTraceSource(shared_from_this(), "testConfig");
00226 }

void TestBase::afterTestCase ( std::string  testCaseName  )  [inherited]

Definition at line 228 of file TestBase.cpp.

References TestBase::configMap, TraceSource::disableTracing(), TestBase::notifyTrace(), AutoBacktrace::setTraceTarget(), TestBase::testName, and TRACE_INFO.

00229 {
00230     AutoBacktrace::setTraceTarget();
00231     configMap.disableTracing();
00232     notifyTrace(testName,TRACE_INFO,"LEAVE:  " + testCaseName);
00233 }

void TestBase::notifyTrace ( std::string  source,
TraceLevel  level,
std::string  message 
) [virtual, inherited]

Receives notification when a trace event occurs.

Parameters:
source the facility from which the message originated
level the trace event severity level
message the text of the message

Implements TraceTarget.

Definition at line 243 of file TestBase.cpp.

References TestBase::traceFile, TestBase::traceMutex, TestBase::traceStdout, and TestBase::traceStream.

Referenced by TestBase::afterTestCase(), and TestBase::beforeTestCase().

00244 {
00245     if (traceFile || traceStdout) {
00246         StrictMutexGuard traceMutexGuard(traceMutex);
00247         if (traceFile) {
00248             traceStream << "[" << source << "] " << message << std::endl;
00249             traceStream.flush();
00250         }
00251         if (traceStdout) {
00252             std::cout << "[" << source << "] " << message << std::endl;
00253             std::cout.flush();
00254         }
00255     }
00256 }

TraceLevel TestBase::getSourceTraceLevel ( std::string  source  )  [virtual, inherited]

Gets the level at which a particular source should be traced.

Parameters:
source name of source to be traced
Returns:
minimum severity level which should be traced

Implements TraceTarget.

Definition at line 258 of file TestBase.cpp.

References TestBase::traceLevel.

Referenced by LbmExecStreamTestBase::generateBitmaps().

00259 {
00260     return traceLevel;
00261 }


Member Data Documentation

SharedCache BTreeTxnTest::pCache [private]

Definition at line 78 of file BTreeTxnTest.cpp.

Referenced by createTree(), deleteTxn(), insertTxn(), testCaseSetUp(), testCaseTearDown(), testTxns(), and threadInit().

SharedDatabase BTreeTxnTest::pDatabase [private]

Definition at line 79 of file BTreeTxnTest.cpp.

Referenced by createTree(), deleteTxn(), insertTxn(), testCaseSetUp(), testCaseTearDown(), testCheckpoint(), testThreadedOp(), testTxns(), and threadInit().

BTreeDescriptor BTreeTxnTest::treeDescriptor [private]

Definition at line 81 of file BTreeTxnTest.cpp.

Referenced by createTree(), testTxns(), threadInit(), and verifyTree().

boost::thread_specific_ptr<TestThreadData> BTreeTxnTest::pTestThreadData [private]

Definition at line 83 of file BTreeTxnTest.cpp.

Referenced by deleteTxn(), generateRandomNumber(), getKeyData(), getReader(), getWriter(), insertTxn(), threadInit(), and threadTerminate().

PageId BTreeTxnTest::rootPageId [private]

Definition at line 84 of file BTreeTxnTest.cpp.

Referenced by createTree(), and testCaseSetUp().

bool BTreeTxnTest::testRollback [private]

Definition at line 86 of file BTreeTxnTest.cpp.

Referenced by BTreeTxnTest(), and endTxn().

uint BTreeTxnTest::iKeyMax [private]

Definition at line 87 of file BTreeTxnTest.cpp.

Referenced by BTreeTxnTest(), deleteTxn(), insertTxn(), and scanTxn().

uint BTreeTxnTest::nInsertsPerTxn [private]

Definition at line 88 of file BTreeTxnTest.cpp.

Referenced by BTreeTxnTest(), and insertTxn().

uint BTreeTxnTest::nDeletesPerTxn [private]

Definition at line 89 of file BTreeTxnTest.cpp.

Referenced by BTreeTxnTest(), and deleteTxn().

uint BTreeTxnTest::nKeysPerScan [private]

Definition at line 90 of file BTreeTxnTest.cpp.

Referenced by BTreeTxnTest(), and scanTxn().

uint BTreeTxnTest::nSecondsBetweenCheckpoints [private]

Definition at line 92 of file BTreeTxnTest.cpp.

Referenced by BTreeTxnTest(), and testCheckpoint().

uint ThreadedTestBase::nSeconds [protected, inherited]

Duration of multi-threaded test.

Definition at line 65 of file ThreadedTestBase.h.

Referenced by BTreeTxnTest(), PagingTestBase::PagingTestBase(), ThreadedTestBase::runThreadedTestCase(), PagingTestBase::testCacheResize(), and ThreadedTestBase::ThreadedTestBase().

std::vector<int> ThreadedTestBase::threadCounts [protected, inherited]

Number of threads to run for each type of operation.

Definition at line 70 of file ThreadedTestBase.h.

Referenced by BTreeTxnTest(), CacheTest::CacheTest(), SegmentTestBase::openStorage(), PagingTestBase::PagingTestBase(), ThreadedTestBase::runThreadedTestCase(), and SegmentTestBase::SegmentTestBase().

TestSuite* TestBase::pTestSuite [protected, inherited]

Boost test suite.

Definition at line 59 of file TestBase.h.

Referenced by TestBase::releaseTestSuite().

boost::shared_ptr<TestBase> TestBase::pTestObj [protected, inherited]

Definition at line 61 of file TestBase.h.

Referenced by TestBase::releaseTestSuite(), and TestBase::TestBase().

std::ofstream TestBase::traceStream [protected, inherited]

Output file stream for tracing.

Definition at line 66 of file TestBase.h.

Referenced by TestBase::notifyTrace(), TestBase::TestBase(), and TestBase::~TestBase().

StrictMutex TestBase::traceMutex [protected, inherited]

Protects traceStream.

Definition at line 71 of file TestBase.h.

Referenced by TestBase::notifyTrace().

std::string TestBase::testName [protected, inherited]

Name of test.

Definition at line 76 of file TestBase.h.

Referenced by TestBase::afterTestCase(), TestBase::beforeTestCase(), TestBase::releaseTestSuite(), TestBase::TestBase(), LhxHashTableTest::testInsert1Ka(), and LhxHashTableTest::testInsert1Kb().

TraceLevel TestBase::traceLevel [protected, inherited]

Level at which to trace test execution.

Definition at line 81 of file TestBase.h.

Referenced by TestBase::getSourceTraceLevel(), and TestBase::TestBase().

FileStatsTarget TestBase::statsTarget [protected, inherited]

Output for stats.

Definition at line 86 of file TestBase.h.

StatsTimer TestBase::statsTimer [protected, inherited]

Timer for stats collection.

Definition at line 91 of file TestBase.h.

Referenced by CacheTestBase::closeStorage(), CacheTestBase::openStorage(), testCaseSetUp(), testCaseTearDown(), and testTxns().

bool TestBase::traceStdout [protected, inherited]

Copy trace output to stdout.

Definition at line 99 of file TestBase.h.

Referenced by TestBase::notifyTrace(), and TestBase::TestBase().

bool TestBase::traceFile [protected, inherited]

Copy trace output to file.

Definition at line 104 of file TestBase.h.

Referenced by TestBase::notifyTrace(), and TestBase::TestBase().

bool TestBase::runAll [static, protected, inherited]

Run all test cases, including the extra tests.

(static, since set by readParams())

Definition at line 110 of file TestBase.h.

Referenced by TestBase::readParams(), and TestBase::releaseTestSuite().

std::string TestBase::runSingle [static, protected, inherited]

Run only the test case of this name.

(static, since set by readParams())

Definition at line 116 of file TestBase.h.

Referenced by TestBase::readParams(), and TestBase::releaseTestSuite().

TestCaseGroup TestBase::defaultTests [protected, inherited]

Definition at line 139 of file TestBase.h.

Referenced by TestBase::releaseTestSuite().

TestCaseGroup TestBase::extraTests [protected, inherited]

Definition at line 140 of file TestBase.h.

Referenced by TestBase::releaseTestSuite().

ParamName TestBase::paramTestSuiteName [static, inherited]

Definition at line 143 of file TestBase.h.

Referenced by TestBase::TestBase().

ParamName TestBase::paramTraceFileName [static, inherited]

Definition at line 144 of file TestBase.h.

Referenced by TestBase::TestBase().

ParamName TestBase::paramDictionaryFileName [static, inherited]

Definition at line 145 of file TestBase.h.

Referenced by TestBase::readParams(), SegStreamTest::testRead(), and SegStreamTest::testWrite().

ParamName TestBase::paramTraceLevel [static, inherited]

Definition at line 146 of file TestBase.h.

Referenced by TestBase::TestBase().

ParamName TestBase::paramStatsFileName [static, inherited]

Definition at line 147 of file TestBase.h.

ParamName TestBase::paramTraceStdout [static, inherited]

Definition at line 148 of file TestBase.h.

Referenced by TestBase::TestBase().

ParamName TestBase::paramDegreeOfParallelism [static, inherited]

Definition at line 149 of file TestBase.h.

Referenced by ParallelExecStreamSchedulerTest::ParallelExecStreamSchedulerTest().

ConfigMap TestBase::configMap [static, inherited]

Configuration parameters.

The reason this is static is so that no constructor parameters (which burden virtual bases) are needed.

Definition at line 155 of file TestBase.h.

Referenced by TestBase::afterTestCase(), TestBase::beforeTestCase(), BTreeTxnTest(), CacheTestBase::CacheTestBase(), BackupRestoreTest::createSnapshotData(), DatabaseTest::DatabaseTest(), TestOptionsTest::extra(), DatabaseTest::loadDatabase(), SparseBitmapTest::openStorage(), PagingTestBase::PagingTestBase(), ParallelExecStreamSchedulerTest::ParallelExecStreamSchedulerTest(), RandomAccessFileDeviceTest::RandomAccessFileDeviceTest(), TestBase::readParams(), SegStorageTestBase::SegStorageTestBase(), TestOptionsTest::test1(), TestOptionsTest::test2(), BackupRestoreTest::testBackupCleanup(), TestBase::TestBase(), testCaseSetUp(), testCheckpoint(), DatabaseTest::testCreateEmpty(), DatabaseTest::testForceTxns(), BackupRestoreTest::testHeaderBackupRestore(), SegPageEntryIterTest::testIter(), SegStreamTest::testRead(), testTxns(), SegStreamTest::testWrite(), ThreadedTestBase::ThreadedTestBase(), and TestBase::~TestBase().


The documentation for this class was generated from the following file:
Generated on Mon Jun 22 04:00:26 2009 for Fennel by  doxygen 1.5.1