-
Notifications
You must be signed in to change notification settings - Fork 48
SSE Client Oversized Messages Handling #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rrwright
wants to merge
4
commits into
apache:main
Choose a base branch
from
rrwright:fix/sse-oversized-message-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
874403d
Add options for how to handle SSE client consumer oversized messages …
rrwright 94c5405
Java API and formatting.
rrwright 1eb8e2c
Pass oversized message to dead letter queue with a type for pattern m…
rrwright 110c5cb
License headers, markdown whitespace, restore test, since annotation
rrwright File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../src/test/java/org/apache/pekko/http/javadsl/settings/OversizedSseStrategySimpleTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.pekko.http.javadsl.settings; | ||
|
||
import org.junit.Test; | ||
import org.scalatestplus.junit.JUnitSuite; | ||
import static org.junit.Assert.*; | ||
|
||
public class OversizedSseStrategySimpleTest extends JUnitSuite { | ||
|
||
@Test | ||
public void testEnumValues() { | ||
// Simple test that the enum values exist and can be converted | ||
OversizedSseStrategy failStream = OversizedSseStrategy.FailStream; | ||
OversizedSseStrategy logAndSkip = OversizedSseStrategy.LogAndSkip; | ||
OversizedSseStrategy truncate = OversizedSseStrategy.Truncate; | ||
OversizedSseStrategy deadLetter = OversizedSseStrategy.DeadLetter; | ||
|
||
assertNotNull("FailStream should not be null", failStream); | ||
assertNotNull("LogAndSkip should not be null", logAndSkip); | ||
assertNotNull("Truncate should not be null", truncate); | ||
assertNotNull("DeadLetter should not be null", deadLetter); | ||
} | ||
|
||
@Test | ||
public void testFromScala() { | ||
// Test that fromScala method works | ||
OversizedSseStrategy strategy = OversizedSseStrategy.fromScala( | ||
org.apache.pekko.http.scaladsl.settings.OversizedSseStrategy.FailStream$.MODULE$ | ||
); | ||
assertEquals("Should convert from Scala FailStream", OversizedSseStrategy.FailStream, strategy); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...rg/apache/pekko/http/javadsl/unmarshalling/sse/EventStreamUnmarshallingOversizedTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.pekko.http.javadsl.unmarshalling.sse; | ||
|
||
import org.apache.pekko.actor.ActorSystem; | ||
import org.apache.pekko.http.javadsl.settings.OversizedSseStrategy; | ||
import org.apache.pekko.http.javadsl.settings.ServerSentEventSettings; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.scalatestplus.junit.JUnitSuite; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class EventStreamUnmarshallingOversizedTest extends JUnitSuite { | ||
|
||
private static ActorSystem system; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
system = ActorSystem.create(); | ||
} | ||
|
||
@AfterClass | ||
public static void teardown() throws Exception { | ||
system.terminate(); | ||
system.getWhenTerminated().toCompletableFuture().get(5, TimeUnit.SECONDS); | ||
} | ||
|
||
@Test | ||
public void testOversizedStrategyEnum() { | ||
// Test that the Java enum can be used with the settings | ||
ServerSentEventSettings settings = | ||
ServerSentEventSettings.create(system) | ||
.withLineLength(50) | ||
.withOversizedStrategy(OversizedSseStrategy.FailStream); | ||
|
||
assertEquals("Should have correct line length", 50, settings.maxLineSize()); | ||
assertEquals("Should have FailStream strategy", | ||
OversizedSseStrategy.FailStream, settings.getOversizedStrategyEnum()); | ||
|
||
// Test all strategies can be set | ||
settings = settings.withOversizedStrategy(OversizedSseStrategy.LogAndSkip); | ||
assertEquals("Should have LogAndSkip strategy", | ||
OversizedSseStrategy.LogAndSkip, settings.getOversizedStrategyEnum()); | ||
|
||
settings = settings.withOversizedStrategy(OversizedSseStrategy.Truncate); | ||
assertEquals("Should have Truncate strategy", | ||
OversizedSseStrategy.Truncate, settings.getOversizedStrategyEnum()); | ||
|
||
settings = settings.withOversizedStrategy(OversizedSseStrategy.DeadLetter); | ||
assertEquals("Should have DeadLetter strategy", | ||
OversizedSseStrategy.DeadLetter, settings.getOversizedStrategyEnum()); | ||
} | ||
|
||
@Test | ||
public void testOversizedStrategyStringCompatibility() { | ||
// Test that the string-based API still works | ||
ServerSentEventSettings settings = | ||
ServerSentEventSettings.create(system) | ||
.withOversizedStrategy("log-and-skip"); | ||
|
||
assertEquals("Should have log-and-skip strategy string", | ||
"log-and-skip", settings.getOversizedStrategy()); | ||
assertEquals("Should have LogAndSkip strategy enum", | ||
OversizedSseStrategy.LogAndSkip, settings.getOversizedStrategyEnum()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...sts/src/test/scala/org/apache/pekko/http/scaladsl/settings/OversizedSseStrategySpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* license agreements; and to You under the Apache License, version 2.0: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This file is part of the Apache Pekko project, which was derived from Akka. | ||
*/ | ||
|
||
package org.apache.pekko.http | ||
package scaladsl | ||
package settings | ||
|
||
import org.apache.pekko.http.scaladsl.settings.OversizedSseStrategy | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpec | ||
|
||
final class OversizedSseStrategySpec extends AnyWordSpec with Matchers { | ||
|
||
"OversizedSseStrategy" should { | ||
"parse valid string values correctly" in { | ||
OversizedSseStrategy.fromString("fail-stream") shouldBe OversizedSseStrategy.FailStream | ||
OversizedSseStrategy.fromString("log-and-skip") shouldBe OversizedSseStrategy.LogAndSkip | ||
OversizedSseStrategy.fromString("truncate") shouldBe OversizedSseStrategy.Truncate | ||
OversizedSseStrategy.fromString("dead-letter") shouldBe OversizedSseStrategy.DeadLetter | ||
} | ||
|
||
"throw IllegalArgumentException for invalid string values" in { | ||
val exception = intercept[IllegalArgumentException] { | ||
OversizedSseStrategy.fromString("invalid-strategy") | ||
} | ||
exception.getMessage should include("Invalid oversized-message-handling: 'invalid-strategy'") | ||
exception.getMessage should include("Valid options are: fail-stream, log-and-skip, truncate, dead-letter") | ||
} | ||
|
||
"convert strategy objects back to strings correctly" in { | ||
OversizedSseStrategy.toString(OversizedSseStrategy.FailStream) shouldBe "fail-stream" | ||
OversizedSseStrategy.toString(OversizedSseStrategy.LogAndSkip) shouldBe "log-and-skip" | ||
OversizedSseStrategy.toString(OversizedSseStrategy.Truncate) shouldBe "truncate" | ||
OversizedSseStrategy.toString(OversizedSseStrategy.DeadLetter) shouldBe "dead-letter" | ||
} | ||
|
||
"handle case-sensitive strings" in { | ||
intercept[IllegalArgumentException] { | ||
OversizedSseStrategy.fromString("FAIL-STREAM") | ||
} | ||
intercept[IllegalArgumentException] { | ||
OversizedSseStrategy.fromString("Fail-Stream") | ||
} | ||
} | ||
|
||
"handle empty and null strings" in { | ||
intercept[IllegalArgumentException] { | ||
OversizedSseStrategy.fromString("") | ||
} | ||
intercept[IllegalArgumentException] { | ||
OversizedSseStrategy.fromString(null) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems dead later is not needed, because we already has a log and skip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was that, while dead letters often just get logged, a pekko user can subscribe/intercept the events that go to dead letters and then handle them if some special logic is needed. So the dead letter queue is potentially more than just logging but also a way to add last-ditch error handling. But maybe it should just send to dead letters without explicitly logging; let logging happen naturally for unhandled dead letters. …changes pushed; I removed logging from the dead letter option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the dead leatter can not be consumed fast , may be an oom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just the standard pekko dead letter queue. So it's a message sent inside the same JVM. I'm pretty sure the dead letter queue is event-driven (I think it's a system actor, but I don't remember if it's actually backed by an actor or not, but it does have an ActorRef). After it's handled, it'll be garbage collected when there's no held reference like any other message. The timing to consume the message wouldn't require any special handling. It would be like any other pekko message.