This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 96e2e8374d add extra test coverage to JsonFraming code (#2362)
96e2e8374d is described below
commit 96e2e8374df415ec0f9e51e963bde9555f81888c
Author: PJ Fanning <[email protected]>
AuthorDate: Sat Oct 25 13:32:06 2025 +0100
add extra test coverage to JsonFraming code (#2362)
* add extra test coverage to JsonFraming code
* Update JsonFramingSpec.scala
---
.../pekko/stream/scaladsl/JsonFramingSpec.scala | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git
a/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/JsonFramingSpec.scala
b/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/JsonFramingSpec.scala
index 8150274f27..d80422abd1 100644
---
a/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/JsonFramingSpec.scala
+++
b/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/JsonFramingSpec.scala
@@ -52,6 +52,28 @@ class JsonFramingSpec extends PekkoSpec {
"""{ "name" : "jack" }""")
}
+ "parse json array with object size smaller than maximumObjectLength" in {
+ val input =
+ """
+ |[
+ | { "name" : "john" },
+ | { "name" : "Ég get etið gler án þess að meiða mig" },
+ | { "name" : "jack" },
+ |]
+ |""".stripMargin // also should complete once notices end of array
+
+ // Using small maximumObjectLength here. Smaller than the full input,
but larger than each json object.
+ val result =
+
Source.single(ByteString(input)).via(JsonFraming.objectScanner(64)).runFold(Seq.empty[String])
{
+ case (acc, entry) => acc ++ Seq(entry.utf8String)
+ }
+
+ result.futureValue shouldBe Seq(
+ """{ "name" : "john" }""",
+ """{ "name" : "Ég get etið gler án þess að meiða mig" }""",
+ """{ "name" : "jack" }""")
+ }
+
"parse multiple arrays" in {
val input1 =
"""
@@ -524,6 +546,7 @@ class JsonFramingSpec extends PekkoSpec {
val input = List(
"""{ "name": "john" }""",
"""{ "name": "jack" }""",
+ """{ "name": "john2" }, { "name": "jack2" }, { "name": "john3" }, {
"name": "jack3" }""",
"""{ "name": "very very long name somehow. how did this happen?"
}""").map(s => ByteString(s))
val probe =
Source(input).via(JsonFraming.objectScanner(48)).runWith(TestSink.probe)
@@ -532,6 +555,10 @@ class JsonFramingSpec extends PekkoSpec {
probe
.requestNext(ByteString("""{ "name": "john" }"""))
.requestNext(ByteString("""{ "name": "jack" }"""))
+ .requestNext(ByteString("""{ "name": "john2" }"""))
+ .requestNext(ByteString("""{ "name": "jack2" }"""))
+ .requestNext(ByteString("""{ "name": "john3" }"""))
+ .requestNext(ByteString("""{ "name": "jack3" }"""))
.request(1)
.expectError()
.getMessage should include("exceeded")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]