2008-05-13 12:17:05 +00:00
/* -*- mode: C; c-basic-offset: 4 -*- */
2013-04-16 23:59:44 -04:00
# ident "$Id$"
2008-05-13 12:17:05 +00:00
# ident "Copyright (c) 2008 Tokutek Inc. All rights reserved."
2013-04-16 23:57:21 -04:00
# include "includes.h"
2008-05-13 12:17:05 +00:00
# include "test.h"
# include <unistd.h>
static TOKUTXN const null_txn = 0 ;
static DB * const null_db = 0 ;
static void test_flat ( void ) {
char fname [ ] = __FILE__ " .brt " ;
u_int64_t limit = 30000 ;
2013-04-16 23:57:47 -04:00
unlink ( fname ) ;
2008-05-13 12:17:05 +00:00
CACHETABLE ct ;
int r = toku_brt_create_cachetable ( & ct , 0 , ZERO_LSN , NULL_LOGGER ) ; assert ( r = = 0 ) ;
BRT t ;
2013-04-16 23:59:44 -04:00
r = toku_open_brt ( fname , 1 , & t , 1 < < 12 , 1 < < 9 , ct , null_txn , toku_builtin_compare_fun , null_db ) ; assert ( r = = 0 ) ;
2008-05-13 12:17:05 +00:00
u_int64_t i ;
for ( i = 0 ; i < limit ; i + + ) {
char key [ 100 ] , val [ 100 ] ;
snprintf ( key , 100 , " %08llu " , ( unsigned long long ) 2 * i + 1 ) ;
snprintf ( val , 100 , " %08llu " , ( unsigned long long ) 2 * i + 1 ) ;
DBT k , v ;
r = toku_brt_insert ( t , toku_fill_dbt ( & k , key , 1 + strlen ( key ) ) , toku_fill_dbt ( & v , val , 1 + strlen ( val ) ) , null_txn ) ;
assert ( r = = 0 ) ;
}
// flatten it.
for ( i = 0 ; i < limit ; i + + ) {
char key [ 100 ] ;
snprintf ( key , 100 , " %08llu " , ( unsigned long long ) 2 * i + 1 ) ;
2013-04-16 23:57:41 -04:00
DBT k ;
struct check_pair pair = { 1 + strlen ( key ) , key , 1 + strlen ( key ) , key , 0 } ;
2013-04-16 23:59:21 -04:00
r = toku_brt_lookup ( t , toku_fill_dbt ( & k , key , 1 + strlen ( key ) ) , lookup_checkf , & pair ) ;
2008-05-13 12:17:05 +00:00
assert ( r = = 0 ) ;
2013-04-16 23:57:41 -04:00
assert ( pair . call_count = = 1 ) ;
2008-05-13 12:17:05 +00:00
}
for ( i = 0 ; i < limit ; i + + ) {
char key [ 100 ] ;
snprintf ( key , 100 , " %08llu " , ( unsigned long long ) 2 * i + 1 ) ;
DBT k ;
u_int64_t less , equal , greater ;
r = toku_brt_keyrange ( t , toku_fill_dbt ( & k , key , 1 + strlen ( key ) ) , & less , & equal , & greater ) ;
assert ( r = = 0 ) ;
//printf("key %llu/%llu %llu %llu %llu\n", (unsigned long long)2*i, (unsigned long long)2*limit, (unsigned long long)less, (unsigned long long)equal, (unsigned long long)greater);
assert ( less = = ( u_int64_t ) i ) ;
assert ( equal = = 1 ) ;
assert ( less + equal + greater = = limit ) ;
}
for ( i = 0 ; i < 1 + limit ; i + + ) {
char key [ 100 ] ;
snprintf ( key , 100 , " %08llu " , ( unsigned long long ) 2 * i ) ;
DBT k ;
u_int64_t less , equal , greater ;
r = toku_brt_keyrange ( t , toku_fill_dbt ( & k , key , 1 + strlen ( key ) ) , & less , & equal , & greater ) ;
assert ( r = = 0 ) ;
//printf("key %llu/%llu %llu %llu %llu\n", (unsigned long long)2*i, (unsigned long long)2*limit, (unsigned long long)less, (unsigned long long)equal, (unsigned long long)greater);
assert ( less = = ( u_int64_t ) i ) ;
assert ( equal = = 0 ) ;
assert ( less + equal + greater = = limit ) ;
}
2013-04-16 23:58:06 -04:00
r = toku_close_brt ( t , 0 ) ; assert ( r = = 0 ) ;
2008-05-13 12:17:05 +00:00
r = toku_cachetable_close ( & ct ) ; assert ( r = = 0 ) ;
}
2013-04-16 23:57:32 -04:00
int
test_main ( int argc , const char * argv [ ] ) {
2008-05-13 12:17:05 +00:00
default_parse_args ( argc , argv ) ;
test_flat ( ) ;
2013-04-16 23:59:22 -04:00
2008-05-13 12:17:05 +00:00
if ( verbose ) printf ( " test ok \n " ) ;
return 0 ;
}