Commit 6d1c8625 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #288

Fixes bugs in tests where find parameters did not have data == NULL

git-svn-id: file:///svn/tokudb@1770 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0ac037f2
......@@ -87,30 +87,30 @@ void tests(BOOL allow_overlaps) {
runinsert(0, init_range(&insert, 6, 7, 0));
runinsert(0, init_range(&insert, 8, 9, 0));
runlimitsearch(init_range(&query, 2, 7, 0), 0, 3);
runlimitsearch(init_range(&query, 2, 7, 0), 1, 1);
runlimitsearch(init_range(&query, 2, 7, 0), 2, 2);
runlimitsearch(init_range(&query, 2, 7, 0), 3, 3);
runlimitsearch(init_range(&query, 2, 7, 0), 4, 3);
runlimitsearch(init_range(&query, 2, 7, -1), 0, 3);
runlimitsearch(init_range(&query, 2, 7, -1), 1, 1);
runlimitsearch(init_range(&query, 2, 7, -1), 2, 2);
runlimitsearch(init_range(&query, 2, 7, -1), 3, 3);
runlimitsearch(init_range(&query, 2, 7, -1), 4, 3);
close_tree();
/* Tree is empty (return none) */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runlimitsearch(init_range(&query, 0, 0, 0), 0, 0);
runlimitsearch(init_range(&query, 0, 0, -1), 0, 0);
close_tree();
/* Tree contains only elements to the left. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 1, 2, 0));
runinsert(0, init_range(&insert, 3, 4, 0));
runlimitsearch(init_range(&query, 8, 30, 0), 0, 0);
runlimitsearch(init_range(&query, 8, 30, -1), 0, 0);
close_tree();
/* Tree contains only elements to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runlimitsearch(init_range(&query, 5, 7, 0), 0, 0);
runlimitsearch(init_range(&query, 5, 7, -1), 0, 0);
close_tree();
/* Tree contains only elements to the left and to the right. */
......@@ -119,7 +119,7 @@ void tests(BOOL allow_overlaps) {
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 70, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 60, 65, 0), 0, 0);
runlimitsearch(init_range(&query, 60, 65, -1), 0, 0);
close_tree();
/* Tree contains overlaps and elements to the left. */
......@@ -128,7 +128,7 @@ void tests(BOOL allow_overlaps) {
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
runlimitsearch(init_range(&query, 70, 95, -1), 0, 2);
close_tree();
/* Tree contains overlaps and elements to the right. */
......@@ -137,7 +137,7 @@ void tests(BOOL allow_overlaps) {
runinsert(0, init_range(&insert, 130, 140, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
runlimitsearch(init_range(&query, 70, 95, -1), 0, 2);
close_tree();
/* Tree contains overlaps and elements to the left and to the right. */
......@@ -148,7 +148,7 @@ void tests(BOOL allow_overlaps) {
runinsert(0, init_range(&insert, 130, 140, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
runlimitsearch(init_range(&query, 70, 95, -1), 0, 2);
close_tree();
}
......
......@@ -73,22 +73,22 @@ void tests(BOOL allow_overlaps) {
/* Tree: {|0-1|}, query of |1-2| returns |0-1| */
setup_tree(allow_overlaps, 0, 1, 0);
runsearch(0, init_range(&query, 1, 2, 0), init_range(&expect, 0, 1, 0));
runsearch(0, init_range(&query, 1, 2, -1), init_range(&expect, 0, 1, 0));
close_tree();
/* Tree: {|1-2|}, query of |0-1| returns |1-2| */
setup_tree(allow_overlaps, 1, 2, 0);
runsearch(0, init_range(&query, 0, 1, 0), init_range(&expect, 1, 2, 0));
runsearch(0, init_range(&query, 0, 1, -1), init_range(&expect, 1, 2, 0));
close_tree();
/* Tree: {|1-2|}, insert of of |0-1| success == allow_overlaps */
setup_tree(allow_overlaps, 1, 2, 0);
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 0, 1, 0));
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 0, 1, -1));
close_tree();
/* Tree: {|0-1|}, insert of of |1-2| success == allow_overlaps */
setup_tree(allow_overlaps, 0, 1, 0);
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 1, 2, 0));
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 1, 2, -1));
close_tree();
/*
......@@ -102,22 +102,22 @@ void tests(BOOL allow_overlaps) {
/* Tree: {|0-3|}, query of |1-2| returns |0-3| */
setup_tree(allow_overlaps, 0, 3, 0);
runsearch(0, init_range(&query, 1, 2, 0), init_range(&expect, 0, 3, 0));
runsearch(0, init_range(&query, 1, 2, -1), init_range(&expect, 0, 3, 0));
close_tree();
/* Tree: {|1-2|}, query of |0-3| returns |1-2| */
setup_tree(allow_overlaps, 1, 2, 0);
runsearch(0, init_range(&query, 0, 3, 0), init_range(&expect, 1, 2, 0));
runsearch(0, init_range(&query, 0, 3, -1), init_range(&expect, 1, 2, 0));
close_tree();
/* Tree: {|1-2|}, insert of of |0-3| success == allow_overlaps */
setup_tree(allow_overlaps, 1, 2, 0);
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 0, 3, 0));
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 0, 3, -1));
close_tree();
/* Tree: {|0-3|}, insert of of |1-2| success == allow_overlaps */
setup_tree(allow_overlaps, 0, 3, 0);
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 1, 2, 0));
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 1, 2, -1));
close_tree();
/*
......@@ -129,12 +129,12 @@ void tests(BOOL allow_overlaps) {
/* Tree: {|0-3|}, query of |0-3| returns |0-3| */
setup_tree(allow_overlaps, 0, 3, 0);
runsearch(0, init_range(&query, 0, 3, 0), init_range(&expect, 0, 3, 0));
runsearch(0, init_range(&query, 0, 3, -1), init_range(&expect, 0, 3, 0));
close_tree();
/* Tree: {|0-3|}, insert of of |0-3| success == allow_overlaps */
setup_tree(allow_overlaps, 0, 3, 0);
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 0, 3, 0));
runinsert((allow_overlaps ? 0 : EDOM), init_range(&query, 0, 3, -1));
close_tree();
}
......
/* We are going to test whether we can insert and delete. */
#include "test.h"
int main(int argc, const char *argv[]) {
int r;
toku_range_tree *tree;
toku_range range;
toku_range find_range;
int nums[8] = {0,1,2,3,4,5,6,7};
char letters[2] = {'A','B'};
unsigned found;
toku_range* buf = (toku_range*)toku_malloc(2*sizeof(toku_range));
unsigned bufsize = 2;
void verify_all_overlap(toku_range* query, toku_range* list, unsigned listlen) {
unsigned i;
parse_args(argc, argv);
for (i = 0; i < listlen; i++) {
/* Range A and B overlap iff A.left <= B.right && B.left <= A.right */
assert(int_cmp(query->left, list[i].right) <= 0 &&
int_cmp(list[i].left, query->right) <= 0);
}
}
find_range.left = &nums[4];
find_range.right = &nums[4];
find_range.data = NULL;
int nums[200];
char letters[2] = {'A','B'};
/* Test no overlap case. */
/* Test overlap case */
/*
1 2 3 4 5 6 7
|---A---|
|---B---|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE);
CKERR(r);
toku_range_tree *tree;
toku_range* buf;
unsigned buflen;
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize >= 4);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
toku_range* init_range(toku_range* range, int left, int right, int data) {
range->left = &nums[left];
range->right = &nums[right];
if (data < 0) range->data = NULL;
else range->data = &letters[data];
return range;
}
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
void setup_tree(BOOL allow_overlaps, BOOL insert, int left, int right, int data) {
int r;
toku_range range;
r = toku_rt_create(&tree, int_cmp, char_cmp, allow_overlaps); CKERR(r);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
if (insert) {
r = toku_rt_insert(tree, init_range(&range, left, right, data));
CKERR(r);
}
}
void close_tree(void) {
int r;
r = toku_rt_close(tree); CKERR(r);
}
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize >= 4);
void runsearch(int rexpect, toku_range* query, toku_range* expect) {
int r;
unsigned found;
r = toku_rt_find(tree, query, 0, &buf, &buflen, &found);
CKERR2(r, rexpect);
if (rexpect != 0) return;
assert(found == 1);
assert(int_cmp(&buf[0].left, expect->left) == 0 &&
int_cmp(&buf[0].right, expect->right) == 0 &&
char_cmp(&buf[0].data, expect->data) == 0);
}
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
void runinsert(int rexpect, toku_range* toinsert) {
int r;
r = toku_rt_insert(tree, toinsert);
CKERR2(r, rexpect);
}
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
assert(*(int*)buf[0].left == 1 &&
*(int*)buf[0].right == 3 &&
*(char*)buf[0].data == letters[0]);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize >= 4);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
assert(*(int*)buf[0].left == 4 &&
*(int*)buf[0].right == 6 &&
*(char*)buf[0].data == letters[1]);
void runlimitsearch(toku_range* query, unsigned limit, unsigned findexpect) {
int r;
unsigned found;
r=toku_rt_find(tree, query, limit, &buf, &buflen, &found); CKERR(r);
verify_all_overlap(query, buf, found);
assert(found == findexpect);
}
/* Clean up. */
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
void tests(BOOL allow_overlaps) {
toku_range query;
toku_range insert;
/*
Limited/Unlimited Queries
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize >= 4);
Limit of k does not produce all, but limit of 0 does. Single point overlaps
*/
/* Done */
/* Tree: {|0-1|,|2-3|,|4-5|,|6-7|,|8-9|}, query of |2-7|, limit 2 finds 2,
limit 3 finds 3, limit 4 finds 3, limit 0 finds 3 */
setup_tree(allow_overlaps, TRUE, 0, 1, 0);
runinsert(0, init_range(&insert, 2, 3, 0));
runinsert(0, init_range(&insert, 4, 5, 0));
runinsert(0, init_range(&insert, 6, 7, 0));
runinsert(0, init_range(&insert, 8, 9, 0));
runlimitsearch(init_range(&query, 2, 7, 0), 0, 3);
runlimitsearch(init_range(&query, 2, 7, 0), 1, 1);
runlimitsearch(init_range(&query, 2, 7, 0), 2, 2);
runlimitsearch(init_range(&query, 2, 7, 0), 3, 3);
runlimitsearch(init_range(&query, 2, 7, 0), 4, 3);
close_tree();
/* Tree is empty (return none) */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runlimitsearch(init_range(&query, 0, 0, 0), 0, 0);
close_tree();
/* Tree contains only elements to the left. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 1, 2, 0));
runinsert(0, init_range(&insert, 3, 4, 0));
runlimitsearch(init_range(&query, 8, 30, 0), 0, 0);
close_tree();
/* Tree contains only elements to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runlimitsearch(init_range(&query, 5, 7, 0), 0, 0);
close_tree();
/* Tree contains only elements to the left and to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 70, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 60, 65, 0), 0, 0);
close_tree();
/* Tree contains overlaps and elements to the left. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
close_tree();
/* Tree contains overlaps and elements to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 110, 120, 0));
runinsert(0, init_range(&insert, 130, 140, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
close_tree();
/* Tree contains overlaps and elements to the left and to the right. */
setup_tree(allow_overlaps, FALSE, 0, 0, 0);
runinsert(0, init_range(&insert, 10, 20, 0));
runinsert(0, init_range(&insert, 30, 40, 0));
runinsert(0, init_range(&insert, 110, 120, 0));
runinsert(0, init_range(&insert, 130, 140, 0));
runinsert(0, init_range(&insert, 60, 80, 0));
runinsert(0, init_range(&insert, 90, 100, 0));
runlimitsearch(init_range(&query, 70, 95, 0), 0, 2);
close_tree();
}
r = toku_rt_close(tree); CKERR(r);
int main(int argc, const char *argv[]) {
int i;
for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) nums[i] = i;
buflen = 2;
buf = (toku_range*)toku_malloc(2 * sizeof(toku_range));
tests(FALSE);
tests(TRUE);
tree = NULL;
toku_free(buf);
buf = NULL;
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