/* test.c */ #include "test.h" #include "mongo.h" #include #include #include #ifndef _WIN32 #include #endif /* supports preprocessor concatenation */ #define DB "benchmarks" /* finds without indexes */ #define DO_SLOW_TESTS 1 #ifndef TEST_SERVER #define TEST_SERVER "127.0.0.1" #endif #define PER_TRIAL 5000 #define BATCH_SIZE 100 static mongo conn[1]; static void make_small( bson *out, int i ) { bson_init( out ); bson_append_new_oid( out, "_id" ); bson_append_int( out, "x", i ); bson_finish( out ); } static void make_medium( bson *out, int i ) { bson_init( out ); bson_append_new_oid( out, "_id" ); bson_append_int( out, "x", i ); bson_append_int( out, "integer", 5 ); bson_append_double( out, "number", 5.05 ); bson_append_bool( out, "boolean", 0 ); bson_append_start_array( out, "array" ); bson_append_string( out, "0", "test" ); bson_append_string( out, "1", "benchmark" ); bson_append_finish_object( out ); bson_finish( out ); } static const char *words[14] = { "10gen","web","open","source","application","paas", "platform-as-a-service","technology","helps", "developers","focus","building","mongodb","mongo" }; static void make_large( bson *out, int i ) { int num; char numstr[4]; bson_init( out ); bson_append_new_oid( out, "_id" ); bson_append_int( out, "x", i ); bson_append_string( out, "base_url", "http://www.example.com/test-me" ); bson_append_int( out, "total_word_count", 6743 ); bson_append_int( out, "access_time", 999 ); /*TODO use date*/ bson_append_start_object( out, "meta_tags" ); bson_append_string( out, "description", "i am a long description string" ); bson_append_string( out, "author", "Holly Man" ); bson_append_string( out, "dynamically_created_meta_tag", "who know\n what" ); bson_append_finish_object( out ); bson_append_start_object( out, "page_structure" ); bson_append_int( out, "counted_tags", 3450 ); bson_append_int( out, "no_of_js_attached", 10 ); bson_append_int( out, "no_of_images", 6 ); bson_append_finish_object( out ); bson_append_start_array( out, "harvested_words" ); for ( num=0; num < 14*20; num++ ) { bson_numstr( numstr, num ); bson_append_string( out, numstr, words[num%14] ); } bson_append_finish_object( out ); bson_finish( out ); } static void serialize_small_test( void ) { int i; bson b; for ( i=0; i