Skip to content

Commit

Permalink
API Review for Simmy
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Sep 20, 2023
1 parent 7cc2ea1 commit b0cf55e
Show file tree
Hide file tree
Showing 19 changed files with 248 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Assembly 'Polly.Core'

using System.Runtime.CompilerServices;

namespace Polly.Simmy.Behavior;

public readonly struct BehaviorActionArguments
{
public ResilienceContext Context { get; }
public BehaviorActionArguments(ResilienceContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Assembly 'Polly.Core'

using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Polly.Simmy.Behavior;

public class BehaviorStrategyOptions : MonkeyStrategyOptions
{
public Func<OnBehaviorInjectedArguments, ValueTask>? OnBehaviorInjected { get; set; }
[Required]
public Func<BehaviorActionArguments, ValueTask>? BehaviorAction { get; set; }
public BehaviorStrategyOptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Assembly 'Polly.Core'

using System.Runtime.CompilerServices;

namespace Polly.Simmy.Behavior;

public readonly struct OnBehaviorInjectedArguments
{
public ResilienceContext Context { get; }
public OnBehaviorInjectedArguments(ResilienceContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Assembly 'Polly.Core'

using System.Runtime.CompilerServices;

namespace Polly.Simmy.Latency;

public readonly struct LatencyGeneratorArguments
{
public ResilienceContext Context { get; }
public LatencyGeneratorArguments(ResilienceContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Assembly 'Polly.Core'

using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Polly.Simmy.Latency;

public class LatencyStrategyOptions : MonkeyStrategyOptions
{
public Func<OnLatencyArguments, ValueTask>? OnLatency { get; set; }
public Func<LatencyGeneratorArguments, ValueTask<TimeSpan>>? LatencyGenerator { get; set; }
public TimeSpan Latency { get; set; }
public LatencyStrategyOptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Assembly 'Polly.Core'

using System;
using System.Runtime.CompilerServices;

namespace Polly.Simmy.Latency;

public readonly struct OnLatencyArguments
{
public ResilienceContext Context { get; }
public TimeSpan Latency { get; }
public OnLatencyArguments(ResilienceContext context, TimeSpan latency);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Assembly 'Polly.Core'

using System.Runtime.CompilerServices;

namespace Polly.Simmy.Outcomes;

public readonly struct OnOutcomeInjectedArguments<TResult>
{
public ResilienceContext Context { get; }
public Outcome<TResult> Outcome { get; }
public OnOutcomeInjectedArguments(ResilienceContext context, Outcome<TResult> outcome);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Assembly 'Polly.Core'

using System.Runtime.CompilerServices;

namespace Polly.Simmy.Outcomes;

public readonly struct OutcomeGeneratorArguments
{
public ResilienceContext Context { get; }
public OutcomeGeneratorArguments(ResilienceContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Assembly 'Polly.Core'

using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Polly.Simmy.Outcomes;

public class OutcomeStrategyOptions<TResult> : MonkeyStrategyOptions
{
public Func<OnOutcomeInjectedArguments<TResult>, ValueTask>? OnOutcomeInjected { get; set; }
public Func<OutcomeGeneratorArguments, ValueTask<Outcome<TResult>?>>? OutcomeGenerator { get; set; }
public Outcome<TResult>? Outcome { get; set; }
public OutcomeStrategyOptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Assembly 'Polly.Core'

namespace Polly.Simmy.Outcomes;

public class OutcomeStrategyOptions : OutcomeStrategyOptions<object>
{
public OutcomeStrategyOptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Assembly 'Polly.Core'

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Polly.Simmy.Behavior;

namespace Polly.Simmy;

public static class BehaviorChaosPipelineBuilderExtensions
{
public static TBuilder AddChaosBehavior<TBuilder>(this TBuilder builder, bool enabled, double injectionRate, Func<ValueTask> behavior) where TBuilder : ResiliencePipelineBuilderBase;
public static TBuilder AddChaosBehavior<TBuilder>(this TBuilder builder, BehaviorStrategyOptions options) where TBuilder : ResiliencePipelineBuilderBase;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Assembly 'Polly.Core'

using System.Runtime.CompilerServices;

namespace Polly.Simmy;

public readonly struct EnabledGeneratorArguments
{
public ResilienceContext Context { get; }
public EnabledGeneratorArguments(ResilienceContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Assembly 'Polly.Core'

using System.Runtime.CompilerServices;

namespace Polly.Simmy;

public readonly struct InjectionRateGeneratorArguments
{
public ResilienceContext Context { get; }
public InjectionRateGeneratorArguments(ResilienceContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Assembly 'Polly.Core'

using System;
using System.Diagnostics.CodeAnalysis;
using Polly.Simmy.Latency;

namespace Polly.Simmy;

public static class LatencyChaosPipelineBuilderExtensions
{
public static TBuilder AddChaosLatency<TBuilder>(this TBuilder builder, bool enabled, double injectionRate, TimeSpan latency) where TBuilder : ResiliencePipelineBuilderBase;
public static TBuilder AddChaosLatency<TBuilder>(this TBuilder builder, LatencyStrategyOptions options) where TBuilder : ResiliencePipelineBuilderBase;
}
14 changes: 14 additions & 0 deletions ApiReview/API.Polly.Core/NoDocs/Polly.Simmy/MonkeyStrategy.T.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Assembly 'Polly.Core'

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Polly.Simmy;

public abstract class MonkeyStrategy<T> : ResilienceStrategy<T>
{
protected MonkeyStrategy(MonkeyStrategyOptions options);
protected ValueTask<bool> ShouldInjectAsync(ResilienceContext context);
}
14 changes: 14 additions & 0 deletions ApiReview/API.Polly.Core/NoDocs/Polly.Simmy/MonkeyStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Assembly 'Polly.Core'

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Polly.Simmy;

public abstract class MonkeyStrategy : ResilienceStrategy
{
protected MonkeyStrategy(MonkeyStrategyOptions options);
protected ValueTask<bool> ShouldInjectAsync(ResilienceContext context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Assembly 'Polly.Core'

using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Polly.Simmy;

public abstract class MonkeyStrategyOptions<TResult> : ResilienceStrategyOptions
{
[Range(0.0, 1.0)]
public double InjectionRate { get; set; }
public Func<InjectionRateGeneratorArguments, ValueTask<double>>? InjectionRateGenerator { get; set; }
public Func<EnabledGeneratorArguments, ValueTask<bool>>? EnabledGenerator { get; set; }
public bool Enabled { get; set; }
[Required]
public Func<double> Randomizer { get; set; }
protected MonkeyStrategyOptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Assembly 'Polly.Core'

namespace Polly.Simmy;

public abstract class MonkeyStrategyOptions : MonkeyStrategyOptions<object>
{
protected MonkeyStrategyOptions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Assembly 'Polly.Core'

using System;
using System.Diagnostics.CodeAnalysis;
using Polly.Simmy.Outcomes;

namespace Polly.Simmy;

public static class OutcomeChaosPipelineBuilderExtensions
{
public static ResiliencePipelineBuilder AddChaosFault(this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, Exception fault);
public static ResiliencePipelineBuilder AddChaosFault(this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, Func<Exception?> faultGenerator);
public static ResiliencePipelineBuilder AddChaosFault(this ResiliencePipelineBuilder builder, OutcomeStrategyOptions<Exception> options);
public static ResiliencePipelineBuilder<TResult> AddChaosFault<TResult>(this ResiliencePipelineBuilder<TResult> builder, bool enabled, double injectionRate, Exception fault);
public static ResiliencePipelineBuilder<TResult> AddChaosFault<TResult>(this ResiliencePipelineBuilder<TResult> builder, bool enabled, double injectionRate, Func<Exception?> faultGenerator);
public static ResiliencePipelineBuilder<TResult> AddChaosFault<TResult>(this ResiliencePipelineBuilder<TResult> builder, OutcomeStrategyOptions<Exception> options);
public static ResiliencePipelineBuilder<TResult> AddChaosResult<TResult>(this ResiliencePipelineBuilder<TResult> builder, bool enabled, double injectionRate, TResult result);
public static ResiliencePipelineBuilder<TResult> AddChaosResult<TResult>(this ResiliencePipelineBuilder<TResult> builder, bool enabled, double injectionRate, Func<TResult?> outcomeGenerator);
public static ResiliencePipelineBuilder<TResult> AddChaosResult<TResult>(this ResiliencePipelineBuilder<TResult> builder, OutcomeStrategyOptions<TResult> options);
}

0 comments on commit b0cf55e

Please sign in to comment.