#include "lsmtest.h"
typedef struct Mctest Mctest;
struct Mctest {
DatasourceDefn defn;
int nStep;
int nWriteStep;
int nReader;
};
static void do_mc_test(
const char *zSystem,
Mctest *pTest,
int *pRc
){
const int nDomain = pTest->nStep * pTest->nWriteStep;
Datasource *pData;
TestDb *pDb;
int iReader;
int iStep;
int iDot = 0;
struct Reader {
TestDb *pDb;
int iLast;
} *aReader;
pData = testDatasourceNew(&pTest->defn);
pDb = testOpen(zSystem, 1, pRc);
aReader = (struct Reader *)testMalloc(sizeof(aReader[0]) * pTest->nReader);
for(iReader=0; iReader<pTest->nReader; iReader++){
aReader[iReader].pDb = testOpen(zSystem, 0, pRc);
}
for(iStep=0; iStep<pTest->nStep; iStep++){
int iLast;
int iBegin;
int iFirst = iStep*pTest->nWriteStep;
testWriteDatasourceRange(pDb, pData, iFirst, pTest->nWriteStep, pRc);
iLast = (iStep+1) * pTest->nWriteStep - 1;
testDbContents(pDb, pData, nDomain, 0, iLast, iLast, 1, pRc);
iBegin = (iStep % pTest->nReader);
if( iBegin<iStep ) tdb_commit(aReader[iBegin].pDb, 0);
tdb_begin(aReader[iBegin].pDb, 1);
aReader[iBegin].iLast = iLast;
for(iReader=0; iReader<pTest->nReader && aReader[iReader].iLast; iReader++){
iLast = aReader[iReader].iLast;
testDbContents(
aReader[iReader].pDb, pData, nDomain, 0, iLast, iLast, 1, pRc
);
}
testCaseProgress(iStep, pTest->nStep, testCaseNDot(), &iDot);
}
for(iReader=0; iReader<pTest->nReader; iReader++){
testClose(&aReader[iReader].pDb);
}
testFree(aReader);
testClose(&pDb);
testDatasourceFree(pData);
}
void test_mc(
const char *zSystem,
const char *zPattern,
int *pRc
){
int i;
Mctest aTest[] = {
{ { TEST_DATASOURCE_RANDOM, 10,10, 100,100 }, 100, 10, 5 },
};
for(i=0; i<ArraySize(aTest); i++){
if( testCaseBegin(pRc, zPattern, "mc1.%s.%d", zSystem, i) ){
do_mc_test(zSystem, &aTest[i], pRc);
testCaseFinish(*pRc);
}
}
}