Esempio n. 1
0
        internal Driver(Uri uri, IConnectionProvider connectionProvider, IRetryLogic retryLogic, ILogger logger)
        {
            Throw.ArgumentNullException.IfNull(connectionProvider, nameof(connectionProvider));

            Uri                 = uri;
            _logger             = logger;
            _connectionProvider = connectionProvider;
            _retryLogic         = retryLogic;
        }
Esempio n. 2
0
        public Session(IConnectionProvider provider, ILogger logger, IRetryLogic retryLogic = null,
                       AccessMode defaultMode = AccessMode.Write, Bookmark bookmark = null) : base(logger)
        {
            _connectionProvider = provider;
            _retryLogic         = retryLogic;

            _defaultMode = defaultMode;
            UpdateBookmark(bookmark);
        }
        private void Retry(int index, IRetryLogic retryLogic)
        {
            var timer = new Stopwatch();

            timer.Start();
            var e = Record.Exception(() => retryLogic.Retry <int>(() =>
            {
                var errorMessage = $"Thread {index} Failed at {timer.Elapsed}";
                throw new SessionExpiredException(errorMessage);
            }));

            timer.Stop();

            var error       = e as AggregateException;
            var innerErrors = error.Flatten().InnerExceptions;

            innerErrors.Count.Should().BeGreaterOrEqualTo(5);
            timer.Elapsed.TotalSeconds.Should().BeGreaterOrEqualTo(30);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RestServiceBase"/> class with the specified string serializer,
        /// logger, retry logic, and URI builder.
        /// </summary>
        /// <param name="stringSerializer">The string serializer to use for requests from this service.</param>
        /// <param name="logger">The logger to use for requests. Specify <c>null</c> if requests do not need to be logged.</param>
        /// <param name="retryLogic">The retry logic to use for REST operations.</param>
        /// <param name="urlBuilder">The URL builder to use for constructing URLs with query parameters.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="stringSerializer"/> is <c>null</c>.
        /// <para>-or-</para>
        /// <para>If <paramref name="retryLogic"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="urlBuilder"/> is <c>null</c>.</para>
        /// </exception>
        protected RestServiceBase(IStringSerializer stringSerializer, IRequestLogger logger, IRetryLogic <Response, HttpStatusCode> retryLogic, IUrlBuilder urlBuilder)
        {
            if (stringSerializer == null)
            {
                throw new ArgumentNullException("stringSerializer");
            }
            if (retryLogic == null)
            {
                throw new ArgumentNullException("retryLogic");
            }
            if (urlBuilder == null)
            {
                throw new ArgumentNullException("urlBuilder");
            }

            _retryLogic       = retryLogic;
            _logger           = logger;
            _urlBuilder       = urlBuilder;
            _stringSerializer = stringSerializer;
        }
Esempio n. 5
0
        private void Retry(int index, IRetryLogic retryLogic)
        {
            var timer = new Stopwatch();

            timer.Start();
            var runCounter = 0;
            var e          = Record.Exception(() => retryLogic.Retry <int>(() =>
            {
                runCounter++;
                Interlocked.Increment(ref _globalCounter);
                var errorMessage = $"Thread {index} Failed at {timer.Elapsed}";
                throw new SessionExpiredException(errorMessage);
            }));

            timer.Stop();

            e.Should().BeOfType <ServiceUnavailableException>();
            var error       = e.InnerException as AggregateException;
            var innerErrors = error.Flatten().InnerExceptions;

            innerErrors.Count.Should().Be(runCounter);
            timer.Elapsed.TotalSeconds.Should().BeGreaterOrEqualTo(5);
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonRestServices"/> class with the specified
 /// logger, retry logic, URI builder, and string serializer.
 /// </summary>
 /// <param name="logger">The logger to use for requests. Specify <c>null</c> if requests do not need to be logged.</param>
 /// <param name="retryLogic">The retry logic to use for REST operations.</param>
 /// <param name="urlBuilder">The URL builder to use for constructing URLs with query parameters.</param>
 /// <param name="stringSerializer">The string serializer to use for requests from this service.</param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="retryLogic"/> is <c>null</c>.
 /// <para>-or-</para>
 /// <para>If <paramref name="urlBuilder"/> is <c>null</c>.</para>
 /// <para>-or-</para>
 /// <para>If <paramref name="stringSerializer"/> is <c>null</c>.</para>
 /// </exception>
 public JsonRestServices(IRequestLogger logger, IRetryLogic<Response, HttpStatusCode> retryLogic, IUrlBuilder urlBuilder, IStringSerializer stringSerializer)
     : base(stringSerializer, logger, retryLogic, urlBuilder)
 {
 }
Esempio n. 7
0
 public InternalSession(IInternalAsyncSession session, IRetryLogic retryLogic, BlockingExecutor executor)
 {
     _session    = session ?? throw new ArgumentNullException(nameof(session));
     _retryLogic = retryLogic ?? throw new ArgumentNullException(nameof(retryLogic));
     _executor   = executor ?? throw new ArgumentNullException(nameof(executor));
 }
Esempio n. 8
0
 internal static Session NewSession(IConnection connection, ILogger logger = null, IRetryLogic retryLogic = null, AccessMode mode = AccessMode.Write, string bookmark = null)
 {
     return(new Session(new TestConnectionProvider(connection), logger, retryLogic, mode, Bookmark.From(bookmark)));
 }
Esempio n. 9
0
        internal static Session NewSession(IBoltProtocol protocol, ILogger logger = null, IRetryLogic retryLogic = null, AccessMode mode = AccessMode.Write, string bookmark = null)
        {
            var mockConn = new Mock <IConnection>();

            mockConn.Setup(x => x.IsOpen).Returns(true);
            mockConn.Setup(x => x.BoltProtocol).Returns(protocol);
            return(new Session(new TestConnectionProvider(mockConn.Object), logger, retryLogic, mode, Bookmark.From(bookmark)));
        }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonRestServices"/> class with the specified
 /// logger, retry logic, URI builder, and string serializer.
 /// </summary>
 /// <param name="logger">The logger to use for requests. Specify <c>null</c> if requests do not need to be logged.</param>
 /// <param name="retryLogic">The retry logic to use for REST operations.</param>
 /// <param name="urlBuilder">The URL builder to use for constructing URLs with query parameters.</param>
 /// <param name="stringSerializer">The string serializer to use for requests from this service.</param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="retryLogic"/> is <c>null</c>.
 /// <para>-or-</para>
 /// <para>If <paramref name="urlBuilder"/> is <c>null</c>.</para>
 /// <para>-or-</para>
 /// <para>If <paramref name="stringSerializer"/> is <c>null</c>.</para>
 /// </exception>
 public JsonRestServices(IRequestLogger logger, IRetryLogic <Response, HttpStatusCode> retryLogic, IUrlBuilder urlBuilder, IStringSerializer stringSerializer) : base(stringSerializer, logger, retryLogic, urlBuilder)
 {
 }