From f6c143f4c4e4f0a8118596909114e34dfc496b92 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 6 Sep 2010 15:16:38 +0200 Subject: fixed test9, works now --- tests/test9.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/test9.cpp b/tests/test9.cpp index 5252524..07c1348 100644 --- a/tests/test9.cpp +++ b/tests/test9.cpp @@ -45,7 +45,7 @@ const int NOF_CONSUMER_OPS = 100; static MUTEX_TYPE cout_mutex; static bool verbose = false; -static bool tracing = true; +static bool tracing = false; static THREAD_FUNC_DECL produce( void *thread_data ) { @@ -54,7 +54,12 @@ static THREAD_FUNC_DECL produce( void *thread_data ) try { connection c( "test9.db" ); if( tracing ) c.trace( true ); - c.prepare( "ins", "insert into x values( ? )" )( "integer", prepare::treat_direct ); +PRODUCER_PREPARE_AGAIN: + try { + c.prepare( "ins", "insert into x values( ? )" )( "integer", prepare::treat_direct ); + } catch( const database_locked& e ) { + goto PRODUCER_PREPARE_AGAIN; + } for( int i = 0; i < NOF_PRODUCER_TRANSACTIONS; i++ ) { work t( c, "ins" ); @@ -68,18 +73,18 @@ PRODUCER_INS_AGAIN: try { result r = t.prepared( "ins" )( no * 100000 + i * 1000 + j ).exec( ); assert( r.affected_rows( ) == 1 ); - } catch( database_locked& e ) { + t.commit( ); + } catch( const database_locked& e ) { goto PRODUCER_INS_AGAIN; } } - t.commit( ); if( verbose ) { MUTEX_LOCK( cout_mutex ); cout << "producer " << no << " transaction " << i << " terminated" << endl; MUTEX_UNLOCK( cout_mutex ); } } - } catch( sql_error& e ) { + } catch( const sql_error& e ) { cerr << "producer error, " << e.what( ) << ": " << e.query( ) << endl; } @@ -92,7 +97,12 @@ static THREAD_FUNC_DECL consume( void *thread_data ) try { connection c( "test9.db" ); - c.prepare( "sel", "select * from x" ); +CONSUMER_PREPARE_AGAIN: + try { + c.prepare( "sel", "select * from x" ); + } catch( const database_locked &e ) { + goto CONSUMER_PREPARE_AGAIN; + } if( tracing ) c.trace( true ); for( int i = 0; i < NOF_CONSUMER_TRANSACTIONS; i++ ) { @@ -116,18 +126,18 @@ CONSUMER_SELECT_AGAIN: cout << "consumer " << no << " transaction " << i << " got " << nof_rows << " rows." << endl; MUTEX_UNLOCK( cout_mutex ); } - } catch( database_locked& e ) { + t.commit( ); + } catch( const database_locked& e ) { goto CONSUMER_SELECT_AGAIN; } } - t.commit( ); if( verbose ) { MUTEX_LOCK( cout_mutex ); cout << "consumer " << no << " transaction " << i << " terminated" << endl; MUTEX_UNLOCK( cout_mutex ); } } - } catch( sql_error& e ) { + } catch( const sql_error& e ) { cerr << "consumer error, " << e.what( ) << ": " << e.query( ) << endl; } @@ -171,7 +181,7 @@ int main( ) { MUTEX_CLEANUP( cout_mutex ); - } catch( sql_error& e ) { + } catch( const sql_error& e ) { cerr << e.what( ) << ": " << e.query( ) << endl; } } -- cgit v1.2.3-54-g00ecf