private static OperationPoller InjectZeroPoller() { OperationPoller poller = new OperationPoller(); poller.GetType().GetField("_delayStrategy", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(poller, new ZeroPollingStrategy()); return(poller); }
public void WaitForCompletionResponseCancelled() { var cts = new CancellationTokenSource(); var poller = new OperationPoller(new TestDelayStrategy(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1), cts)); var operation = new OperationInternal(new ClientDiagnostics(ClientOptions.Default), new EndlessOperation(), new MockResponse(200)); Assert.Catch <OperationCanceledException>(() => poller.WaitForCompletionResponse(operation, null, cts.Token)); }
public void ShouldDefaultToConstantFallback() { OperationPoller poller = new OperationPoller(); var delayStrategy = poller.GetType().GetField("_delayStrategy", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(poller); Assert.IsNotNull(delayStrategy); Assert.AreEqual(typeof(RetryAfterDelayStrategy), delayStrategy.GetType()); var fallbackStrategy = delayStrategy.GetType().GetField("_fallbackStrategy", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(delayStrategy); Assert.IsNotNull(delayStrategy); Assert.AreEqual(typeof(ConstantDelayStrategy), fallbackStrategy.GetType()); }
public void CanOverrideFallbackStrategy() { ExponentialDelayStrategy exponentialDelayStrategy = new ExponentialDelayStrategy(); OperationPoller poller = new OperationPoller(exponentialDelayStrategy); var delayStrategy = poller.GetType().GetField("_delayStrategy", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(poller); Assert.IsNotNull(delayStrategy); Assert.AreEqual(typeof(RetryAfterDelayStrategy), delayStrategy.GetType()); var fallbackStrategy = delayStrategy.GetType().GetField("_fallbackStrategy", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(delayStrategy); Assert.IsNotNull(delayStrategy); Assert.AreEqual(exponentialDelayStrategy, fallbackStrategy); }
/// <summary> /// Periodically calls the server till the long-running operation completes. /// </summary> /// <param name="pollingInterval"> /// The interval between status requests to the server. /// The interval can change based on information returned from the server. /// For example, the server might communicate to the client that there is not reason to poll for status change sooner than some time. /// </param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> used for the periodical service calls.</param> /// <returns>The last HTTP response received from the server.</returns> /// <remarks> /// This method will periodically call UpdateStatusAsync till HasCompleted is true, then return the final response of the operation. /// </remarks> public virtual async ValueTask <Response> WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) { OperationPoller poller = new OperationPoller(); return(await poller.WaitForCompletionResponseAsync(this, pollingInterval, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Periodically calls the server till the long-running operation completes. /// </summary> /// <param name="pollingInterval"> /// The interval between status requests to the server. /// The interval can change based on information returned from the server. /// For example, the server might communicate to the client that there is not reason to poll for status change sooner than some time. /// </param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> used for the periodical service calls.</param> /// <returns>The last HTTP response received from the server.</returns> /// <remarks> /// This method will periodically call UpdateStatusAsync till HasCompleted is true, then return the final response of the operation. /// </remarks> public virtual Response WaitForCompletionResponse(TimeSpan pollingInterval, CancellationToken cancellationToken = default) { OperationPoller poller = new OperationPoller(); return(poller.WaitForCompletionResponse(this, pollingInterval, cancellationToken)); }
/// <summary> /// Periodically calls the server till the long-running operation completes. /// </summary> /// <param name="cancellationToken">A <see cref="CancellationToken"/> used for the periodical service calls.</param> /// <returns>The last HTTP response received from the server.</returns> /// <remarks> /// This method will periodically call UpdateStatusAsync till HasCompleted is true, then return the final response of the operation. /// </remarks> public virtual Response WaitForCompletionResponse(CancellationToken cancellationToken = default) { OperationPoller poller = new OperationPoller(); return(poller.WaitForCompletionResponse(this, null, cancellationToken)); }
public virtual async ValueTask <Response <T> > WaitForCompletionAsync(CancellationToken cancellationToken = default) { OperationPoller poller = new OperationPoller(); return(await poller.WaitForCompletionAsync(this, null, cancellationToken).ConfigureAwait(false)); }