From 7378edffa5751159d35eab31eceb76a1f16231d0 Mon Sep 17 00:00:00 2001 From: jdybnis Date: Mon, 1 Dec 2008 03:54:52 +0000 Subject: [PATCH] add to txn test --- include/txn.h | 2 +- test/txn_test.c | 16 +++++++++++----- txn/txn.c | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/txn.h b/include/txn.h index 51db400..b2d6a10 100644 --- a/include/txn.h +++ b/include/txn.h @@ -13,7 +13,7 @@ typedef enum { TXN_RUNNING, TXN_VALIDATING, TXN_VALIDATED, TXN_ABORTED } txn_sta typedef struct txn txn_t; -txn_t * txn_begin (txn_access_e access, txn_isolation_e isolation, map_type_t map_type); +txn_t * txn_begin (txn_access_e access, txn_isolation_e isolation, map_t *map); void txn_abort (txn_t *txn); txn_state_e txn_commit (txn_t *txn); diff --git a/test/txn_test.c b/test/txn_test.c index e20027e..6e9044f 100644 --- a/test/txn_test.c +++ b/test/txn_test.c @@ -8,11 +8,17 @@ #define ASSERT_EQUAL(x, y) CuAssertIntEquals(tc, x, y) void test1 (CuTest* tc) { - txn_t *tm = txn_begin(TXN_READ_WRITE, TXN_REPEATABLE_READ, MAP_TYPE_LIST); - tm_set(tm, "abc", 4, 2); - tm_set(tm, "abc", 4, 3); - ASSERT_EQUAL( 3, tm_get(tm, "abc", 4) ); - ASSERT_EQUAL( TXN_VALIDATED, txn_commit(tm)); + map_t *map = map_alloc(MAP_TYPE_LIST); + txn_t *t1 = txn_begin(TXN_READ_WRITE, TXN_REPEATABLE_READ, map); + txn_t *t2 = txn_begin(TXN_READ_WRITE, TXN_REPEATABLE_READ, map); + tm_set(t1, "abc", 4, 2); + tm_set(t1, "abc", 4, 3); + ASSERT_EQUAL( DOES_NOT_EXIST, tm_get(t2, "abc", 4) ); + tm_set(t2, "abc", 4, 4); + ASSERT_EQUAL( 3, tm_get(t1, "abc", 4) ); + ASSERT_EQUAL( 4, tm_get(t2, "abc", 4) ); + ASSERT_EQUAL( TXN_VALIDATED, txn_commit(t2)); + ASSERT_EQUAL( TXN_ABORTED, txn_commit(t1)); } int main (void) { diff --git a/txn/txn.c b/txn/txn.c index 1073f7b..5275882 100644 --- a/txn/txn.c +++ b/txn/txn.c @@ -130,7 +130,7 @@ static update_rec_t *alloc_update_rec (void) { return u; } -txn_t *txn_begin (txn_access_e access, txn_isolation_e isolation, map_type_t map_type) { +txn_t *txn_begin (txn_access_e access, txn_isolation_e isolation, map_t *map) { txn_t *txn = (txn_t *)nbd_malloc(sizeof(txn_t)); memset(txn, 0, sizeof(txn_t)); txn->access = access; @@ -138,7 +138,7 @@ txn_t *txn_begin (txn_access_e access, txn_isolation_e isolation, map_type_t map txn->rv = version_; txn->wv = UNDETERMINED_VERSION; txn->state = TXN_RUNNING; - txn->map = map_alloc(map_type); + txn->map = map; if (isolation != TXN_READ_ONLY) { txn->writes = nbd_malloc(sizeof(*txn->writes) * INITIAL_WRITES_SIZE); txn->writes_size = INITIAL_WRITES_SIZE; -- 2.40.0