]> pd.if.org Git - nbds/blob - test/txn_test.c
all structures now support arbitrary type keys with a fast path for integers
[nbds] / test / txn_test.c
1 #include <stdio.h>
2 #include "CuTest.h"
3
4 #include "common.h"
5 #include "runtime.h"
6 #include "txn.h"
7
8 #define ASSERT_EQUAL(x, y) CuAssertIntEquals(tc, x, y)
9
10 void test1 (CuTest* tc) {
11     map_t *map = map_alloc(MAP_TYPE_LIST, NULL, NULL, NULL);
12     txn_t *t1 = txn_begin(TXN_READ_WRITE, TXN_REPEATABLE_READ, map);
13     txn_t *t2 = txn_begin(TXN_READ_WRITE, TXN_REPEATABLE_READ, map);
14     tm_set(t1, "abc", 2);
15     tm_set(t1, "abc", 3);
16     ASSERT_EQUAL( DOES_NOT_EXIST, tm_get(t2, "abc") );
17     tm_set(t2, "abc", 4);
18     ASSERT_EQUAL( 3, tm_get(t1, "abc") );
19     ASSERT_EQUAL( 4, tm_get(t2, "abc") );
20     ASSERT_EQUAL( TXN_VALIDATED, txn_commit(t2));
21     ASSERT_EQUAL( TXN_ABORTED, txn_commit(t1));
22 }
23
24 int main (void) {
25
26     nbd_init();
27
28     CuString *output = CuStringNew();
29     CuSuite* suite = CuSuiteNew();
30     SUITE_ADD_TEST(suite, test1);
31     CuSuiteRun(suite);
32     CuSuiteDetails(suite, output);
33     printf("%s\n", output->buffer);
34
35     return 0;
36 }
37