From 72a939b7cbaf201e6186d430d85e9893722e5620 Mon Sep 17 00:00:00 2001 From: ravengerUA Date: Wed, 27 Sep 2017 13:22:28 +0300 Subject: [PATCH] changed example --- .../DocsExamples/Streams/StreamTcpDocTests.cs | 83 +++++++++++-------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/docs/examples/DocsExamples/Streams/StreamTcpDocTests.cs b/docs/examples/DocsExamples/Streams/StreamTcpDocTests.cs index 348ed1e4564..9e9c112389b 100644 --- a/docs/examples/DocsExamples/Streams/StreamTcpDocTests.cs +++ b/docs/examples/DocsExamples/Streams/StreamTcpDocTests.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Collections.Generic; using System.Threading.Tasks; using Akka; using Akka.Streams; @@ -9,9 +9,8 @@ using Xunit.Abstractions; using Akka.Actor; using Akka.IO; +using Akka.Util; using Tcp = Akka.Streams.Dsl.Tcp; -using TcpExt = Akka.Streams.Dsl.TcpExt; -using Akka.Util.Internal; namespace DocsExamples.Streams { @@ -82,37 +81,6 @@ public void Simple_server_connection_must_close_incoming_connection() }, Materializer); } - [Fact] - public void Simple_server_connection_must_REPL() - { - #region repl-client - var connection = Sys.TcpStream().OutgoingConnection("127.0.0.1", 8888); - - var replParser = Flow.Create().TakeWhile(c => c != "q") - .Concat(Source.Single("BYE")) - .Select(elem => ByteString.FromString($"{elem}\n")); - - var repl = Flow.Create() - .Via(Framing.Delimiter( - ByteString.FromString("\n"), - maximumFrameLength: 256, - allowTruncation: true)) - .Select(c => c.ToString()) - .Select(text => - { - Console.WriteLine($"Server: {text}"); - return text; - }) - .Select(text => - { - return Console.ReadLine(); // TODO: implement - }) - .Via(replParser); - - connection.Join(repl).Run(Materializer); - #endregion - } - [Fact] public void Simple_server_must_initial_server_banner_echo_server() { @@ -122,6 +90,7 @@ public void Simple_server_must_initial_server_banner_echo_server() #region welcome-banner-chat-server connections.RunForeach(connection => { + // server logic, parses incoming commands var commandParser = Flow.Create().TakeWhile(c => c != "BYE").Select(c => c + "!"); var welcomeMessage = $"Welcome to: {connection.LocalAddress}, you are: {connection.RemoteAddress}!"; @@ -146,6 +115,52 @@ public void Simple_server_must_initial_server_banner_echo_server() connection.HandleWith(serverLogic, Materializer); }, Materializer); #endregion + + var input = new AtomicReference>(new List { "Hello world", "What a lovely day", null }); + + string ReadLine(string prompt) + { + // TODO: implement it + switch (input.Value) + { + default: + return null; + } + } + + { + var connection = Sys.TcpStream().OutgoingConnection("127.0.0.1", 8888); + } + + { + #region repl-client + var connection = Sys.TcpStream().OutgoingConnection("127.0.0.1", 8888); + + var replParser = Flow.Create().TakeWhile(c => c != "q") + .Concat(Source.Single("BYE")) + .Select(elem => ByteString.FromString($"{elem}\n")); + + var repl = Flow.Create() + .Via(Framing.Delimiter( + ByteString.FromString("\n"), + maximumFrameLength: 256, + allowTruncation: true)) + .Select(c => c.ToString()) + .Select(text => + { + Output.WriteLine($"Server: {text}"); + return text; + }) + .Select(text => ReadLine("> ")) + .Via(replParser); + + connection.Join(repl).Run(Materializer); + #endregion + } + + serverProbe.ExpectMsg("Hello world", TimeSpan.FromSeconds(20)); + serverProbe.ExpectMsg("What a lovely day"); + serverProbe.ExpectMsg("BYE"); } } }