Exemplo n.º 1
0
        public void Collecting_multiple_json_should_emit_all_elements_after_input_completes()
        {
            var input  = this.CreatePublisherProbe <ByteString>();
            var output = this.CreateSubscriberProbe <string>();

            var result =
                Source.FromPublisher(input)
                .Via(JsonFraming.ObjectScanner(int.MaxValue))
                .Select(b => b.ToString())
                .RunWith(Sink.FromSubscriber(output), Materializer);

            output.Request(1);
            input.ExpectRequest();
            input.SendNext(ByteString.FromString("[{\"a\":0}, {\"b\":1}, {\"c\":2}, {\"d\":3}, {\"e\":4}]"));
            input.SendComplete();
            Thread.Sleep(100); // another of those races, we don't know the order of next and complete
            output.ExpectNext("{\"a\":0}");
            output.Request(1);
            output.ExpectNext("{\"b\":1}");
            output.Request(1);
            output.ExpectNext("{\"c\":2}");
            output.Request(1);
            output.ExpectNext("{\"d\":3}");
            output.Request(1);
            output.ExpectNext("{\"e\":4}");
            output.Request(1);
            output.ExpectComplete();
        }
Exemplo n.º 2
0
        public void Collecting_multiple_json_should_fail_on_too_large_initial_object()
        {
            var input = @"{ ""name"": ""john"" },{ ""name"": ""jack"" }";

            var result = Source.Single(ByteString.FromString(input))
                         .Via(JsonFraming.ObjectScanner(5))
                         .Select(b => b.ToString())
                         .RunAggregate(new List <string>(), (list, s) =>
            {
                list.Add(s);
                return(list);
            }, Materializer);

            result.Invoking(t => t.Wait(TimeSpan.FromSeconds(3))).Should().Throw <Framing.FramingException>();
        }
Exemplo n.º 3
0
        public void Collecting_multiple_json_should_emit_single_json_element_from_string()
        {
            var input = @"
            { ""name"" : ""john"" }
            { ""name"" : ""jack"" }
           ";

            var result = Source.Single(ByteString.FromString(input))
                         .Via(JsonFraming.ObjectScanner(int.MaxValue))
                         .Take(1)
                         .RunAggregate(new List <string>(), (list, s) =>
            {
                list.Add(s.ToString());
                return(list);
            }, Materializer);

            result.AwaitResult().Should().HaveCount(1).And.Subject.Should().Contain(@"{ ""name"" : ""john"" }");
        }
Exemplo n.º 4
0
        public void Collecting_multiple_json_should_fail_when_2nd_object_is_too_large()
        {
            var input = @"
                 { ""name"": ""john"" },
                 { ""name"": ""jack"" },
                 { ""name"": ""very very long name somehow. how did this happen?"" }"
                        .Split(',').Select(ByteString.FromString);

            var probe = Source.From(input)
                        .Via(JsonFraming.ObjectScanner(48))
                        .RunWith(this.SinkProbe <ByteString>(), Materializer);

            probe.EnsureSubscription();

            probe.Request(1).ExpectNext(ByteString.FromString(@"{ ""name"": ""john"" }"));
            probe.Request(1).ExpectNext(ByteString.FromString(@"{ ""name"": ""jack"" }"));
            probe.Request(1).ExpectError().Message.Should().Contain("exceeded");
        }
Exemplo n.º 5
0
        public void Collecting_multiple_json_should_parse_comma_delimited()
        {
            var input = @"{ ""name"" : ""john"" }, { ""name"" : ""jack"" }, { ""name"" : ""katie"" }
           ";

            var result = Source.Single(ByteString.FromString(input))
                         .Via(JsonFraming.ObjectScanner(int.MaxValue))
                         .RunAggregate(new List <string>(), (list, s) =>
            {
                list.Add(s.ToString());
                return(list);
            }, Materializer);


            result.AwaitResult().Should().BeEquivalentTo(new[]
            {
                @"{ ""name"" : ""john"" }",
                @"{ ""name"" : ""jack"" }",
                @"{ ""name"" : ""katie"" }"
            });
        }
Exemplo n.º 6
0
        public void Collecting_multiple_json_should_parse_chunks_successfully()
        {
            var input = new[]
            {
                ByteString.FromString(@"[{ ""name"" : ""john"" "), ByteString.FromString("},"),
                ByteString.FromString("{ \"na"), ByteString.FromString("me\" : \"jack\" "),
                ByteString.FromString("}]")
            };
            var result = Source.From(input)
                         .Via(JsonFraming.ObjectScanner(int.MaxValue))
                         .RunAggregate(new List <string>(), (list, s) =>
            {
                list.Add(s.DecodeString());
                return(list);
            }, Materializer);


            result.AwaitResult().ShouldAllBeEquivalentTo(new[]
            {
                @"{ ""name"" : ""john"" }",
                @"{ ""name"" : ""jack"" }"
            });
        }
Exemplo n.º 7
0
        public void Collecting_multiple_json_should_parse_json_array()
        {
            var input = @"
           [
            { ""name"" : ""john"" },
            { ""name"" : ""Ég get etið gler án þess að meiða mig"" },
            { ""name"" : ""jack"" },
           ]";

            var result = Source.Single(ByteString.FromString(input))
                         .Via(JsonFraming.ObjectScanner(int.MaxValue))
                         .RunAggregate(new List <string>(), (list, s) =>
            {
                list.Add(s.ToString());
                return(list);
            }, Materializer);

            result.AwaitResult().ShouldAllBeEquivalentTo(new []
            {
                @"{ ""name"" : ""john"" }",
                @"{ ""name"" : ""Ég get etið gler án þess að meiða mig"" }",
                @"{ ""name"" : ""jack"" }"
            });
        }