-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_simple.c
More file actions
83 lines (61 loc) · 1.79 KB
/
test_simple.c
File metadata and controls
83 lines (61 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "test_core.h"
static char *get_file_arg(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "usage: test-simple TEST-DB\n");
exit(1);
}
char *file = argv[1];
if (file_exists(file)) {
fprintf(stderr, "%s exists\n", file);
exit(1);
}
return file;
}
#define num_epochs 10
#define slot_seconds 60
#define num_keys 10001
int main(int argc, char *argv[]) {
char *file = get_file_arg(argc, argv);
tsdb_handler db;
int ret;
int cur, start, stop;
char key[255];
uint i;
uint write_val;
uint *read_val;
set_trace_level(1);
// Open (create) a new db.
u_int16_t vals_per_entry = 1;
ret = tsdb_open(file, &db, &vals_per_entry, slot_seconds, 0);
assert_int_equal(0, ret);
// Move through epochs for write.
start = 1000000000;
stop = start + (num_epochs - 1) * slot_seconds;
for (cur = start; cur <= stop; cur += slot_seconds) {
ret = tsdb_goto_epoch(&db, cur, 0, 1);
assert_int_equal(0, ret);
// Write keys.
for (i = 1; i <= num_keys; i++) {
sprintf(key, "key-%i", i);
write_val = i * 1000;
ret = tsdb_set(&db, key, &write_val);
assert_int_equal(0, ret);
}
}
tsdb_flush(&db);
// Move through epochs for reads.
for (cur = start; cur <= stop; cur += slot_seconds) {
ret = tsdb_goto_epoch(&db, cur, 1, 0);
assert_int_equal(0, ret);
// Read keys.
for (i = 1; i <= num_keys; i++) {
sprintf(key, "key-%i", i);
ret = tsdb_get_by_key(&db, key, &read_val);
assert_int_equal(0, ret);
write_val = i * 1000;
assert_int_equal(write_val, *read_val);
}
}
tsdb_close(&db);
return 0;
}