OSDN Git Service

UTコードを一部修正
authorokada <okada@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Thu, 4 Jun 2009 03:50:12 +0000 (03:50 +0000)
committerokada <okada@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Thu, 4 Jun 2009 03:50:12 +0000 (03:50 +0000)
git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-shamshel-refine@7883 1ed66053-1c2d-0410-8867-f7571e6e31d3

unit_tests/virtualservice_test/stub.cpp
unit_tests/virtualservice_test/vs_tcp.h
unit_tests/virtualservice_test/vs_tcp_test.cpp
unit_tests/virtualservice_test/vs_test.h

index 5de2f35..25336f3 100644 (file)
@@ -119,15 +119,21 @@ std::string               l7vs::Parameter::get_string(const PARAMETER_COMPONENT_TAG in_tag,
 
 void   l7vs::session_thread_control::upstream_run(){
        state_tag       state;
+       upthread_running_mutex.lock();
        {       // get first state from class upstream state.
-               boost::mutex::scoped_lock upcond_lock( upthread_condition_mutex );      // upstream state lock
+               rw_scoped_lock  upstate_lock( upthread_state_mutex );
                state = upthread_state; //thread local state is update.
        }
-//     boost::mutex::scoped_lock up_exit_lock( upthread_exit_mutex );
        for(;;){        // thread loop
                if( state == WAIT ){    // after create or session end. this thread is pooling mode
                        boost::mutex::scoped_lock       lock( upthread_condition_mutex );
-                       upthread_condition.wait( lock );        // thread is condition wait.( start at notify_all() )
+//                     upthread_condition.wait( lock );        // thread is condition wait.( start at notify_all() )
+                       boost::xtime    wait;
+                       boost::xtime_get( &wait, boost::TIME_UTC );
+                       wait.sec += 1;
+                       upthread_running_mutex.unlock();
+                       upthread_condition.timed_wait( lock, wait ); // thread is condition wait( start at notify_all() )
+                       upthread_running_mutex.lock();
                }
                else if( state == EXIT ){ // this state is vitrualservice end. thread is finishing.
                        break;
@@ -136,22 +142,31 @@ void      l7vs::session_thread_control::upstream_run(){
                        session->up_thread_run();       //session upstream thread looping.
                        stopupstream();
                }
-               boost::mutex::scoped_lock       upcond_lock( upthread_condition_mutex );        // upstream state lock
+               rw_scoped_lock  upstate_lock( upthread_state_mutex );
                state = upthread_state; //thread local state is update.
        }
+       upthread_running_mutex.unlock();
+       boost::mutex::scoped_lock up_lk( upthread_joining_mutex );
+       upthread_joining_condition.notify_all();
 }
 
 void   l7vs::session_thread_control::downstream_run(){
        state_tag       state;
+       downthread_running_mutex.lock();
        {
-               boost::mutex::scoped_lock downcond_lock( downthread_condition_mutex );  //downstream state is lock
+               rw_scoped_lock  downstate_lock( downthread_state_mutex );
                state = downthread_state;       //thread local state is update.
        }
-//     boost::mutex::scoped_lock down_exit_lock( downthread_exit_mutex );
        for(;;){        //thread loop
                if( state == WAIT ){    //after create or session end. this thread is pooling mode
                        boost::mutex::scoped_lock       lock( downthread_condition_mutex );
-                       downthread_condition.wait( lock ); // thread is condition wait( start at notify_all() )
+//                     downthread_condition.wait( lock ); // thread is condition wait( start at notify_all() )
+                       boost::xtime    wait;
+                       boost::xtime_get( &wait, boost::TIME_UTC );
+                       wait.sec += 1;
+                       downthread_running_mutex.unlock();
+                       downthread_condition.timed_wait( lock, wait ); // thread is condition wait( start at notify_all() )
+                       downthread_running_mutex.lock();
                }
                else if( state == EXIT ){// this state is vitrualservice end. thread is finishing.
                        break;
@@ -160,9 +175,12 @@ void       l7vs::session_thread_control::downstream_run(){
                        session->down_thread_run();//session downstream thread looping.
                        stopdownstream();
                }
-               boost::mutex::scoped_lock       downcond_lock( downthread_condition_mutex );    //downstream state lock
+               rw_scoped_lock  downstate_lock( downthread_state_mutex );
                state = downthread_state;       // thread local sate is update.
        }
+       downthread_running_mutex.unlock();
+       boost::mutex::scoped_lock down_lk( downthread_joining_mutex );
+       downthread_joining_condition.notify_all();
 }
 
 void   l7vs::session_thread_control::startupstream(){
index fa5dd2f..c49e8d3 100644 (file)
@@ -35,6 +35,12 @@ public:
        session_map_type&       get_active_sessions(){
                return  active_sessions;
        }
+       session_map_type&       get_waiting_sessions(){
+               return  waiting_sessions;
+       }
+       session_map_type&       get_sorry_sessions(){
+               return  sorry_sessions;
+       }
        std::list<realserver>&  get_rs_list(){
                return rs_list;
        }
@@ -43,7 +49,8 @@ public:
                virtualservice_tcp::release_session( in_id );
        }
        unsigned long long      get_ref_count(){
-               return rs_list_ref_count.get();
+//             return rs_list_ref_count.get();
+               return rs_list_ref_count;
        }
 };
 
index eddadaa..c922273 100644 (file)
@@ -101,10 +101,12 @@ void      virtualservice_tcp_test1(){
        // unit_test[5]  release_session method test(stopすると、sessionスレッドからrelease_sessionが呼ばれる)
        BOOST_MESSAGE( "-------5" );
        BOOST_CHECK( vs->get_pool_sessions().size() == (l7vs::virtualservice_base::SESSION_POOL_NUM_DEFAULT-1) );
-       BOOST_CHECK( vs->get_active_sessions().size() == 1 );
-       vs->release_session( vs->get_active_sessions().begin()->second->get_upthread_id() );
+       BOOST_CHECK( vs->get_waiting_sessions().size() == 1 );
+       BOOST_CHECK( vs->get_active_sessions().size() == 0 );
+       vs->release_session( vs->get_waiting_sessions().begin()->second->get_upthread_id() );
        BOOST_CHECK( vs->get_pool_sessions().size() == static_cast<size_t>( l7vs::virtualservice_base::SESSION_POOL_NUM_DEFAULT) );
        BOOST_CHECK( vs->get_active_sessions().size() == 0 );
+       BOOST_CHECK( vs->get_waiting_sessions().size() == 0 );
 
        // unit_test[6]  stop method test(call twice)
        BOOST_MESSAGE( "-------6" );
@@ -1232,10 +1234,10 @@ test_suite*     init_unit_test_suite( int argc, char* argv[] ){
        test_suite* ts = BOOST_TEST_SUITE( "virtualservice_base_test" );
 
        // add test case to test suite
-/*     ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test1 ) );
+       ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test1 ) );
        ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test2 ) );
        ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test3 ) );
-       ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test4 ) );*/
+       ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test4 ) );
        ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test5 ) );
 
        framework::master_test_suite().add( ts );
index 3c1e4ba..adc4755 100644 (file)
@@ -73,17 +73,20 @@ public:
        }
 
        unsigned long long      get_refcount(){
-               return rs_list_ref_count.get();
+//             return rs_list_ref_count.get();
+               return rs_list_ref_count;
        }
        void                            set_refcount( unsigned long long in ){
                rs_list_ref_count = in;
        }
 
        unsigned long long      get_curr_up_recv_size(){
-               return current_up_recvsize.get();
+//             return current_up_recvsize.get();
+               return current_up_recvsize;
        }
        unsigned long long      get_curr_down_recv_size(){
-               return current_down_recvsize.get();
+//             return current_down_recvsize.get();
+               return current_down_recvsize;
        }
        void    call_handle_throughput_update( const boost::system::error_code& err ){
                boost::xtime_get( &diffelencial_time, boost::TIME_UTC );