-
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.
* Update Streams to 2.4.8 * Fix log messages * Fix failure message
- Loading branch information
1 parent
aa913c2
commit 8f35fdc
Showing
44 changed files
with
2,473 additions
and
501 deletions.
There are no files selected for viewing
1,216 changes: 1,213 additions & 3 deletions
1,216
src/core/Akka.API.Tests/CoreAPISpec.ApproveStreams.approved.txt
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,242 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="LazySinkSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2015-2016 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2016 Akka.NET project <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Akka.Streams.Dsl; | ||
using Akka.Streams.Supervision; | ||
using Akka.Streams.TestKit; | ||
using Akka.Streams.TestKit.Tests; | ||
using Akka.TestKit; | ||
using Akka.Util.Internal; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Streams.Tests.Dsl | ||
{ | ||
public class LazySinkSpec : AkkaSpec | ||
{ | ||
public LazySinkSpec(ITestOutputHelper helper) : base(helper) | ||
{ | ||
var settings = ActorMaterializerSettings.Create(Sys).WithInputBuffer(1,1); | ||
Materializer = Sys.Materializer(settings); | ||
} | ||
|
||
private ActorMaterializer Materializer { get; } | ||
|
||
private static Func<TMat> Fallback<TMat>() | ||
{ | ||
return () => | ||
{ | ||
Assert.True(false, "Must not call fallback function"); | ||
return default(TMat); | ||
}; | ||
} | ||
|
||
private static readonly Exception Ex = new TestException(""); | ||
|
||
[Fact] | ||
public void A_LazySink_must_work_in_the_happy_case() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe<int>()), | ||
Fallback<TestSubscriber.Probe<int>>()); | ||
var taskProbe = Source.From(Enumerable.Range(0, 11)).RunWith(lazySink, Materializer); | ||
var probe = taskProbe.AwaitResult(TimeSpan.FromMilliseconds(300)); | ||
probe.Request(100); | ||
Enumerable.Range(0, 11).ForEach(i => probe.ExpectNext(i)); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_work_with_slow_sink_init() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var p = new TaskCompletionSource<Sink<int, TestSubscriber.Probe<int>>>(); | ||
var sourceProbe = this.CreateManualPublisherProbe<int>(); | ||
var taskProbe = Source.FromPublisher(sourceProbe) | ||
.RunWith(Sink.LazySink((int _) => p.Task, Fallback<TestSubscriber.Probe<int>>()), Materializer); | ||
|
||
var sourceSub = sourceProbe.ExpectSubscription(); | ||
sourceSub.ExpectRequest(1); | ||
sourceSub.SendNext(0); | ||
sourceSub.ExpectRequest(1); | ||
sourceProbe.ExpectNoMsg(TimeSpan.FromMilliseconds(200)); | ||
taskProbe.Wait(TimeSpan.FromMilliseconds(200)).ShouldBeFalse(); | ||
|
||
p.SetResult(this.SinkProbe<int>()); | ||
var probe = taskProbe.AwaitResult(TimeSpan.FromMilliseconds(300)); | ||
probe.Request(100); | ||
probe.ExpectNext(0); | ||
Enumerable.Range(1,10).ForEach(i => | ||
{ | ||
sourceSub.SendNext(i); | ||
probe.ExpectNext(i); | ||
}); | ||
sourceSub.SendComplete(); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_complete_when_there_was_no_elements_in_stream() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var lazySink = Sink.LazySink((int _) => Task.FromResult(Sink.Aggregate(0, (int i, int i2) => i + i2)), | ||
() => Task.FromResult(0)); | ||
var taskProbe = Source.Empty<int>().RunWith(lazySink, Materializer); | ||
var taskResult = taskProbe.AwaitResult(TimeSpan.FromMilliseconds(300)); | ||
taskResult.AwaitResult(TimeSpan.FromMilliseconds(300)).ShouldBe(0); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_complete_normally_when_upstream_is_completed() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe<int>()), | ||
Fallback<TestSubscriber.Probe<int>>()); | ||
var taskProbe = Source.Single(1).RunWith(lazySink, Materializer); | ||
var taskResult = taskProbe.AwaitResult(TimeSpan.FromMilliseconds(300)); | ||
taskResult.Request(1).ExpectNext(1).ExpectComplete(); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_fail_gracefully_when_sink_factory_method_failed() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var sourceProbe = this.CreateManualPublisherProbe<int>(); | ||
var taskProbe = Source.FromPublisher(sourceProbe).RunWith(Sink.LazySink((int _) => | ||
{ | ||
throw Ex; | ||
}, Fallback<TestSubscriber.Probe<int>>()), Materializer); | ||
|
||
var sourceSub = sourceProbe.ExpectSubscription(); | ||
sourceSub.ExpectRequest(1); | ||
sourceSub.SendNext(0); | ||
sourceSub.ExpectCancellation(); | ||
taskProbe.Invoking(t => t.Wait()).ShouldThrow<TestException>(); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_fail_gracefully_when_upstream_failed() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var sourceProbe = this.CreateManualPublisherProbe<int>(); | ||
var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe<int>()), | ||
Fallback<TestSubscriber.Probe<int>>()); | ||
var taskProbe = Source.FromPublisher(sourceProbe).RunWith(lazySink, Materializer); | ||
|
||
var sourceSub = sourceProbe.ExpectSubscription(); | ||
sourceSub.ExpectRequest(1); | ||
sourceSub.SendNext(0); | ||
var probe = taskProbe.AwaitResult(TimeSpan.FromMilliseconds(300)); | ||
probe.Request(1).ExpectNext(0); | ||
sourceSub.SendError(Ex); | ||
probe.ExpectError().Should().Be(Ex); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_fail_gracefully_when_factory_task_failed() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var failedTask = new TaskFactory<Sink<int, TestSubscriber.Probe<int>>>().StartNew(() => | ||
{ | ||
throw Ex; | ||
}); | ||
var sourceProbe = this.CreateManualPublisherProbe<int>(); | ||
var lazySink = Sink.LazySink((int _) => failedTask, Fallback<TestSubscriber.Probe<int>>()); | ||
var graph = | ||
Source.FromPublisher(sourceProbe) | ||
.ToMaterialized(lazySink, Keep.Right) | ||
.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.StoppingDecider)); | ||
var taskProbe = RunnableGraph.FromGraph(graph).Run(Materializer); | ||
|
||
var sourceSub = sourceProbe.ExpectSubscription(); | ||
sourceSub.ExpectRequest(1); | ||
sourceSub.SendNext(0); | ||
taskProbe.Invoking(t => t.Wait(TimeSpan.FromMilliseconds(300))).ShouldThrow<TestException>(); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_cancel_upstream_when_internal_sink_is_cancelled() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var sourceProbe = this.CreateManualPublisherProbe<int>(); | ||
var lazySink = Sink.LazySink((int _) => Task.FromResult(this.SinkProbe<int>()), | ||
Fallback<TestSubscriber.Probe<int>>()); | ||
var taskProbe = Source.FromPublisher(sourceProbe).RunWith(lazySink, Materializer); | ||
var sourceSub = sourceProbe.ExpectSubscription(); | ||
sourceSub.ExpectRequest(1); | ||
sourceSub.SendNext(0); | ||
sourceSub.ExpectRequest(1); | ||
var probe = taskProbe.AwaitResult(TimeSpan.FromMilliseconds(300)); | ||
probe.Request(1).ExpectNext(0); | ||
probe.Cancel(); | ||
sourceSub.ExpectCancellation(); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_contine_if_supervision_is_resume() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var sourceProbe = this.CreateManualPublisherProbe<int>(); | ||
var lazySink = Sink.LazySink((int a) => | ||
{ | ||
if (a == 0) | ||
throw Ex; | ||
return Task.FromResult(this.SinkProbe<int>()); | ||
}, | ||
Fallback<TestSubscriber.Probe<int>>()); | ||
var graph = | ||
Source.FromPublisher(sourceProbe) | ||
.ToMaterialized(lazySink, Keep.Right) | ||
.WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)); | ||
var taskProbe = RunnableGraph.FromGraph(graph).Run(Materializer); | ||
var sourceSub = sourceProbe.ExpectSubscription(); | ||
sourceSub.ExpectRequest(1); | ||
sourceSub.SendNext(0); | ||
sourceSub.ExpectRequest(1); | ||
sourceSub.SendNext(1); | ||
var probe = taskProbe.AwaitResult(TimeSpan.FromMilliseconds(300)); | ||
probe.Request(1); | ||
probe.ExpectNext(1); | ||
probe.Cancel(); | ||
}, Materializer); | ||
} | ||
|
||
[Fact] | ||
public void A_LazySink_must_fail_task_when_zero_throws_expception() | ||
{ | ||
this.AssertAllStagesStopped(() => | ||
{ | ||
var lazySink = Sink.LazySink((int _) => Task.FromResult(Sink.Aggregate<int, int>(0, (i, i1) => i + i1)), | ||
() => | ||
{ | ||
throw Ex; | ||
}); | ||
var taskProbe = Source.Empty<int>().RunWith(lazySink, Materializer); | ||
taskProbe.Invoking(t => t.Wait(TimeSpan.FromMilliseconds(300))).ShouldThrow<TestException>(); | ||
}, Materializer); | ||
} | ||
} | ||
} |
Oops, something went wrong.