#include "lsmtest.h"
#define DATA_SEQUENTIAL TEST_DATASOURCE_SEQUENCE
#define DATA_RANDOM TEST_DATASOURCE_RANDOM
typedef struct Datatest4 Datatest4;
struct Datatest4 {
DatasourceDefn defn;
int nRec;
int nRepeat;
int bReopen;
};
static void doDataTest4(
const char *zSystem,
Datatest4 *p,
int *pRc
){
lsm_db *db = 0;
TestDb *pDb;
TestDb *pControl;
Datasource *pData;
int i;
int rc = 0;
int iDot = 0;
int bMultiThreaded = 0;
int nRecOn3 = (p->nRec / 3);
int iData = 0;
rc = testControlDb(&pControl);
pDb = testOpen(zSystem, 1, &rc);
pData = testDatasourceNew(&p->defn);
if( rc==0 ){
db = tdb_lsm(pDb);
bMultiThreaded = tdb_lsm_multithread(pDb);
}
testWriteDatasourceRange(pControl, pData, iData, nRecOn3*3, &rc);
testWriteDatasourceRange(pDb, pData, iData, nRecOn3*3, &rc);
for(i=0; rc==0 && i<p->nRepeat; i++){
testDeleteDatasourceRange(pControl, pData, iData, nRecOn3*2, &rc);
testDeleteDatasourceRange(pDb, pData, iData, nRecOn3*2, &rc);
if( db ){
int nDone;
#if 0#endif
do {
nDone = 0;
rc = lsm_work(db, 1, (1<<30), &nDone);
}while( rc==0 && nDone>0 );
if( bMultiThreaded && rc==LSM_BUSY ) rc = LSM_OK;
#if 0#endif
}
if( i+1<p->nRepeat ){
iData += (nRecOn3*2);
testWriteDatasourceRange(pControl, pData, iData+nRecOn3, nRecOn3*2, &rc);
testWriteDatasourceRange(pDb, pData, iData+nRecOn3, nRecOn3*2, &rc);
testCompareDb(pData, nRecOn3*3, iData, pControl, pDb, &rc);
if( p->bReopen ){
testReopen(&pDb, &rc);
if( rc==0 ) db = tdb_lsm(pDb);
}
}
testCaseProgress(i, p->nRepeat, testCaseNDot(), &iDot);
}
testClose(&pDb);
testClose(&pControl);
testDatasourceFree(pData);
testCaseFinish(rc);
*pRc = rc;
}
static char *getName4(const char *zSystem, Datatest4 *pTest){
char *zRet;
char *zData;
zData = testDatasourceName(&pTest->defn);
zRet = testMallocPrintf("data4.%s.%s.%d.%d.%d",
zSystem, zData, pTest->nRec, pTest->nRepeat, pTest->bReopen
);
testFree(zData);
return zRet;
}
void test_data_4(
const char *zSystem,
const char *zPattern,
int *pRc
){
Datatest4 aTest[] = {
{ {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 0 },
{ {DATA_RANDOM, 20,25, 500,600}, 10000, 10, 1 },
};
int i;
for(i=0; *pRc==LSM_OK && i<ArraySize(aTest); i++){
char *zName = getName4(zSystem, &aTest[i]);
if( testCaseBegin(pRc, zPattern, "%s", zName) ){
doDataTest4(zSystem, &aTest[i], pRc);
}
testFree(zName);
}
}