void test_batch_insert_with_continue( mongo *conn ) { bson *objs[5]; bson *objs2[5]; bson empty; int i; mongo_cmd_drop_collection( conn, TEST_DB, TEST_COL, NULL ); mongo_create_simple_index( conn, TEST_NS, "n", MONGO_INDEX_UNIQUE, NULL ); for( i=0; i<5; i++ ) { objs[i] = bson_malloc( sizeof( bson ) ); bson_init( objs[i] ); bson_append_int( objs[i], "n", i ); bson_finish( objs[i] ); } ASSERT( mongo_insert_batch( conn, TEST_NS, (const bson **)objs, 5, NULL, 0 ) == MONGO_OK ); ASSERT( mongo_count( conn, TEST_DB, TEST_COL, bson_empty( &empty ) ) == 5 ); /* Add one duplicate value for n. */ objs2[0] = bson_malloc( sizeof( bson ) ); bson_init( objs2[0] ); bson_append_int( objs2[0], "n", 1 ); bson_finish( objs2[0] ); /* Add n for 6 - 9. */ for( i = 1; i < 5; i++ ) { objs2[i] = bson_malloc( sizeof( bson ) ); bson_init( objs2[i] ); bson_append_int( objs2[i], "n", i + 5 ); bson_finish( objs2[i] ); } /* Without continue on error, will fail immediately. */ ASSERT( mongo_insert_batch( conn, TEST_NS, (const bson **)objs2, 5, NULL, 0 ) == MONGO_OK ); ASSERT( mongo_count( conn, TEST_DB, TEST_COL, bson_empty( &empty ) ) == 5 ); /* With continue on error, will insert four documents. */ ASSERT( mongo_insert_batch( conn, TEST_NS, (const bson **)objs2, 5, NULL, MONGO_CONTINUE_ON_ERROR ) == MONGO_OK ); ASSERT( mongo_count( conn, TEST_DB, TEST_COL, bson_empty( &empty ) ) == 9 ); for( i=0; i<5; i++ ) { bson_destroy( objs2[i] ); bson_free( objs2[i] ); bson_destroy( objs[i] ); bson_free( objs[i] ); } }
static void index_insert_large_test( void ) { int i; bson b; ASSERT( mongo_create_simple_index( conn, DB ".index.large", "x", 0, NULL ) == MONGO_OK ); for ( i=0; i<PER_TRIAL; i++ ) { make_large( &b, i ); mongo_insert( conn, DB ".index.large", &b, NULL ); bson_destroy( &b ); } }
static void index_insert_medium_test(){ int i; bson b; ASSERT(mongo_create_simple_index(conn, DB ".index.medium", "x", 0, NULL)); for (i=0; i<PER_TRIAL; i++){ make_medium(&b, i); mongo_insert(conn, DB ".index.medium", &b); bson_destroy(&b); } }