Commit 136b3161 authored by Vincenzo Liberatore's avatar Vincenzo Liberatore

Addresses #288

Exercise buffer increase and decrease.

git-svn-id: file:///svn/tokudb@1910 c7de825b-a66e-492c-adef-691d508d4ae1
parent 460b31fd
/* We are going to test whether we can manage memory once we do lots of
insert and delete. */
#include "test.h"
unsigned malloc_cnt;
unsigned malloc_cntl;
/* Controllable malloc failure: it fails only the ith time it is invoked */
static void* malloc_fail(size_t size) {
if (malloc_cntl == ++malloc_cnt) {
errno = ENOMEM;
return NULL;
} else
return malloc(size);
}
int main(int argc, const char *argv[]) {
int i, j;
int r;
toku_range_tree *tree;
toku_range range;
int nums[1024];
char letters[2] = {'A','B'};
for (i = 0; i < 1024; i++)
nums[i] = i;
parse_args(argc, argv);
/* Insert and delete lots of ranges to force memory increase and decrease */
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, malloc, free, realloc);
CKERR(r);
/* Insert lots of ranges */
for (i = 0; i < 512; i++) {
j = i + i;
range.left = &nums[j];
range.right = &nums[j+1];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
}
/* Decrease lots of ranges */
for (i = 0; i < 512; i++) {
j = i + i;
range.left = &nums[j];
range.right = &nums[j+1];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
}
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
/* Force malloc to fail */
/* Failure when allocating the tree */
malloc_cnt = 0;
malloc_cntl = 1;
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, malloc_fail, free,
realloc);
CKERR2(r, ENOMEM);
/* Failure when allocating the tree ranges */
malloc_cnt = 0;
malloc_cntl = 2;
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE, malloc_fail, free,
realloc);
CKERR2(r, ENOMEM);
return 0;
}
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