-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly remove subscriptions in ReplayOperator
Fixes a memory leak caused by old subscriptions not being removed properly. In addition, this fixes the edge case where no completion event would be sent for replay subscriptions if the number of requested items was exactly equal to the number of available items. Fixes #1482
- Loading branch information
1 parent
3b71c14
commit 90c2609
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
27 changes: 27 additions & 0 deletions
27
...mentation/src/test/java/io/smallrye/mutiny/operators/multi/replay/ReplayOperatorTest.java
This file contains 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,27 @@ | ||
package io.smallrye.mutiny.operators.multi.replay; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.helpers.test.AssertSubscriber; | ||
|
||
public class ReplayOperatorTest { | ||
|
||
@Test | ||
public void shouldRemoveSubscriptionAfterCompletion() { | ||
// given | ||
var upstream = Multi.createFrom().range(0, 3); | ||
var operator = new ReplayOperator<>(upstream, 3); | ||
|
||
// when | ||
var subscriber = operator.subscribe().withSubscriber(AssertSubscriber.create(3)); | ||
var subscriber2 = operator.subscribe().withSubscriber(AssertSubscriber.create(3)); | ||
|
||
// then | ||
subscriber.assertItems(0, 1, 2).assertCompleted(); | ||
subscriber2.assertItems(0, 1, 2).assertCompleted(); | ||
assertEquals(0, operator.subscriptions.size()); | ||
} | ||
} |