/* -*- mode: C; c-basic-offset: 4 -*- */ #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #include "memory.h" #include "cachetable.h" #include "toku_assert.h" #include #include #include #include #include "test.h" static const int test_object_size = 1; static CACHETABLE ct; enum { N_PRESENT_LIMIT = 4, TRIALS=200, N_FILES=2 }; static int n_present=0; static struct present_items { CACHEKEY key; CACHEFILE cf; } present_items[N_PRESENT_LIMIT]; static void print_ints(void) __attribute__((__unused__)); static void print_ints(void) { int i; for (i=0; ilsn = 0; return 0; } static void verify_cachetable_against_present (void) { int i; for (i=0; i0 && r0) { // First touch some random ones int whichone = random()%n_present; void *value; //printf("Touching %d (%lld, %p)\n", whichone, present_items[whichone].key, present_items[whichone].cf); r = toku_cachetable_get_and_pin(present_items[whichone].cf, present_items[whichone].key, &value, NULL, flush_forchain, fetch_forchain, (void*)(long)present_items[whichone].key ); assert(r==0); r = toku_cachetable_unpin(present_items[whichone].cf, present_items[whichone].key, CACHETABLE_CLEAN, test_object_size); assert(r==0); } i += 1+ random()%100; int fnum = i%N_FILES; // i is always incrementing, so we need not worry about inserting a duplicate //printf("%s:%d Add {%d,%p}\n", __FILE__, __LINE__, i, f[fnum]); r = toku_cachetable_put(f[fnum], i, (void*)i, test_object_size, flush_forchain, fetch_forchain, (void*)i); assert(r==0); item_becomes_present(f[fnum], i); //print_ints(); //cachetable_print_state(ct); r = toku_cachetable_unpin(f[fnum], i, CACHETABLE_CLEAN, test_object_size); assert(r==0); verify_cachetable_against_present(); if (random()%10==0) { i = random()%N_FILES; //printf("Close %d (%p), now n_present=%d\n", i, f[i], n_present); //print_ints(); CACHEFILE oldcf=f[i]; r = toku_cachefile_close(&f[i]); assert(r==0); file_is_not_present(oldcf); r = toku_cachetable_openf(&f[i], ct, fname[i], O_RDWR, 0777); assert(r==0); } } for (i=0; i