-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix scs sources cannot be appended to Kafka binder context #31715
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
21ce5b3
fix sources cannot be appended
yiliuTo beca90d
add changelog
yiliuTo 7efce9c
fix checkstyle
yiliuTo d912d1f
Merge branch 'main' into fix-binder-source-append
yiliuTo d59fa73
fix changelog error
yiliuTo 02cbda9
modify the way to read/write spring.main.sources
yiliuTo 53a36de
add tests
yiliuTo 9b195fc
fix checkstyle
yiliuTo d66f7eb
remove duplicated line
yiliuTo 8c2cf93
supress spotbug error
yiliuTo 4d9a065
fix spotbug
yiliuTo e868918
fix spotbug
yiliuTo 03f8896
Merge branch 'main' into fix-binder-source-append
yiliuTo 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
121 changes: 121 additions & 0 deletions
121
...azure/spring/cloud/autoconfigure/kafka/BindingServicePropertiesBeanPostProcessorTest.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,121 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| package com.azure.spring.cloud.autoconfigure.kafka; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.springframework.cloud.stream.config.BinderProperties; | ||
| import org.springframework.cloud.stream.config.BindingServiceProperties; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| import static com.azure.spring.cloud.autoconfigure.kafka.AzureKafkaSpringCloudStreamConfiguration.AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| class BindingServicePropertiesBeanPostProcessorTest { | ||
|
|
||
| private final BindingServicePropertiesBeanPostProcessor bpp = new BindingServicePropertiesBeanPostProcessor(); | ||
|
|
||
| @Test | ||
| void testReadSpringMainPropertiesMapWithoutOriginalValues() { | ||
| Map<String, Object> env = new LinkedHashMap<>(); | ||
| Map<String, Object> mainPropertiesMap = buildSpringMainPropertiesMap(env, null, null, null); | ||
| assertSame(mainPropertiesMap, ((Map<String, Object>) env.get("spring")).get("main")); | ||
| } | ||
|
|
||
| @Test | ||
| void testReadSpringMainPropertiesMapWithSpringProp() { | ||
| Map<String, Object> env = new LinkedHashMap<>(); | ||
| Map<String, Object> mainPropertiesMap = buildSpringMainPropertiesMap(env, "profiles", "active", "dev"); | ||
|
|
||
| assertEquals("dev", ((Map<String, Map<String, Object>>) env.get("spring")).get("profiles").get("active")); | ||
| assertSame(mainPropertiesMap, ((Map<String, Object>) env.get("spring")).get("main")); | ||
| } | ||
|
|
||
| @Test | ||
| void testReadSpringMainPropertiesMapWithMainProp() { | ||
| Map<String, Object> env = new LinkedHashMap<>(); | ||
| Map<String, Object> mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "banner-mode", "test"); | ||
|
|
||
| assertEquals("test", ((Map<String, Map<String, Object>>) env.get("spring")).get("main").get("banner-mode")); | ||
| assertSame(mainPropertiesMap, ((Map<String, Object>) env.get("spring")).get("main")); | ||
| } | ||
|
|
||
| @Test | ||
| void testReadSpringMainPropertiesMapWithSourcesProp() { | ||
| Map<String, Object> env = new LinkedHashMap<>(); | ||
| Map<String, Object> mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "sources", "test"); | ||
|
|
||
| assertEquals("test", ((Map<String, Map<String, Object>>) env.get("spring")).get("main").get("sources")); | ||
| assertSame(mainPropertiesMap, ((Map<String, Object>) env.get("spring")).get("main")); | ||
| } | ||
|
|
||
| @Test | ||
| void testConfigureBinderSources() { | ||
| Map<String, Object> env = new LinkedHashMap<>(); | ||
| Map<String, Object> mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "sources", "test"); | ||
| bpp.configureBinderSources(mainPropertiesMap); | ||
| assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS + ",test", ((Map<String, Map<String, Object>>) env.get("spring")).get("main").get("sources")); | ||
|
|
||
| env.clear(); | ||
| mainPropertiesMap = buildSpringMainPropertiesMap(env, "main", "profiles", "active"); | ||
| bpp.configureBinderSources(mainPropertiesMap); | ||
| assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map<String, Map<String, Object>>) env.get("spring")).get("main").get("sources")); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindKafkaByDefault() { | ||
| BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); | ||
| bpp.postProcessBeforeInitialization(bindingServiceProperties, null); | ||
| Map<String, Object> env = bindingServiceProperties.getBinders().get("kafka") | ||
| .getEnvironment(); | ||
| assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map<String, Map<String, Object>>) env.get("spring")).get("main").get("sources")); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| void testBindKafkaByName() { | ||
| BinderProperties binderProperties = new BinderProperties(); | ||
| Map<String, BinderProperties> binders = new HashMap<>(); | ||
| binders.put("kafka", binderProperties); | ||
| BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); | ||
| bindingServiceProperties.setBinders(binders); | ||
|
|
||
| bpp.postProcessBeforeInitialization(bindingServiceProperties, null); | ||
| Map<String, Object> env = bindingServiceProperties.getBinders().get("kafka") | ||
| .getEnvironment(); | ||
| assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map<String, Map<String, Object>>) env.get("spring")).get("main").get("sources")); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindKafkaByType() { | ||
| BinderProperties binderProperties = new BinderProperties(); | ||
| Map<String, BinderProperties> binders = new HashMap<>(); | ||
| binders.put("test", binderProperties); | ||
| binderProperties.setType("kafka"); | ||
| BindingServiceProperties bindingServiceProperties = new BindingServiceProperties(); | ||
| bindingServiceProperties.setBinders(binders); | ||
|
|
||
| bpp.postProcessBeforeInitialization(bindingServiceProperties, null); | ||
| Map<String, Object> env = bindingServiceProperties.getBinders().get("test") | ||
| .getEnvironment(); | ||
| assertEquals(AZURE_KAFKA_SPRING_CLOUD_STREAM_CONFIGURATION_CLASS, ((Map<String, Map<String, Object>>) env.get("spring")).get("main").get("sources")); | ||
| } | ||
|
|
||
| private Map<String, Object> buildSpringMainPropertiesMap(Map<String, Object> env, String secondProperty, String thirdProperty, String value) { | ||
| if (StringUtils.hasText(secondProperty)) { | ||
| Map<String, Object> second = new LinkedHashMap<>(); | ||
| second.put(thirdProperty, value); | ||
| Map<String, Object> first = new LinkedHashMap<>(); | ||
| first.put(secondProperty, second); | ||
| env.put("spring", first); | ||
| } | ||
| return bpp.readSpringMainPropertiesMap(env); | ||
| } | ||
|
|
||
| } |
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.