Skip to content

Commit

Permalink
Merge branch '3.1.x' into 3.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Feb 25, 2025
2 parents 870360a + 2cc8c34 commit bb200cd
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2024 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.
Expand Down Expand Up @@ -38,6 +38,11 @@ public class ConfigurationWatcherConfigurationProperties {
*/
public static final String KAFKA = "bus-kafka";

/**
* not AMQP or KAFKA profile name.
*/
static final String NOT_AMQP_NOT_KAFKA = "!" + AMQP + " & !" + KAFKA;

/**
* label to enable refresh/restart when using configmaps.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 the original author or authors.
* Copyright 2013-2025 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.
Expand Down Expand Up @@ -29,6 +29,7 @@

import static org.springframework.cloud.kubernetes.configuration.watcher.ConfigurationWatcherConfigurationProperties.AMQP;
import static org.springframework.cloud.kubernetes.configuration.watcher.ConfigurationWatcherConfigurationProperties.KAFKA;
import static org.springframework.cloud.kubernetes.configuration.watcher.ConfigurationWatcherConfigurationProperties.NOT_AMQP_NOT_KAFKA;

/**
* @author wind57
Expand All @@ -47,6 +48,7 @@ BusRefreshTrigger busRefreshTrigger(ApplicationEventPublisher applicationEventPu

@Bean
@ConditionalOnMissingBean
@Profile({ NOT_AMQP_NOT_KAFKA })
HttpRefreshTrigger httpRefreshTrigger(KubernetesInformerReactiveDiscoveryClient client,
ConfigurationWatcherConfigurationProperties properties, WebClient webClient) {
return new HttpRefreshTrigger(client, properties, webClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright 2013-2025 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 org.springframework.cloud.kubernetes.configuration.watcher;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.cloud.kubernetes.client.discovery.reactive.KubernetesInformerReactiveDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.web.reactive.function.client.WebClient;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.kubernetes.configuration.watcher.ConfigurationWatcherConfigurationProperties.AMQP;
import static org.springframework.cloud.kubernetes.configuration.watcher.ConfigurationWatcherConfigurationProperties.KAFKA;

/**
* @author wind57
*/
class RefreshTriggerAutoConfigurationTests {

private ApplicationContextRunner applicationContextRunner;

@Test
void amqpOnly() {
setup(AMQP);
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(BusRefreshTrigger.class);
assertThat(context).doesNotHaveBean(HttpRefreshTrigger.class);
});
}

@Test
void kafkaOnly() {
setup(KAFKA);
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(BusRefreshTrigger.class);
assertThat(context).doesNotHaveBean(HttpRefreshTrigger.class);
});
}

@Test
void kafkaAndAmqp() {
setup(KAFKA + " , " + AMQP);
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(BusRefreshTrigger.class);
assertThat(context).doesNotHaveBean(HttpRefreshTrigger.class);
});
}

@Test
void notAmqp() {
setup("not-" + AMQP);
applicationContextRunner.run(context -> {
assertThat(context).doesNotHaveBean(BusRefreshTrigger.class);
assertThat(context).hasSingleBean(HttpRefreshTrigger.class);
});
}

@Test
void notKafka() {
setup("not-" + KAFKA);
applicationContextRunner.run(context -> {
assertThat(context).doesNotHaveBean(BusRefreshTrigger.class);
assertThat(context).hasSingleBean(HttpRefreshTrigger.class);
});
}

@Test
void amqpNotKafka() {
setup(AMQP + "," + "not-" + KAFKA);
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(BusRefreshTrigger.class);
assertThat(context).doesNotHaveBean(HttpRefreshTrigger.class);
});
}

@Test
void kafkaNotAmqp() {
setup(KAFKA + "," + "not-" + AMQP);
applicationContextRunner.run(context -> {
assertThat(context).hasSingleBean(BusRefreshTrigger.class);
assertThat(context).doesNotHaveBean(HttpRefreshTrigger.class);
});
}

private void setup(String activeProfiles) {
applicationContextRunner = new ApplicationContextRunner()
.withUserConfiguration(TestConfig.class, RefreshTriggerAutoConfiguration.class)
.withPropertyValues("spring.main.cloud-platform=kubernetes", "spring.profiles.active=" + activeProfiles);
}

@TestConfiguration
static class TestConfig {

@Bean
@Primary
BusProperties busProperties() {
return new BusProperties();
}

@Bean
@Primary
KubernetesInformerReactiveDiscoveryClient client() {
return Mockito.mock(KubernetesInformerReactiveDiscoveryClient.class);
}

@Bean
@Primary
ConfigurationWatcherConfigurationProperties configurationWatcherConfigurationProperties() {
return new ConfigurationWatcherConfigurationProperties();
}

@Primary
@Bean
WebClient webClient() {
return Mockito.mock(WebClient.class);
}

}

}

0 comments on commit bb200cd

Please sign in to comment.