From f92dd279a1e26dad7507d5d6944567c23834d440 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 27 May 2010 09:45:12 +0000 Subject: A lot of session handling. A lot of new unit tests. Add of a more structured commit/discard handling. Fix of some wierd line break bugs in journalwriter --- server/src/connectionpool.cc | 69 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to 'server/src/connectionpool.cc') diff --git a/server/src/connectionpool.cc b/server/src/connectionpool.cc index 07e6aa2..e2b6bfc 100644 --- a/server/src/connectionpool.cc +++ b/server/src/connectionpool.cc @@ -58,6 +58,20 @@ static void* thread_run(void *data) return NULL; } +static void* thread_run_clear_test(void *data) +{ + ConnectionPool *pool = (ConnectionPool*)data; + pool->giveBack(1); + pool->giveBack(2); + + sleep(1); + + pool->giveBack(3); + pool->giveBack(4); + + return NULL; +} + TEST_BEGIN; ConnectionPool pool; @@ -90,19 +104,21 @@ pool.giveBack(b_db2); TEST_EQUAL(pool.numFree(), 4, "Testing number of free databases."); -pthread_attr_t attr; -pthread_t tid; -pthread_attr_init(&attr); -pthread_create(&tid, &attr, thread_run, &pool); - -while(pool.numFree() > 0) { usleep(10); } - -int b_db3 = pool.borrow(); -TEST_FALSE(pool.testFree(b_db3), "Testing if returned db is free (semaphore test)."); -pool.giveBack(db3); - -pthread_join(tid, NULL); -pthread_attr_destroy(&attr); +{ + pthread_attr_t attr; + pthread_t tid; + pthread_attr_init(&attr); + pthread_create(&tid, &attr, thread_run, &pool); + + while(pool.numFree() > 0) { usleep(10); } + + int b_db3 = pool.borrow(); + TEST_FALSE(pool.testFree(b_db3), "Testing if returned db is free (semaphore test)."); + pool.giveBack(db3); + + pthread_join(tid, NULL); + pthread_attr_destroy(&attr); +} TEST_EQUAL(pool.numFree(), 4, "Testing if all database are now available again"); @@ -114,6 +130,33 @@ TEST_EQUAL(pool.numFree(), 4, "Testing if all database are now available again") } TEST_EQUAL(pool.numFree(), 4, "Testing if autoborrower has returned the db."); +// Force remove all elements. +pool.borrow(); +pool.clear(true); +TEST_EQUAL(pool.numFree(), 0, "Testing number of free databases."); + +// Add them again. +pool.add(db1); +pool.add(db2); +pool.add(db3); +pool.add(db4); +TEST_EQUAL(pool.numFree(), 4, "Testing number of free databases."); + +pool.borrow(); +pool.borrow(); +pool.borrow(); +pool.borrow(); + +{ + pthread_attr_t attr; + pthread_t tid; + pthread_attr_init(&attr); + pthread_create(&tid, &attr, thread_run_clear_test, &pool); + pool.clear(false); + pthread_join(tid, NULL); + pthread_attr_destroy(&attr); +} + TEST_END; #endif/*TEST_CONNECTIONPOOL*/ -- cgit v1.2.3