void testDBOptions() { EJCOLLOPTS opts; opts.cachedrecords = 10000; opts.compressed = true; opts.large = true; opts.records = 110000; EJCOLL *coll = ejdbcreatecoll(jb, "optscoll", &opts); CU_ASSERT_PTR_NOT_NULL_FATAL(coll); TCHDB *hdb = coll->tdb->hdb; CU_ASSERT_TRUE(hdb->bnum >= (opts.records * 2 + 1)); CU_ASSERT_EQUAL(hdb->rcnum, opts.cachedrecords); CU_ASSERT_TRUE(hdb->opts & HDBTDEFLATE); CU_ASSERT_TRUE(hdb->opts & HDBTLARGE); CU_ASSERT_TRUE(ejdbrmcoll(jb, "optscoll", true)); }
/* * Class: org_ejdb_driver_EJDBCollection * Method: drop * Signature: (Z)V */ JNIEXPORT void JNICALL Java_org_ejdb_driver_EJDBCollection_drop (JNIEnv *env, jobject obj, jboolean prune) { EJDB* db = get_ejdb_from_object(env, obj); if (!ejdbisopen(db)) { set_error(env, 0, "EJDB not opened"); return; } jstring colname = get_coll_name(env, obj); const char *cname = (*env)->GetStringUTFChars(env, colname, NULL); bool status = ejdbrmcoll(db, cname, (prune == JNI_TRUE)); (*env)->ReleaseStringUTFChars(env, colname, cname); if (!status) { set_ejdb_error(env, db); return; } update_coll_meta(env, obj, NULL); };
void testRace2() { CU_ASSERT_PTR_NOT_NULL_FATAL(jb); bool err = false; TARGRACE targs[tnum]; pthread_t threads[tnum]; ejdbrmcoll(jb, "threadrace1", true); EJCOLL *coll = ejdbcreatecoll(jb, "threadrace1", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(coll); if (!ejdbsetindex(coll, "tid", JBIDXDROPALL)) { //NO INDEX eprint(jb, __LINE__, "testRace2"); err = true; } if (err) { goto finish; } for (int i = 0; i < tnum; i++) { targs[i].jb = jb; targs[i].id = i; if (pthread_create(threads + i, NULL, threadrace1, targs + i) != 0) { eprint(jb, __LINE__, "pthread_create"); targs[i].id = -1; err = true; } } for (int i = 0; i < tnum; i++) { if (targs[i].id == -1) continue; void *rv; if (pthread_join(threads[i], &rv) != 0) { eprint(jb, __LINE__, "pthread_join"); err = true; } else if (rv) { err = true; } } finish: CU_ASSERT_FALSE(err); }
int clean_suite(void) { ejdbrmcoll(jb, "contacts", true); ejdbclose(jb); ejdbdel(jb); return 0; }
void testPerf1() { CU_ASSERT_PTR_NOT_NULL_FATAL(jb); CU_ASSERT_PTR_NOT_NULL_FATAL(recs); EJCOLL *coll = ejdbcreatecoll(jb, "pcoll1", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(coll); unsigned long st = tcmstime(); for (int i = 0; i < RS; ++i) { bson_oid_t oid; ejdbsavebson(coll, recs + i, &oid); } ejdbsyncoll(coll); fprintf(stderr, "\ntestPerf1(): SAVED %d BSON OBJECTS, TIME %lu ms\n", RS, tcmstime() - st); st = tcmstime(); uint32_t acount = 0; int i; for (i = 0; i < QRS; ++i) { int idx = rand() % QRS; bson *bs = recs + idx; assert(bs); EJQ *q = ejdbcreatequery(jb, bs, NULL, 0, NULL); assert(q); uint32_t count; ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); assert(count); if (count != 1) { fprintf(stderr, "CNT=%u\n", count); } acount += count; ejdbquerydel(q); } CU_ASSERT_TRUE(i <= acount); fprintf(stderr, "testPerf1(): %u QUERIES, TIME: %lu ms, PER QUERY TIME: %lu ms\n", i, tcmstime() - st, (unsigned long) ((tcmstime() - st) / QRS)); st = tcmstime(); CU_ASSERT_TRUE(ejdbsetindex(coll, "rstring", JBIDXSTR)); fprintf(stderr, "testPerf1(): SET INDEX 'rstring' TIME: %lu ms\n", tcmstime() - st); st = tcmstime(); acount = 0; for (i = 0; i < QRS; ++i) { int idx = rand() % QRS; bson *bs = recs + idx; assert(bs); EJQ *q = ejdbcreatequery(jb, bs, NULL, 0, NULL); assert(q); uint32_t count; ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); assert(count); acount += count; ejdbquerydel(q); } CU_ASSERT_TRUE(i <= acount); fprintf(stderr, "testPerf1(): %u QUERIES WITH 'rstring' INDEX, TIME: %lu ms, PER QUERY TIME: %lu ms\n", i, tcmstime() - st, (unsigned long) ((tcmstime() - st) / QRS)); bson bsq1; bson_init_as_query(&bsq1); bson_append_start_object(&bsq1, "$set"); bson_append_int(&bsq1, "intv", 1); bson_append_finish_object(&bsq1); bson_finish(&bsq1); EJQ *q = ejdbcreatequery(jb, &bsq1, NULL, JBQRYCOUNT, NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(q); uint32_t count; st = tcmstime(); //$set op ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); if (ejdbecode(jb) != 0) { eprint(jb, __LINE__, "$set test"); CU_ASSERT_TRUE(false); } CU_ASSERT_EQUAL(count, RS); fprintf(stderr, "testPerf1(): {'$set' : {'intv' : 1}} FOR %u OBJECTS, TIME %lu ms\n", count, tcmstime() - st); ejdbquerydel(q); bson_destroy(&bsq1); bson_init_as_query(&bsq1); bson_append_start_object(&bsq1, "$inc"); bson_append_int(&bsq1, "intv", 1); bson_append_finish_object(&bsq1); bson_finish(&bsq1); q = ejdbcreatequery(jb, &bsq1, NULL, JBQRYCOUNT, NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(q); st = tcmstime(); //$inc op ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); if (ejdbecode(jb) != 0) { eprint(jb, __LINE__, "$inc test"); CU_ASSERT_TRUE(false); } CU_ASSERT_EQUAL(count, RS); fprintf(stderr, "testPerf1(): {'$inc' : {'intv' : 1}} FOR %u OBJECTS, TIME %lu ms\n", count, tcmstime() - st); ejdbquerydel(q); bson_destroy(&bsq1); bson_init_as_query(&bsq1); bson_append_int(&bsq1, "intv", 2); bson_finish(&bsq1); q = ejdbcreatequery(jb, &bsq1, NULL, JBQRYCOUNT, NULL); ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); CU_ASSERT_EQUAL(count, RS); ejdbquerydel(q); bson_destroy(&bsq1); ejdbrmcoll(jb, coll->cname, true); }