コード例 #1
0
ファイル: BitcoinP2P.cpp プロジェクト: achow101/BitcoinArmory
void BitcoinP2P::connectToNode(bool async)
{
   unique_lock<mutex> lock(connectMutex_, defer_lock);

   if (!lock.try_lock()) //return if another thread is already here
      throw SocketError("another connect attempt is underway");

   connectedPromise_ = unique_ptr<promise<bool>>(new promise<bool>());
   auto connectedFuture = connectedPromise_->get_future();

   auto connectLambda = [this](void)->void
   {
      this->connectLoop();
   };

   thread connectthread(connectLambda);
   if (connectthread.joinable())
      connectthread.detach();

   if (async)
      return;

   connectedFuture.get();

   if (select_except_ != nullptr)
      rethrow_exception(select_except_);

   if (process_except_ != nullptr)
      rethrow_exception(process_except_);
}
コード例 #2
0
ファイル: exception.c プロジェクト: abak/jato
static struct vm_object *
new_exception(struct vm_class *vmc, const char *message)
{
	struct vm_object *message_str;
	struct vm_method *vmm;
	struct vm_object *obj;

	obj = vm_object_alloc(vmc);
	if (!obj)
		return rethrow_exception();

	if (message == NULL)
		message_str = NULL;
	else {
		message_str = vm_object_alloc_string_from_c(message);
		if (!message_str)
			return rethrow_exception();
	}

	vmm = vm_class_get_method(vmc, "<init>", "(Ljava/lang/String;)V");
	if (vmm) {
		vm_call_method(vmm, obj, message_str);

		return obj;
	}

	vmm = vm_class_get_method(vmc, "<init>", "()V");
	if (!vmm)
		error("constructor not found for %s", vmc->name);

	vm_call_method(vmm, obj);

	return obj;
}
コード例 #3
0
void
join( thread_handle & t )
    {
    t.t_.join();
    if( t.err_ )
        rethrow_exception(t.err_);
    }
コード例 #4
0
ファイル: assign.pass.cpp プロジェクト: AstroVPK/LLVM-4.0.0
int main()
{
    {
        std::nested_exception e0;
        std::nested_exception e;
        e = e0;
        assert(e.nested_ptr() == nullptr);
    }
#ifndef TEST_HAS_NO_EXCEPTIONS
    {
        try
        {
            throw A(2);
            assert(false);
        }
        catch (const A&)
        {
            std::nested_exception e0;
            std::nested_exception e;
            e = e0;
            assert(e.nested_ptr() != nullptr);
            try
            {
                rethrow_exception(e.nested_ptr());
                assert(false);
            }
            catch (const A& a)
            {
                assert(a == A(2));
            }
        }
    }
#endif
}
コード例 #5
0
wstring ExceptionHelper::GetCurrentExceptionMessage()
{
    wstring exceptionMessage;
    const exception_ptr exceptionPointer = current_exception();

    if(exceptionPointer == nullptr)
    {
        return wstring();
    }

    try
    {
        rethrow_exception(exceptionPointer);
    }
    catch (const SelectedTextTranslateBaseException& exception)
    {
        exceptionMessage = exception.GetFullErrorMessage();
    }
    catch (const SelectedTextTranslateBaseException* exception)
    {
        exceptionMessage = exception->GetFullErrorMessage();
    }
    catch (const exception& exception)
    {
        exceptionMessage = StringUtilities::Format(L"\tException message: '%hs'", exception.what());
    }
    catch (...)
    {
        exceptionMessage = L"\tUnknown exception occurred.";
    }

    return exceptionMessage;
}
コード例 #6
0
void
join( thread_handle & t )
    {
    t.t_.join();
    assert(t.err_);
    rethrow_exception(t.err_);
    }
コード例 #7
0
ファイル: fiber_base.cpp プロジェクト: rjpower/boost-fiber
void
fiber_base::rethrow() const
{
    BOOST_ASSERT( has_exception() );

    rethrow_exception( except_);
}
コード例 #8
0
ファイル: exception.cpp プロジェクト: themiwi/libcxx
void
nested_exception::rethrow_nested /*[[noreturn]]*/ () const
{
    if (__ptr_ == nullptr)
        terminate();
    rethrow_exception(__ptr_);
}
コード例 #9
0
int main()
{
    {
        std::nested_exception e;
        assert(e.nested_ptr() == nullptr);
    }
    {
        try
        {
            throw A(2);
            assert(false);
        }
        catch (const A&)
        {
            std::nested_exception e;
            assert(e.nested_ptr() != nullptr);
            try
            {
                rethrow_exception(e.nested_ptr());
                assert(false);
            }
            catch (const A& a)
            {
                assert(a == A(2));
            }
        }
    }
}
コード例 #10
0
json::Node PreparedQueryBase::_refetchStringValue( const std::size_t index ){
    // These types which are of uncertain size we must fetch separately now that we know how much
    // space to allocate.
    MYSQL_BIND& binder = m_results[ index ];
    if( *binder.length == 0 ){
        return json::Node( "", "" );
    }

    // It is not empty, so create a new binder and copy over this one's values.
    MYSQL_BIND rightSizeBinder;
    memcpy( &rightSizeBinder, &binder, sizeof( MYSQL_BIND ) );
    rightSizeBinder.buffer          = new char[ (*binder.length) + 1 ];
    rightSizeBinder.buffer_length   = (*binder.length) + 1;

    // Now fetch the column with our right-sized buffer.
    try {
        mysql_stmt_fetch_column( m_statement, &rightSizeBinder, index, 0 );
        LW_MYSQL_STMT_CHECK_FOR_ERRORS( m_statement, "Failed to fetch column" );
    }
    catch( ... ){
        lw::util::safeDeleteArray( (char*&)rightSizeBinder.buffer );
        rethrow_exception( current_exception() );
    }

    // Now convert the value to a string JSON node, clean up, and return.
    json::Node node( "", string( (char*)rightSizeBinder.buffer, *rightSizeBinder.length ) );
    lw::util::safeDeleteArray( (char*&)rightSizeBinder.buffer );
    return node;
}
コード例 #11
0
 void
 get_exception() const
     {
     boost::unique_lock<boost::mutex> lck (mux_);
     while (! ready_)
         cond_.wait (lck);
     rethrow_exception (exc_);
     }
コード例 #12
0
	void CThreadPoolItemExecutorJoin::Impl::join()
	{
		complete.wait();
		running=false;
		waiting_queue->emplace_and_notify(item);
		if(except)	//must check
			rethrow_exception(except);
	}
コード例 #13
0
void
_gmx_sel_lexer_rethrow_exception_if_occurred(yyscan_t scanner)
{
    gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(scanner);
    if (state->exception)
    {
        boost::exception_ptr ex = state->exception;
        state->exception = boost::exception_ptr();
        rethrow_exception(ex);
    }
}
コード例 #14
0
 void enter_()
 {
     holder< void > * hldr_from(
         reinterpret_cast< holder< void > * >(
             this->caller_.jump(
                 this->callee_,
                 reinterpret_cast< intptr_t >( this),
                 this->preserve_fpu() ) ) );
     this->callee_ = * hldr_from->ctx;
     if ( this->except_) rethrow_exception( this->except_);
 }
コード例 #15
0
ファイル: result.cpp プロジェクト: beimprovised/CppRemote
void result::get(param<void>&)
{
	if(never_update())
		return;

	boost::unique_lock<boost::mutex> lock(m_mutex);
	wait(lock);

	BOOST_ASSERT(m_ready);
	if(m_exception)
		rethrow_exception(m_exception);
}
コード例 #16
0
 template <class Impl> static constexpr void wide_value_check(Impl &&self)
 {
   if(!base::_has_value(std::forward<Impl>(self)))
   {
     if(base::_has_error(std::forward<Impl>(self)))
     {
       // ADL
       rethrow_exception(policy::exception_ptr(base::_error(std::forward<Impl>(self))));
     }
     BOOST_OUTCOME_THROW_EXCEPTION(bad_result_access("no value"));  // NOLINT
   }
 }
コード例 #17
0
ファイル: trampoline.c プロジェクト: jiangecho/jato
static void *jit_jni_trampoline(struct compilation_unit *cu)
{
	struct vm_method *method = cu->method;
	struct buffer *buf;
	void *target;

	target = vm_jni_lookup_method(method->class->name, method->name, method->type);
	if (!target) {
		signal_new_exception(vm_java_lang_UnsatisfiedLinkError, "%s.%s%s",
				     method->class->name, method->name, method->type);
		return rethrow_exception();
	}
コード例 #18
0
void
tester()
    {
    try
        {
        throw_fwd( &boost::exception_test::throw_test_exception<T> );
        BOOST_ASSERT(false);
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        T & y )
            {
#ifdef BOOST_NO_RTTI
            try
                {
                throw;
                }
            catch(
            boost::exception & y )
                {
#endif
                BOOST_TEST(boost::get_error_info<test_data>(y));
                if( int const * d=boost::get_error_info<test_data>(y) )
                    BOOST_TEST(*d==42);
#ifdef BOOST_NO_RTTI
                }
            catch(
            ... )
                {
                BOOST_TEST(false);
                }
#endif
            BOOST_TEST(y.x_==42);
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }
    }
コード例 #19
0
inline
std::string
diagnostic_information( exception_ptr const & p )
{
    if( p )
        try
        {
            rethrow_exception(p);
        }
        catch(
                ... )
        {
            return current_exception_diagnostic_information();
        }
    return "<empty>";
}
コード例 #20
0
ファイル: comm_link.cpp プロジェクト: beimprovised/CppRemote
bool comm_link::is_connection_error(exception_ptr const& _exception)
{
	try
	{
		rethrow_exception(_exception);
		BOOST_ASSERT(false);
	}
	catch(system_error& e)
	{
		if(e.code() == boost::system::errc::message_size)
			return false;

		return true;
	}
	catch(...)
	{}
	return false;
}
コード例 #21
0
void
simple_test()
    {
    boost::exception_ptr p = boost::copy_exception(err());
    try
        {
        rethrow_exception(p);
        BOOST_TEST(false);
        }
    catch(
    err & )
        {
        }
    catch(
    ... )
        {
        BOOST_TEST(false);
        }
    }
コード例 #22
0
int
main()
    {
    boost::exception_ptr p = boost::copy_exception(test_exception());
    try
        {
        rethrow_exception(p);
        BOOST_TEST(false);
        }
    catch(
    test_exception & )
        {
        }
    catch(
    ... )
        {
        BOOST_TEST(false);
        }
    return boost::report_errors();
    }
コード例 #23
0
ファイル: exception.cpp プロジェクト: Stevejohntest/hpx
    HPX_EXPORT void throw_exception(Exception const& e, std::string const& func,
        std::string const& file, long line)
    {
        boost::int64_t pid_ = ::getpid();
        std::string back_trace(backtrace());

        std::string hostname_ = "";
        if (get_runtime_ptr())
        {
            util::osstream strm;
            strm << get_runtime().here();
            hostname_ = util::osstream_get_string(strm);
        }

        // if this is not a HPX thread we do not need to query neither for
        // the shepherd thread nor for the thread id
        boost::uint32_t node = 0;
        std::size_t shepherd = std::size_t(-1);
        std::size_t thread_id = 0;
        std::string thread_name("");

        threads::thread_self* self = threads::get_self_ptr();
        if (NULL != self)
        {
            if (threads::threadmanager_is(running))
            {
                node = get_locality_id();
                shepherd = threads::threadmanager_base::get_worker_thread_num();
            }

            thread_id = reinterpret_cast<std::size_t>(self->get_thread_id());
            thread_name = threads::get_thread_description(self->get_thread_id());
        }

        rethrow_exception(e, func, file, line, back_trace, node, hostname_,
            pid_, shepherd, thread_id, thread_name);
    }
コード例 #24
0
ファイル: workercrashlogger.cpp プロジェクト: aveminus/freq
void WorkerCrashLogger::
        worker_quit(std::exception_ptr e, Signal::ComputingEngine::ptr ce)
{
    DEBUG TaskInfo ti(boost::format("WorkerCrashLogger::worker_quit %s") % (e?"normally":"with exception"));
    if (consume_exceptions_)
      {
        workers_.write ()->removeComputingEngine(ce);
      }

    try
      {
        if (e)
          {
            rethrow_exception(e);
          }

      }
    catch ( const boost::exception& x)
      {
        x << Workers::crashed_engine(ce) << Workers::crashed_engine_typename(ce?vartype(*ce):"(null)");

        log(x);
      }
}
コード例 #25
0
void
test_std_exception()
    {
    try
        {
        throw T();
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        BOOST_TEST(!(p==boost::exception_ptr()));
        BOOST_TEST(p!=boost::exception_ptr());
        BOOST_TEST(p);
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        T & )
            {
            boost::exception_ptr p = boost::current_exception();
            BOOST_TEST(!(p==boost::exception_ptr()));
            BOOST_TEST(p!=boost::exception_ptr());
            BOOST_TEST(p);
            try
                {
                rethrow_exception(p);
                BOOST_TEST(false);
                }
            catch(
            T & )
                {
                }
            catch(
            ... )
                {
                BOOST_TEST(false);
                }
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        boost::exception & x )
            {
#ifndef BOOST_NO_RTTI
            std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
            BOOST_TEST(t!=0 && *t!=0 && **t==typeid(T));
#endif
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }
    }
コード例 #26
0
int
main()
    {
    BOOST_TEST( boost::exception_ptr()==boost::exception_ptr() );
    BOOST_TEST( !(boost::exception_ptr()!=boost::exception_ptr()) );
    BOOST_TEST( !boost::exception_ptr() );

    int count=0;
    try
        {
        throw boost::enable_current_exception(derives_nothing(count));
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        BOOST_TEST(!(p==boost::exception_ptr()));
        BOOST_TEST(p!=boost::exception_ptr());
        BOOST_TEST(p);
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        derives_nothing & )
            {
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }
    BOOST_TEST(count==0);

    try
        {
        throw boost::enable_current_exception(derives_std_exception());
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        BOOST_TEST(!(p==boost::exception_ptr()));
        BOOST_TEST(p!=boost::exception_ptr());
        BOOST_TEST(p);
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        derives_std_exception & )
            {
            boost::exception_ptr p = boost::current_exception();
            BOOST_TEST(!(p==boost::exception_ptr()));
            BOOST_TEST(p!=boost::exception_ptr());
            BOOST_TEST(p);
            try
                {
                rethrow_exception(p);
                BOOST_TEST(false);
                }
            catch(
            derives_std_exception & )
                {
                }
            catch(
            ... )
                {
                BOOST_TEST(false);
                }
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }

    try
        {
        throw derives_std_exception();
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        BOOST_TEST(!(p==boost::exception_ptr()));
        BOOST_TEST(p!=boost::exception_ptr());
        BOOST_TEST(p);
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        boost::unknown_exception & e )
            {
#ifndef BOOST_NO_RTTI
            std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(e);
            BOOST_TEST(t!=0 && *t!=0 && **t==typeid(derives_std_exception));
#endif
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }

    test_std_exception_what<std::domain_error>();
    test_std_exception_what<std::invalid_argument>();
    test_std_exception_what<std::length_error>();
    test_std_exception_what<std::out_of_range>();
    test_std_exception_what<std::logic_error>();
    test_std_exception_what<std::range_error>();
    test_std_exception_what<std::overflow_error>();
    test_std_exception_what<std::underflow_error>();
    test_std_exception_what<std::ios_base::failure>();
    test_std_exception_what<std::runtime_error>();
    test_std_exception<std::bad_alloc>();
#ifndef BOOST_NO_TYPEID
    test_std_exception<std::bad_cast>();
    test_std_exception<std::bad_typeid>();
#endif
    test_std_exception<std::bad_exception>();
    test_std_exception<std::exception>();

    try
        {
        throw derives_std_boost_exception() << my_info(42);
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        BOOST_TEST(!(p==boost::exception_ptr()));
        BOOST_TEST(p!=boost::exception_ptr());
        BOOST_TEST(p);
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        boost::unknown_exception & x )
            {
            BOOST_TEST(boost::get_error_info<my_info>(x));
            if( int const * p=boost::get_error_info<my_info>(x) )
                BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
                {
            std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
            BOOST_TEST(t && *t && **t==typeid(derives_std_boost_exception));
                }
#endif
            boost::exception_ptr p = boost::current_exception();
            BOOST_TEST(!(p==boost::exception_ptr()));
            BOOST_TEST(p!=boost::exception_ptr());
            BOOST_TEST(p);
            try
                {
                rethrow_exception(p);
                BOOST_TEST(false);
                }
            catch(
            boost::unknown_exception & x )
                {
                BOOST_TEST(boost::get_error_info<my_info>(x));
                if( int const * p=boost::get_error_info<my_info>(x) )
                    BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
                std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
                BOOST_TEST(t && *t && **t==typeid(derives_std_boost_exception));
#endif
                }
            catch(
            ... )
                {
                BOOST_TEST(false);
                }
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }

    try
        {
        throw derives_boost_exception() << my_info(42);
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        BOOST_TEST(!(p==boost::exception_ptr()));
        BOOST_TEST(p!=boost::exception_ptr());
        BOOST_TEST(p);
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        boost::unknown_exception & x )
            {
            BOOST_TEST(boost::get_error_info<my_info>(x));
            if( int const * p=boost::get_error_info<my_info>(x) )
                BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
                {
            std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
            BOOST_TEST(t && *t && **t==typeid(derives_boost_exception));
                }
#endif
            boost::exception_ptr p = boost::current_exception();
            BOOST_TEST(!(p==boost::exception_ptr()));
            BOOST_TEST(p!=boost::exception_ptr());
            BOOST_TEST(p);
            try
                {
                rethrow_exception(p);
                BOOST_TEST(false);
                }
            catch(
            boost::unknown_exception & x )
                {
                BOOST_TEST(boost::get_error_info<my_info>(x));
                if( int const * p=boost::get_error_info<my_info>(x) )
                    BOOST_TEST(*p==42);
                }
            catch(
            ... )
                {
                BOOST_TEST(false);
                }
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }

    test_throw_on_copy<std::bad_alloc,std::bad_alloc>();
    test_throw_on_copy<int,std::bad_exception>();

    try
        {
        throw boost::enable_current_exception(derives_std_boost_exception("what1"));
        }
    catch(
    ... )
        {
        boost::exception_ptr p=boost::current_exception();
            {
        std::string s=diagnostic_information(p);
        BOOST_TEST(s.find("what1")!=s.npos);
            }
        try
            {
            throw boost::enable_current_exception(derives_std_boost_exception("what2") << nested_exception(p) );
            }
        catch(
        ... )
            {
            std::string s=boost::current_exception_diagnostic_information();
            BOOST_TEST(s.find("what1")!=s.npos);
            BOOST_TEST(s.find("what2")!=s.npos);
            }
        }
    BOOST_TEST(!diagnostic_information(boost::exception_ptr()).empty());
    return boost::report_errors();
    }
コード例 #27
0
void
test_throw_on_copy()
    {
    try
        {
        try
            {
            throw boost::enable_current_exception(may_throw_on_copy<Throw>());
            }
        catch(
        may_throw_on_copy<Throw> & x )
            {
            x.throw_=true;
            throw;
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }
    catch(
    ... )
        {
        boost::exception_ptr p = boost::current_exception();
        BOOST_TEST(!(p==boost::exception_ptr()));
        BOOST_TEST(p!=boost::exception_ptr());
        BOOST_TEST(p);
        try
            {
            rethrow_exception(p);
            BOOST_TEST(false);
            }
        catch(
        Catch & )
            {
            boost::exception_ptr p = boost::current_exception();
            BOOST_TEST(!(p==boost::exception_ptr()));
            BOOST_TEST(p!=boost::exception_ptr());
            BOOST_TEST(p);
            try
                {
                boost::rethrow_exception(p);
                BOOST_TEST(false);
                }
            catch(
            Catch & )
                {
                }
            catch(
            ... )
                {
                BOOST_TEST(false);
                }
            }
        catch(
        ... )
            {
            BOOST_TEST(false);
            }
        }
    }
コード例 #28
0
ファイル: session_impl.cpp プロジェクト: Corvusoft/restbed
        void SessionImpl::fetch_body( const size_t length, const shared_ptr< Session > session, const function< void ( const shared_ptr< Session >, const Bytes& ) >& callback ) const
        {
            const auto data_ptr = asio::buffer_cast< const Byte* >( session->m_pimpl->m_request->m_pimpl->m_buffer->data( ) );
            const auto data = Bytes( data_ptr, data_ptr + length );
            session->m_pimpl->m_request->m_pimpl->m_buffer->consume( length );
            
            auto& body = m_request->m_pimpl->m_body;
            
            if ( body.empty( ) )
            {
                body = data;
            }
            else
            {
                body.insert( body.end( ), data.begin( ), data.end( ) );
            }

            try
            {
                callback(session, data);
            }
            catch ( const int status_code )
            {
                const auto error_handler = session->m_pimpl->get_error_handler();
                error_handler( status_code, runtime_error( m_settings->get_status_message( status_code ) ), session );
            }
            catch ( const regex_error& re )
            {
                const auto error_handler = session->m_pimpl->get_error_handler();
                error_handler( 500, re, session );
            }
            catch ( const runtime_error& re )
            {
                const auto error_handler = session->m_pimpl->get_error_handler();
                error_handler( 400, re, session );
            }
            catch ( const exception& ex )
            {
                const auto error_handler = session->m_pimpl->get_error_handler();
                error_handler( 500, ex, session );
            }
            catch ( ... )
            {
                auto cex = current_exception( );

                if ( cex not_eq nullptr )
                {
                    try
                    {
                        rethrow_exception( cex );
                    }
                    catch ( const exception& ex )
                    {
                        const auto error_handler = session->m_pimpl->get_error_handler();
                        error_handler( 500, ex, session );
                    }
                    catch ( ... )
                    {
                        const auto error_handler = session->m_pimpl->get_error_handler();
                        error_handler( 500, runtime_error( "Internal Server Error" ), session );
                    }
                }
                else
                {
                    const auto error_handler = session->m_pimpl->get_error_handler();
                    error_handler( 500, runtime_error( "Internal Server Error" ), session );
                }
            }
        }
コード例 #29
0
ファイル: qteventworker.cpp プロジェクト: aveminus/freq
void QtEventWorker::
        test()
{
    std::string name = "Worker";
    int argc = 1;
    char * argv = &name[0];
    QApplication a(argc,&argv);

    // It should start and stop automatically
    {
        UNITTEST_STEPS TaskTimer tt("It should start and stop automatically");

        ISchedule::ptr gettask(new GetTaskMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        QThread::yieldCurrentThread ();
        EXCEPTION_ASSERT( worker.isRunning () );
    }

    // It should run tasks as given by the scheduler
    {
        UNITTEST_STEPS TaskTimer tt("It should run tasks as given by the scheduler");

        ISchedule::ptr gettask(new GetTaskMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        worker.wait (1);

        EXCEPTION_ASSERT_EQUALS( 1, dynamic_cast<GetTaskMock*>(&*gettask)->get_task_count );
        // Verify that tasks execute properly in Task::test.

        EXCEPTION_ASSERT( worker.isRunning () );
        worker.abort ();
        EXCEPTION_ASSERT( worker.wait (2) );
        EXCEPTION_ASSERT( !worker.isRunning () );
    }

    // It should wait to be awaken if there are no tasks
    {
        UNITTEST_STEPS TaskTimer tt("It should run tasks as given by the scheduler");

        ISchedule::ptr gettask(new GetTaskMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        EXCEPTION_ASSERT( !worker.wait (1) );
        EXCEPTION_ASSERT_EQUALS( 1, dynamic_cast<GetTaskMock*>(&*gettask)->get_task_count );
        QThread::msleep (1);
        EXCEPTION_ASSERT_EQUALS( 1, dynamic_cast<GetTaskMock*>(&*gettask)->get_task_count );

        worker.wakeup ();
        worker.wait (1);
        EXCEPTION_ASSERT_EQUALS( 2, dynamic_cast<GetTaskMock*>(&*gettask)->get_task_count );
    }

    // It should store information about a crashed task (segfault) and stop execution.
    if (!DetectGdb::is_running_through_gdb() && !DetectGdb::was_started_through_gdb ())
    {
        UNITTEST_STEPS TaskTimer tt("It should store information about a crashed task (segfault) and stop execution");

        PrettifySegfault::EnableDirectPrint (false);

        ISchedule::ptr gettask(new GetTaskSegFaultMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        worker.wait (1);
        worker.abort ();
        EXCEPTION_ASSERT( worker.wait (1) );
        EXCEPTION_ASSERT( worker.caught_exception () );

        EXPECT_EXCEPTION(segfault_sigill_exception, rethrow_exception(worker.caught_exception ()));

        PrettifySegfault::EnableDirectPrint (true);
    }

    // It should store information about a crashed task (std::exception) and stop execution. (1)
    {
        UNITTEST_STEPS TaskTimer tt("It should store information about a crashed task (std::exception) and stop execution (1)");

        ISchedule::ptr gettask(new GetTaskExceptionMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        QThread::yieldCurrentThread ();
    }

    // It should store information about a crashed task (std::exception) and stop execution. (2)
    {
        UNITTEST_STEPS TaskTimer tt("It should store information about a crashed task (std::exception) and stop execution (2)");

        ISchedule::ptr gettask(new GetTaskExceptionMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        worker.wait (1);
        worker.abort ();
        worker.wait (1);
        worker.abort ();

        EXCEPTION_ASSERT( worker.caught_exception () );

        try {
            rethrow_exception(worker.caught_exception ());
            BOOST_THROW_EXCEPTION(boost::unknown_exception());
        } catch (const ExceptionAssert& x) {
            const std::string* message = boost::get_error_info<ExceptionAssert::ExceptionAssert_message>(x);
            EXCEPTION_ASSERT_EQUALS( "testing that worker catches exceptions from a scheduler", message?*message:"" );
        }
    }

#if !defined SHARED_STATE_NO_TIMEOUT
    // It should store information about a crashed task (LockFailed) and stop execution.
    {
        UNITTEST_STEPS TaskTimer tt("It should store information about a crashed task (LockFailed) and stop execution.");

        ISchedule::ptr gettask(new ImmediateDeadLockMock());

        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        worker.wait (2);
        worker.abort ();
        EXCEPTION_ASSERT( worker.wait (10) );
        EXCEPTION_ASSERT( worker.caught_exception () );
        EXPECT_EXCEPTION(lock_failed, rethrow_exception(worker.caught_exception ()));

        EXCEPTION_ASSERT_EQUALS( 1, dynamic_cast<GetTaskMock*>(&*gettask)->get_task_count );
    }
#endif

    // It should not hang if it causes a deadlock (1)
    {
        UNITTEST_STEPS TaskTimer tt("It should not hang if it causes a deadlock (1)");

        ISchedule::ptr gettask(new DeadLockMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        EXCEPTION_ASSERT( worker.isRunning () );
        worker.terminate ();
        worker.terminate ();
        worker.terminate ();
        worker.terminate ();
        worker.abort ();
        worker.abort ();
        worker.abort ();
        worker.abort ();
        EXCEPTION_ASSERT( worker.wait (1) );
    }

    // It should not hang if it causes a deadlock (2)
    {
        UNITTEST_STEPS TaskTimer tt("It should not hang if it causes a deadlock (2)");

        ISchedule::ptr gettask(new DeadLockMock());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask);

        EXCEPTION_ASSERT( !worker.wait (1) );
        worker.terminate ();
        EXCEPTION_ASSERT( worker.wait (2) ); // Finish within 2 ms after terminate
        EXPECT_EXCEPTION( TerminatedException, rethrow_exception(worker.caught_exception ()) );
    }

    // It should announce when tasks are finished.
    {
        UNITTEST_STEPS TaskTimer tt("It should announce when tasks are finished.");

        ISchedule::ptr gettask(new DummySchedule());
        QtEventWorker worker(Signal::ComputingEngine::ptr(), gettask, false);

        QTimer t;
        t.setSingleShot( true );
        t.setInterval( 100 );

        QEventLoop e;
        connect (&t, SIGNAL(timeout()), &e, SLOT(quit()));
        connect (&worker, SIGNAL(oneTaskDone()), &e, SLOT(quit()), Qt::DirectConnection);

        worker.wakeup ();
        t.start();

        e.exec ();

        bool aborted_from_timeout = !t.isActive();
        EXCEPTION_ASSERT(!aborted_from_timeout);
   }
}
コード例 #30
0
ファイル: parcelhandler.hpp プロジェクト: cDoru/hpx
 /// The function \a get_parcel returns the next available parcel
 ///
 /// \param p        [out] The parcel instance to be filled with the
 ///                 received parcel. If the functioned returns \a true
 ///                 this will be the next received parcel.
 /// \param parcel_id  [in] The id of the parcel to fetch
 ///
 /// \returns        Returns \a true if the parcel with the given id
 ///                 has been retrieved successfully. The reference
 ///                 given by parameter \a p will be initialized with
 ///                 the received parcel data.
 ///                 Return \a false if no parcel is available in the
 ///                 parcelhandler, the reference \a p is not touched.
 ///
 /// The returned parcel will be no longer available from the
 /// parcelhandler as it is removed from the internal queue of received
 /// parcels.
 bool get_parcel(parcel& p, naming::gid_type const& parcel_id)
 {
     rethrow_exception();
     return parcels_->get_parcel(p, parcel_id);
 }