Esempio n. 1
0
bool
InterceptorI::dispatch(Ice::Request& request)
{
    Ice::Current& current = const_cast<Ice::Current&>(request.getCurrent());
    _lastOperation = current.operation;

    if(_lastOperation == "addWithRetry")
    {
        for(int i = 0; i < 10; ++i)
        {
            try
            {
                _servant->ice_dispatch(request);
                test(false);
            }
            catch(const Test::RetryException&)
            {
                //
                // Expected, retry
                //
            }
        }

        current.ctx["retry"] = "no";
    }
    _lastStatus = _servant->ice_dispatch(request);
    return _lastStatus;
}
Esempio n. 2
0
Ice::DispatchStatus 
AMDInterceptorI::dispatch(Ice::Request& request)
{
    class CallbackI : public Ice::DispatchInterceptorAsyncCallback
    {
    public:
        
        virtual bool response(bool ok)
        {
            test(ok);
            return false;
        }

        virtual bool exception(const std::exception& ex)
        {
            test(dynamic_cast<const Test::RetryException*>(&ex) != 0);
            return false;
        }

        virtual bool exception()
        {
            //
            // Unexpected
            //
            test(false);
            return false;
        }
    };


    Ice::Current& current = const_cast<Ice::Current&>(request.getCurrent());
    _lastOperation = current.operation;
    
    Ice::DispatchInterceptorAsyncCallbackPtr cb = new CallbackI();

    if(_lastOperation == "amdAddWithRetry")
    {
        for(int i = 0; i < 10; ++i)
        {
            _lastStatus =  _servant->ice_dispatch(request, cb);
            test(_lastStatus == Ice::DispatchAsync);
        }
        
        current.ctx["retry"] = "no";
    }
      
    _lastStatus = _servant->ice_dispatch(request, _defaultCb);
    return _lastStatus;
}
Esempio n. 3
0
bool
AMDInterceptorI::dispatch(Ice::Request& request)
{
#ifndef ICE_CPP11_MAPPING
    class CallbackI : public Ice::DispatchInterceptorAsyncCallback
    {
    public:
        CallbackI() : _count(0)
        {
        }

        virtual bool response()
        {
            return false;
        }

        virtual bool exception(const std::exception& ex)
        {
            test(_count++ == 0); // Ensure it's only called once
            test(dynamic_cast<const Test::RetryException*>(&ex) != 0);
            return false;
        }

        virtual bool exception()
        {
            //
            // Unexpected
            //
            test(false);
            return false;
        }

    private:

        int _count;
    };
#endif

    Ice::Current& current = const_cast<Ice::Current&>(request.getCurrent());
    _lastOperation = current.operation;

    if(_lastOperation == "amdAddWithRetry")
    {
        for(int i = 0; i < 10; ++i)
        {
#ifdef ICE_CPP11_MAPPING
            _lastStatus = _servant->ice_dispatch(request, nullptr, [](exception_ptr ex) {
                try
                {
                    rethrow_exception(ex);
                }
                catch(const Test::RetryException&)
                {
                }
                catch(...)
                {
                    test(false);
                }
                return false;
            });
#else
            _lastStatus =  _servant->ice_dispatch(request, new CallbackI());
#endif
            test(!_lastStatus);
        }

        current.ctx["retry"] = "no";
    }

#ifdef ICE_CPP11_MAPPING
    _lastStatus = _servant->ice_dispatch(request, []() { return true; }, [this](exception_ptr ex) {
        try
        {
            rethrow_exception(ex);
        }
        catch(const IceUtil::Exception& ex)
        {
            setException(ex);
        }
        catch(...)
        {
            test(false);
        }
        return true;
    });
#else
    _lastStatus = _servant->ice_dispatch(request, _defaultCb);
#endif
    return _lastStatus;
}