static void mt_async_read(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 5) == 0 ); t( sp_setint(env, "compaction.0.async", 1) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setstring(env, "db.test.format", "kv", 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int i = 0; while (i < 100000) { void *o = sp_object(db); assert(o != NULL); sp_setstring(o, "key", &i, sizeof(i)); int rc = sp_set(db, o); t( rc == 0 ); print_current(i); i++; } fprintf(st_r.output, " (insert done..iterate) "); void *async = sp_asynchronous(db); t( async != NULL ); /* trigger iteration */ void *o = sp_object(async); sp_setstring(o, "order", ">=", 0); o = sp_get(db, o); t( o != NULL ); sp_destroy(o); i = 0; while (i < 100000) { o = sp_poll(env); if (o == NULL) continue; t( strcmp(sp_getstring(o, "type", 0), "on_read") == 0 ); t( sp_getint(o, "status") == 1 ); t( *(int*)sp_getstring(o, "key", NULL) == i ); o = sp_get(db, o); t( o != NULL ); sp_destroy(o); print_current(i); i++; } t( i == 100000 ); fprintf(st_r.output, "(complete)"); t( sp_destroy(env) == 0 ); }
static void backup_test1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "backup.path", st_r.conf->backup_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); t( sp_setstring(env, "scheduler.on_event", on_event, 0) == 0 ); t( sp_setint(env, "scheduler.event_on_backup", 1) == 0 ); t( sp_open(env) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); int i = 0; while ( i < 100 ) { void *o = sp_object(db); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &i, sizeof(i)) == 0 ); t( sp_set(db, o) == 0 ); i++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "scheduler.checkpoint", 0) == 0 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_getint(env, "backup.active") == 0 ); t( sp_setint(env, "backup.run", 0) == 0 ); /* state 0 */ t( sp_getint(env, "backup.active") == 1 ); /* state 1 + 2 */ t( sp_setint(env, "scheduler.run", 0) == 1 ); /* index backup completion */ t( sp_setint(env, "scheduler.run", 0) == 1 ); /* state 3 + branch */ t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_setint(env, "scheduler.run", 0) == 0 ); t( trigger_called == 1 ); t( sp_getint(env, "backup.active") == 0 ); t( sp_getint(env, "backup.last") == 1 ); t( sp_getint(env, "backup.last_complete") == 1 ); void *o = sp_poll(env); t( o != NULL ); t( sp_destroy(o) == 0 ); t( sp_poll(env) == NULL ); t( sp_destroy(env) == 0 ); /* recover backup */ char path[1024]; snprintf(path, sizeof(path), "%s/1", st_r.conf->backup_dir); env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", path, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "backup.path", st_r.conf->backup_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); o = sp_object(db); t( o != NULL ); void *cur = sp_cursor(env); t( cur != NULL ); i = 0; while ((o = sp_get(cur, o))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); i++; } t( i == 100 ); t( sp_destroy(cur) == 0 ); t( sp_destroy(env) == 0 ); }