-
Notifications
You must be signed in to change notification settings - Fork 54
Make AbstractMomSubscriber thread-safe #2020
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
Merged
rogersteblerbsi
merged 1 commit into
releases/24.2
from
features/rsb/24.2/411785_threadSafeMomSubscriber
Feb 19, 2026
Merged
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions
78
...e.scout.rt.mom.api.test/src/test/java/org/eclipse/scout/rt/mom/api/MomSubscriberTest.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,78 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2026 BSI Business Systems Integration AG | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.eclipse.scout.rt.mom.api; | ||
|
|
||
| import static org.mockito.Mockito.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.eclipse.scout.rt.platform.job.IFuture; | ||
| import org.eclipse.scout.rt.platform.job.Jobs; | ||
| import org.junit.Test; | ||
|
|
||
| public class MomSubscriberTest { | ||
|
|
||
| @Test | ||
| public void testDispose() { | ||
| ISubscription subscriptionMock = mock(ISubscription.class); | ||
| AbstractMomSubscriber subscriber = new AbstractMomSubscriber() { | ||
| @Override | ||
| public void subscribe() { | ||
| registerSubscription(subscriptionMock); | ||
| } | ||
| }; | ||
| subscriber.subscribe(); | ||
| subscriber.dispose(); | ||
| verify(subscriptionMock, times(1)).dispose(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConcurrentSubscriptions() { | ||
| List<ISubscription> subscriptionMocks = Stream.generate(() -> mock(ISubscription.class)) | ||
| .limit(10000) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| AbstractMomSubscriber subscriber = new AbstractMomSubscriber() { | ||
| @Override | ||
| public void subscribe() { | ||
| subscriptionMocks.stream().parallel().forEach(this::registerSubscription); | ||
| } | ||
| }; | ||
|
|
||
| subscriber.subscribe(); | ||
| subscriber.dispose(); | ||
| for (ISubscription subscriptionMock : subscriptionMocks) { | ||
| verify(subscriptionMock, times(1)).dispose(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testConcurrentModification() { | ||
| List<ISubscription> subscriptionMocks = Stream.generate(() -> mock(ISubscription.class)) | ||
| .limit(100_000) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| AbstractMomSubscriber subscriber = new AbstractMomSubscriber() { | ||
| @Override | ||
| public void subscribe() { | ||
| for (ISubscription subscriptionMock : subscriptionMocks) { | ||
| registerSubscription(subscriptionMock); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| subscriber.subscribe(); // insert initial subscriptions | ||
| IFuture<Void> subscriptionFuture = Jobs.schedule(subscriber::subscribe, Jobs.newInput()); // insert more subscriptions async | ||
| subscriber.dispose(); // start disposing while new subscriptions are being added | ||
| subscriptionFuture.awaitDone(); | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.