コード例 #1
0
        public void InputStreamSink_should_return_minus_1_when_read_after_stream_is_completed()
        {
            this.AssertAllStagesStopped(() =>
            {
                var inputStream = Source.Single(_byteString).RunWith(StreamConverters.AsInputStream(), _materializer);

                var r = ReadN(inputStream, _byteString.Count);
                r.Item1.Should().Be(_byteString.Count);
                r.Item2.ShouldBeEquivalentTo(_byteString);

                inputStream.ReadByte().Should().Be(-1);
                inputStream.Close();
            }, _materializer);
        }
コード例 #2
0
        public void InputStreamSink_should_read_next_byte_as_an_int_from_InputStream()
        {
            this.AssertAllStagesStopped(() =>
            {
                var bytes       = ByteString.CopyFrom(new byte[] { 0, 100, 200, 255 });
                var inputStream = Source.Single(bytes).RunWith(StreamConverters.AsInputStream(), _materializer);

                Enumerable.Range(1, 5)
                .Select(_ => inputStream.ReadByte())
                .Should().BeEquivalentTo(new[] { 0, 100, 200, 255, -1 });

                inputStream.Dispose();
            }, _materializer);
        }
コード例 #3
0
        public void InputStreamSink_should_throw_error_when_reactive_stream_is_closed()
        {
            this.AssertAllStagesStopped(() =>
            {
                var t = this.SourceProbe <ByteString>()
                        .ToMaterialized(StreamConverters.AsInputStream(), Keep.Both)
                        .Run(_materializer);
                var probe       = t.Item1;
                var inputStream = t.Item2;

                probe.SendNext(_byteString);
                inputStream.Close();
                probe.ExpectCancellation();

                Action block = () => inputStream.Read(new byte[1], 0, 1);
                block.ShouldThrow <IOException>();
            }, _materializer);
        }
コード例 #4
0
 public void InputStreamSink_should_use_dedicated_default_blocking_io_dispatcher_by_default()
 {
     this.AssertAllStagesStopped(() =>
     {
         var sys          = ActorSystem.Create("dispatcher-testing", Utils.UnboundedMailboxConfig);
         var materializer = ActorMaterializer.Create(sys);
         try
         {
             this.SourceProbe <ByteString>().RunWith(StreamConverters.AsInputStream(), materializer);
             (materializer as ActorMaterializerImpl).Supervisor.Tell(StreamSupervisor.GetChildren.Instance, TestActor);
             var children = ExpectMsg <StreamSupervisor.Children>().Refs;
             var actorRef = children.First(c => c.Path.ToString().Contains("inputStreamSink"));
             Utils.AssertDispatcher(actorRef, "akka.stream.default-blocking-io-dispatcher");
         }
         finally
         {
             Shutdown(sys);
         }
     }, _materializer);
 }
コード例 #5
0
        public void InputStreamSink_should_work_when_read_chunks_smaller_then_stream_chunks()
        {
            this.AssertAllStagesStopped(() =>
            {
                var bytes       = RandomByteString(10);
                var inputStream = Source.Single(bytes).RunWith(StreamConverters.AsInputStream(), _materializer);

                while (bytes.NonEmpty)
                {
                    var expected = bytes.Take(3);
                    bytes        = bytes.Drop(3);

                    var result = ReadN(inputStream, 3);
                    result.Item1.Should().Be(expected.Count);
                    result.Item2.ShouldBeEquivalentTo(expected);
                }

                inputStream.Close();
            }, _materializer);
        }
コード例 #6
0
        public void InputStreamSink_should_block_read_until_get_requested_number_of_bytes_from_upstream()
        {
            this.AssertAllStagesStopped(() =>
            {
                var run =
                    this.SourceProbe <ByteString>()
                    .ToMaterialized(StreamConverters.AsInputStream(), Keep.Both)
                    .Run(_materializer);
                var probe       = run.Item1;
                var inputStream = run.Item2;
                var f           = Task.Run(() => inputStream.Read(new byte[_byteString.Count], 0, _byteString.Count));

                f.Wait(Timeout).Should().BeFalse();

                probe.SendNext(_byteString);
                f.Wait(Timeout).Should().BeTrue();
                f.Result.Should().Be(_byteString.Count);

                probe.SendComplete();
                inputStream.ReadByte().Should().Be(-1);
                inputStream.Close();
            }, _materializer);
        }