コード例 #1
0
        public void MemoryStream_JustNewLines_3_BufferSize_2()
        {
            const int bufferSize = 2;
            Encoding  encoding   = Encoding.Unicode;

            TestProbe    owner       = CreateTestProbe(name: "owner");
            MemoryStream stream      = CreateMemoryStream("\n\n\n", encoding);
            IActorRef    streamLines = ActorOf(
                StreamLines.Create("just-new-lines-3-buffer-size-2", owner, stream, encoding, bufferSize),
                name: "stream-lines"
                );

            Within(TimeSpan.FromSeconds(5), () =>
            {
                owner.ExpectMsg <StreamLines.StreamLine>(streamLine =>
                {
                    Assert.Equal(String.Empty, streamLine.Line);
                });
                owner.ExpectMsg <StreamLines.StreamLine>(streamLine =>
                {
                    Assert.Equal(String.Empty, streamLine.Line);
                });
                owner.ExpectMsg <StreamLines.StreamLine>(streamLine =>
                {
                    Assert.Equal(String.Empty, streamLine.Line);
                });
                owner.ExpectMsg <StreamLines.EndOfStream>();
                owner.ExpectNoMsg();
            });
        }
コード例 #2
0
        public void MemoryStream_Lines_2_Trailing_NewLine_BufferSize_3()
        {
            const int bufferSize = 3;
            Encoding  encoding   = Encoding.Unicode;

            TestProbe    owner       = CreateTestProbe(name: "owner");
            MemoryStream stream      = CreateMemoryStream("ABCDE\nFGHIJ\n", encoding);
            IActorRef    streamLines = ActorOf(
                StreamLines.Create("lines-2-buffer-size-3", owner, stream, encoding, bufferSize)
                );

            Within(TimeSpan.FromSeconds(5), () =>
            {
                owner.ExpectMsg <StreamLines.StreamLine>(streamLine =>
                {
                    Assert.Equal("ABCDE", streamLine.Line);
                });
                owner.ExpectMsg <StreamLines.StreamLine>(streamLine =>
                {
                    Assert.Equal("FGHIJ", streamLine.Line);
                });
                owner.ExpectMsg <StreamLines.EndOfStream>();
                owner.ExpectNoMsg();
            });
        }
コード例 #3
0
        /// <summary>
        ///		Create a new <see cref="DockerEventParser"/> actor.
        /// </summary>
        /// <param name="correlationId">
        ///		The message correlation Id that will be sent with the stream data.
        /// </param>
        /// <param name="owner">
        ///		The actor that owns the <see cref="DockerEventParser"/> actor (this actor will receive the stream data).
        /// </param>
        /// <param name="stream">
        ///		The <see cref="Stream"/> to read from.
        /// </param>
        /// <param name="bufferSize">
        ///		The buffer size to use when reading from the stream.
        /// </param>
        public DockerEventParser(string correlationId, IActorRef owner, Stream stream, int bufferSize)
        {
            if (String.IsNullOrWhiteSpace(correlationId))
            {
                throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(correlationId)}.", nameof(correlationId));
            }

            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            _owner            = owner;
            _streamLinesProps = StreamLines.Create(correlationId, Self, stream, Encoding.ASCII, bufferSize);

            Receive <StreamLines.StreamLine>(streamLine =>
            {
                var parsedEvent = DockerEvent.FromJson(streamLine.Line, correlationId);

                _owner.Tell(parsedEvent);
            });
            Receive <ReadStream.StreamError>(error =>
            {
                _owner.Tell(error);
            });
            Receive <Terminated>(terminated =>
            {
                if (terminated.ActorRef.Equals(_owner))
                {
                    Log.Debug("Owner '{0}' terminated.", _owner);

                    Context.Stop(Self);
                }
                else if (terminated.ActorRef.Equals(_streamLines))
                {
                    Log.Debug("Streamer '{0}' terminated.", _streamLines);

                    Context.Stop(Self);
                }
                else
                {
                    Unhandled(terminated);
                }
            });
        }