-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streams update 2.4.18 #2737
Streams update 2.4.18 #2737
Changes from 6 commits
4f38f73
f8262d6
7d61cb8
dd2e3bd
0639b77
128418b
b663263
fe63b3f
e01e47b
b2676ad
7fc98b8
6b2f726
eba2278
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
using Akka.Streams.IO; | ||
using Akka.Streams.TestKit.Tests; | ||
using Akka.TestKit; | ||
using Akka.Util; | ||
using Akka.Util.Internal; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
@@ -148,6 +149,44 @@ public void SynchronousFileSink_should_allow_appending_to_file() | |
}, _materializer); | ||
} | ||
|
||
[Fact] | ||
public void SynchronousFileSink_should_allow_writing_from_specific_position_to_the_file() | ||
{ | ||
TargetFile(f => { | ||
var testLinesCommon = new List<string> | ||
{ | ||
new string('a', 1000) + "\n", | ||
new string('b', 1000) + "\n", | ||
new string('c', 1000) + "\n", | ||
new string('d', 1000) + "\n", | ||
}; | ||
|
||
var commonByteString = ByteString.FromString(testLinesCommon.Join("")).Compact(); | ||
var startPosition = commonByteString.Count; | ||
|
||
var testLinesPart2 = new List<string>() | ||
{ | ||
new string('x', 1000) + "\n", | ||
new string('x', 1000) + "\n", | ||
}; | ||
|
||
Func<List<string>, long, Task<IOResult>> write = (lines, pos) => Source.From(lines) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use local function, is easier to read ;-) |
||
.Select(ByteString.FromString) | ||
.RunWith(FileIO.ToFile(f, fileMode:FileMode.OpenOrCreate, startPosition:pos), _materializer); | ||
|
||
var completion1 = write(_testLines, 0); | ||
completion1.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a |
||
var result1 = completion1.Result; | ||
|
||
var completion2 = write(testLinesPart2, startPosition); | ||
completion2.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above |
||
var result2 = completion2.Result; | ||
|
||
f.Length.ShouldBe(startPosition + result2.Count); | ||
CheckFileContent(f, testLinesCommon.Join("") + testLinesPart2.Join("")); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void SynchronousFileSink_should_use_dedicated_blocking_io_dispatcher_by_default() | ||
{ | ||
|
@@ -209,6 +248,29 @@ public void SynchronousFileSink_should_allow_overriding_the_dispatcher_using_Att | |
}, _materializer); | ||
} | ||
|
||
// Needed help converting this test case | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be removed ? :) |
||
[Fact] | ||
public void SynchronousFileSink_should_write_single_line_to_a_file_from_lazy_sink() | ||
{ | ||
this.AssertAllStagesStopped(() => { | ||
TargetFile(f => { | ||
var lazySink = Sink.LazySink( | ||
(ByteString _) => Task.FromResult(FileIO.ToFile(f)), | ||
() => Task.FromResult(IOResult.Success(0))) | ||
.MapMaterializedValue(t => { | ||
t.Wait(TimeSpan.FromSeconds(3)); | ||
return t.Result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's more like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure either, the origin code is a flatMap to ExecutionContexts, so the closest I can think of is to await the |
||
}); | ||
|
||
var completion = Source.From(new []{_testByteStrings.Head()}) | ||
.RunWith(lazySink, _materializer); | ||
|
||
completion.Wait(TimeSpan.FromSeconds(3)); | ||
CheckFileContent(f, _testLines.Head()); | ||
}); | ||
}, _materializer); | ||
} | ||
|
||
private static void TargetFile(Action<FileInfo> block, bool create = true) | ||
{ | ||
var targetFile = new FileInfo(Path.Combine(Path.GetTempPath(), "synchronous-file-sink.tmp")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.AssertAllStagesStopped(() => {
is missing