Repository navigation
fix(server): resolve Hazelcast notification trigger independent of auto-configuration order #5726
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
YadavKshitiz
wants to merge
4
commits into
codecentric:master
Choose a base branch
from
YadavKshitiz:fix/5716-hazelcast-notification-dedup
base: master
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.
+249
−42
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
74194d1
fix(server): create HazelcastNotificationTrigger for property-configu…
YadavKshitiz e25b482
fix(server): expose notification filters map instead of auto-creating…
YadavKshitiz b2a9b29
docs(server): clarify sent-notifications map Javadoc and FilteringNot…
YadavKshitiz 4c5b3ee
test(server): cover @Primary FilteringNotifier wrapping a property-co…
YadavKshitiz 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
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
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
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
162 changes: 162 additions & 0 deletions
162
...va/de/codecentric/boot/admin/server/config/AdminServerHazelcastAutoConfigurationTest.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,162 @@ | ||
| /* | ||
| * Copyright 2014-2026 the original author or authors. | ||
| * | ||
| * Licensed 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 | ||
| * | ||
| * https://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 de.codecentric.boot.admin.server.config; | ||
|
|
||
| import java.util.concurrent.ConcurrentMap; | ||
|
|
||
| import com.hazelcast.config.Config; | ||
| import com.hazelcast.map.IMap; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
| import org.springframework.boot.hazelcast.autoconfigure.HazelcastAutoConfiguration; | ||
| import org.springframework.boot.http.client.autoconfigure.reactive.ReactiveHttpClientAutoConfiguration; | ||
| import org.springframework.boot.test.context.runner.WebApplicationContextRunner; | ||
| import org.springframework.boot.webclient.autoconfigure.WebClientAutoConfiguration; | ||
| import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Primary; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; | ||
| import de.codecentric.boot.admin.server.notify.HazelcastNotificationTrigger; | ||
| import de.codecentric.boot.admin.server.notify.NotificationTrigger; | ||
| import de.codecentric.boot.admin.server.notify.Notifier; | ||
| import de.codecentric.boot.admin.server.notify.filter.FilteringNotifier; | ||
| import de.codecentric.boot.admin.server.notify.filter.NotificationFilter; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class AdminServerHazelcastAutoConfigurationTest { | ||
|
|
||
| private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() | ||
| .withConfiguration(AutoConfigurations.of(ReactiveHttpClientAutoConfiguration.class, | ||
| WebClientAutoConfiguration.class, HazelcastAutoConfiguration.class, WebMvcAutoConfiguration.class, | ||
| AdminServerHazelcastAutoConfiguration.class, AdminServerAutoConfiguration.class, | ||
| AdminServerNotifierAutoConfiguration.class)) | ||
| .withUserConfiguration(AdminServerMarkerConfiguration.class, HazelcastOnlyConfig.class); | ||
|
|
||
| @Test | ||
| void should_use_hazelcast_trigger_for_property_configured_notifier() { | ||
| this.contextRunner.withPropertyValues("spring.boot.admin.notify.slack.webhook-url:https://example.com") | ||
| .run((context) -> { | ||
| assertThat(context).hasSingleBean(NotificationTrigger.class); | ||
| assertThat(context).getBean(NotificationTrigger.class).isInstanceOf(HazelcastNotificationTrigger.class); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void should_use_hazelcast_trigger_for_multiple_property_configured_notifiers() { | ||
| this.contextRunner | ||
| .withPropertyValues("spring.boot.admin.notify.slack.webhook-url:https://example.com", | ||
| "spring.boot.admin.notify.discord.webhook-url:https://example.com") | ||
| .run((context) -> { | ||
| assertThat(context).hasSingleBean(NotificationTrigger.class); | ||
| assertThat(context).getBean(NotificationTrigger.class).isInstanceOf(HazelcastNotificationTrigger.class); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void should_use_plain_trigger_when_hazelcast_is_disabled() { | ||
| this.contextRunner | ||
| .withPropertyValues("spring.boot.admin.hazelcast.enabled:false", | ||
| "spring.boot.admin.notify.slack.webhook-url:https://example.com") | ||
| .run((context) -> { | ||
| assertThat(context).hasSingleBean(NotificationTrigger.class); | ||
| assertThat(context).getBean(NotificationTrigger.class) | ||
| .isNotInstanceOf(HazelcastNotificationTrigger.class); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void should_start_and_use_hazelcast_trigger_with_single_user_defined_notifier() { | ||
| this.contextRunner.withUserConfiguration(UserNotifierConfig.class).run((context) -> { | ||
| assertThat(context).hasNotFailed(); | ||
| assertThat(context).hasSingleBean(NotificationTrigger.class); | ||
| assertThat(context).getBean(NotificationTrigger.class).isInstanceOf(HazelcastNotificationTrigger.class); | ||
| assertThat(context).doesNotHaveBean(FilteringNotifier.class); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void should_share_filters_map_with_user_defined_filtering_notifier() { | ||
| this.contextRunner.withUserConfiguration(UserFilteringNotifierConfig.class).run((context) -> { | ||
| assertThat(context).hasNotFailed(); | ||
| assertThat(context).getBean(NotificationTrigger.class).isInstanceOf(HazelcastNotificationTrigger.class); | ||
| assertThat(context.getBean(FilteringNotifier.class)).extracting("filters").isInstanceOf(IMap.class); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| void should_start_with_primary_filtering_notifier_wrapping_property_configured_notifier() { | ||
| this.contextRunner.withUserConfiguration(PrimaryFilteringNotifierConfig.class) | ||
| .withPropertyValues("spring.boot.admin.notify.slack.webhook-url:https://example.com") | ||
| .run((context) -> { | ||
| assertThat(context).hasNotFailed(); | ||
| assertThat(context).hasSingleBean(FilteringNotifier.class); | ||
| assertThat(context).getBean(NotificationTrigger.class).isInstanceOf(HazelcastNotificationTrigger.class); | ||
| }); | ||
| } | ||
|
|
||
| public static class HazelcastOnlyConfig { | ||
|
|
||
| @Bean | ||
| public Config config() { | ||
| return new Config(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static class UserNotifierConfig { | ||
|
|
||
| @Bean | ||
| public Notifier notifier() { | ||
| return (event) -> Mono.empty(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static class UserFilteringNotifierConfig { | ||
|
|
||
| @Bean | ||
| public Notifier delegateNotifier() { | ||
| return (event) -> Mono.empty(); | ||
| } | ||
|
|
||
| @Bean | ||
| @Primary | ||
| public FilteringNotifier filteringNotifier(@Qualifier("delegateNotifier") Notifier delegate, | ||
| InstanceRepository repository, | ||
| @Qualifier("notificationFiltersMap") ConcurrentMap<String, NotificationFilter> filters) { | ||
| return new FilteringNotifier(delegate, repository, filters); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static class PrimaryFilteringNotifierConfig { | ||
|
|
||
| @Bean | ||
| @Primary | ||
| public FilteringNotifier filteringNotifier(@Qualifier("slackNotifier") Notifier delegate, | ||
| InstanceRepository repository, | ||
| @Qualifier("notificationFiltersMap") ConcurrentMap<String, NotificationFilter> filters) { | ||
| return new FilteringNotifier(delegate, repository, filters); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
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.
Like for the other maps already present, I don't think it's necessary to have them declared as beans explicitly.