Commit 36aaf769 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

test_db_curs4 is good, but too much randomness

git-svn-id: file:///svn/tokudb@1057 c7de825b-a66e-492c-adef-691d508d4ae1
parent dafce7dc
......@@ -139,3 +139,6 @@ make_libs:
clean:
rm -f $(ALL_TESTS) *.o
rm -rf dir.*.tdb dir.*.bdb
test_db_curs4.tdb: trace.h
......@@ -274,25 +274,58 @@ void do_create (void) {
assert(n_named==n_prim);
}
int rcount=0;
void insert_person (void) {
int namelen = 5+random()%245;
rcount++;
struct primary_key pk;
struct primary_data pd;
char keyarray[1000], dataarray[1000];
unsigned char namearray[1000];
pk.rand = random();
rcount++;
gettod(&pk.ts);
pd.creationtime = pk.ts;
pd.expiretime = pk.ts;
pd.expiretime.tv_sec += 24*60*60*366;
pd.doesexpire = (random()%10==0);
int i;
pd.name.name = namearray;
pd.name.name[0] = 'A'+random()%26;
for (i=1; i<namelen; i++) {
pd.name.name[i] = 'a'+random()%26;
pd.doesexpire = 0;
random();
rcount++;
if (opnum==2 || opnum==10 || opnum==22 || opnum==86) {
pd.doesexpire = 1;
}
pd.name.name[i]=0;
int i;
for (i=0; i<namelen; i++) { random(); rcount++; }
namelen=i=2;
char *newnamearray;
if (oppass==1 && opnum==1) newnamearray="Cd";
else if (oppass==1 && opnum==2) newnamearray="Ew";
else if (oppass==1 && opnum==5) newnamearray="Zq";
else if (oppass==1 && opnum==6) newnamearray="Ug";
else if (oppass==1 && opnum==9) newnamearray="Ib";
else if (oppass==1 && opnum==10) newnamearray="Cf";
else if (oppass==1 && opnum==13) newnamearray="Qf";
else if (oppass==1 && opnum==14) newnamearray="Pp";
else if (oppass==1 && opnum==15) newnamearray="Dz";
else if (oppass==1 && opnum==16) newnamearray="Dd";
else if (oppass==1 && opnum==22) newnamearray="Uy";
else if (oppass==1 && opnum==24) newnamearray="Wm";
else if (oppass==1 && opnum==25) newnamearray="Qw";
else if (oppass==1 && opnum==26) newnamearray="Fg";
else if (oppass==1 && opnum==30) newnamearray="Iv";
else if (oppass==2 && opnum==9) newnamearray="Dq";
else if (oppass==2 && opnum==15) newnamearray="Rr";
else if (oppass==2 && opnum==36) newnamearray="Sp";
else if (oppass==2 && opnum==37) newnamearray="Uo";
else if (oppass==2 && opnum==39) newnamearray="Je";
else if (oppass==2 && opnum==73) newnamearray="Kg";
else if (oppass==2 && opnum==74) newnamearray="Gp";
else if (oppass==2 && opnum==76) newnamearray="Iv";
else if (oppass==2 && opnum==86) newnamearray="Sk";
else if (oppass==2 && opnum==100) newnamearray="Tq";
else abort();
pd.name.name=(unsigned char*)newnamearray;
//printf("%2d %d: pk.rand=%u;\n", oppass, opnum, pk.rand);
DBT key,data;
memset(&key,0,sizeof(DBT));
memset(&data,0,sizeof(DBT));
......@@ -307,7 +340,7 @@ void insert_person (void) {
int r=dbp->put(dbp, null_txn, &key, &data,0); CKERR(r);
// If the cursor is to the left of the current item, then increment count_items
{
int compare=strcmp((char*)namearray, nc_key.data);
int compare=strcmp((char*)newnamearray, nc_key.data);
//printf("%s:%d compare=%d insert %s, cursor at %s\n", __FILE__, __LINE__, compare, namearray, (char*)nc_key.data);
if (compare>0) calc_n_items++;
count_all_items++;
......@@ -327,19 +360,21 @@ void delete_oldest_expired (void) {
printf("%s:%d %d:%d delete\n", __FILE__, __LINE__, oppass, opnum);
int r;
random();
rcount++;
if (delete_cursor==0) {
r = expiredb->cursor(expiredb, null_txn, &delete_cursor, 0); CKERR(r);
}
DBT key,pkey,data, savepkey;
DBT pkey;
{
DBT key,data;
memset(&key, 0, sizeof(key));
memset(&pkey, 0, sizeof(pkey));
memset(&data, 0, sizeof(data));
#if 1
r = delete_cursor->c_pget(delete_cursor, &key, &pkey, &data, DB_FIRST);
if (r==DB_NOTFOUND) return;
CKERR(r);
#endif
}
printf("%s:%d oppass==%d opnum==%d ", __FILE__, __LINE__, oppass, opnum);
{
if (oppass==2 && opnum==8) {
......@@ -361,12 +396,16 @@ void delete_oldest_expired (void) {
}
}
count_all_items--;
savepkey = pkey;
DBT savepkey = pkey;
savepkey.data = malloc(pkey.size);
memcpy(savepkey.data, pkey.data, pkey.size);
r = dbp->del(dbp, null_txn, &pkey, 0); CKERR(r);
// Make sure it's really gone.
{
DBT data;
memset(&data, 0, sizeof(data));
r = dbp->get(dbp, null_txn, &savepkey, &data, 0);
}
assert(r==DB_NOTFOUND);
free(savepkey.data);
}
......@@ -399,14 +438,21 @@ void step_name (void) {
int cursor_load=2; /* Set this to a higher number to do more cursor work for every insertion. Needed to get to the end. */
void activity (void) {
if (random()%20==0) {
random();
rcount++;
if (oppass==2 && (opnum==8 || opnum==53 || opnum==57 || opnum==65 || opnum==78 || opnum==97)) {
// Delete the oldest expired one. Keep the cursor open
delete_oldest_expired();
} else if (random()%cursor_load==0) {
} else {
random();
rcount++;
if ((oppass==2 && (opnum==9 || opnum==15 || opnum==36 || opnum==37 || opnum==39 || opnum==73 || opnum==74 || opnum==76 || opnum==86 || opnum==100))
|| (oppass==1 && (opnum==1 || opnum==2 || opnum==5 || opnum==6 || opnum==9 || opnum==10 || opnum==13 || opnum==14 || opnum==15 || opnum==16 || opnum==22 || opnum==24 || opnum==25 || opnum==26 || opnum==30))) {
insert_person();
} else {
step_name();
}
}
//assert(count_all_items==count_entries(dbp));
}
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment