-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RestartSource/Flow/Sink (#3103)
* Restart Flow/Sink/Source * Added RestartSource specs * More tests and docs * Ported all tests * Fixed sink test * fix specs * Added docs * Added timeout * Increased timeouts for mono
- Loading branch information
1 parent
d971549
commit b9af0c9
Showing
6 changed files
with
1,273 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Akka; | ||
using Akka.Streams; | ||
using Akka.Streams.Dsl; | ||
using Akka.TestKit.Xunit2; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace DocsExamples.Streams | ||
{ | ||
public class RestartDocTests : TestKit | ||
{ | ||
private ActorMaterializer Materializer { get; } | ||
|
||
public RestartDocTests(ITestOutputHelper output) | ||
: base("", output) | ||
{ | ||
Materializer = Sys.Materializer(); | ||
} | ||
|
||
private void DoSomethingElse() | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Restart_stages_should_demonstrate_a_restart_with_backoff_source() | ||
{ | ||
#region restart-with-backoff-source | ||
var httpClient = new HttpClient(); | ||
|
||
var restartSource = RestartSource.WithBackoff(() => | ||
{ | ||
// Create a source from a task | ||
return Source.FromTask( | ||
httpClient.GetAsync("http://example.com/eventstream") // Make a single request | ||
) | ||
.Select(c => c.Content.ReadAsStringAsync()) | ||
.Select(c => c.Result); | ||
}, | ||
minBackoff: TimeSpan.FromSeconds(3), | ||
maxBackoff: TimeSpan.FromSeconds(30), | ||
randomFactor: 0.2 // adds 20% "noise" to vary the intervals slightly | ||
); | ||
#endregion | ||
|
||
#region with-kill-switch | ||
var killSwitch = restartSource | ||
.ViaMaterialized(KillSwitches.Single<string>(), Keep.Right) | ||
.ToMaterialized(Sink.ForEach<string>(evt => Console.WriteLine($"Got event: {evt}")), Keep.Left) | ||
.Run(Materializer); | ||
|
||
DoSomethingElse(); | ||
|
||
killSwitch.Shutdown(); | ||
#endregion | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.