Skip to content

Conversation

@mercyblitz
Copy link
Contributor

This pull request introduces several improvements and enhancements to the Spring Cloud Commons integration, focusing on better support for reactive discovery, utility methods, and configuration flexibility. The most important changes include new utility classes for discovery properties, expanded support for both simple and reactive discovery properties in the service registry, and improved auto-configuration ordering for reactive discovery clients.

Spring Cloud Discovery Enhancements:

  • Added DiscoveryUtils utility class to simplify conversions and instance retrieval between SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties.
  • Updated SimpleServiceRegistry to support both SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties, allowing for more flexible service registration. [1] [2]

Reactive Discovery Client Improvements:

  • Enhanced ReactiveDiscoveryClientAutoConfiguration to use @AutoConfigureAfter for better ordering with related auto-configuration classes, and updated constants accordingly. [1] [2] [3] [4] [5]
  • Improved blocking behavior in ReactiveDiscoveryClientAdapter to avoid blocking in non-blocking threads, increasing compatibility with reactive environments. [1] [2]

Configuration and Utility Updates:

  • Added ConditionalOnUtilEnabled annotation for conditional configuration based on the UtilAutoConfiguration property. [1] [2]
  • Modified ConditionalOnFeaturesEnabled to always match if the property is missing, simplifying its usage. [1] [2]

Other Notable Changes:

  • Improved the getUriString utility to handle default ports when not specified, and added a new setProperties helper for ServiceInstance copying. [1] [2] [3]
  • Updated dependencies and documentation to reflect the latest versions and ensure compatibility with Spring Cloud LoadBalancer. [1] [2]

Update the <revision> property in pom.xml to prepare for the next development iteration.
Introduced constants for SimpleReactiveDiscoveryClientAutoConfiguration and ReactiveCompositeDiscoveryClientAutoConfiguration class names in DiscoveryClientConstants. This improves maintainability and consistency when referencing these class names.
Added assertions for SIMPLE_REACTIVE_DISCOVERY_CLIENT_AUTO_CONFIGURATION_CLASS_NAME and REACTIVE_COMPOSITE_DISCOVERY_CLIENT_AUTO_CONFIGURATION_CLASS_NAME in DiscoveryClientConstantsTest to improve test coverage for recently introduced constants.
Annotated ReactiveDiscoveryClientAutoConfiguration with @AutoConfigureAfter to ensure it is configured after SimpleReactiveDiscoveryClientAutoConfiguration and ReactiveCompositeDiscoveryClientAutoConfiguration. This improves the ordering of auto-configuration classes.
Introduces DiscoveryUtils, a utility class providing helper methods for working with SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties in Spring Cloud. Includes methods for retrieving instance maps and converting between the two property types.
Introduces DiscoveryUtilsTest to verify the behavior of DiscoveryUtils methods, including getInstancesMap and simpleDiscoveryProperties, using both SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties.
Extended SimpleServiceRegistry to support both SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties by overloading constructors and using a utility method to obtain the instances map. This enhances compatibility with reactive discovery configurations.
Introduces a test for the SimpleServiceRegistry constructor that accepts SimpleReactiveDiscoveryProperties. Also refactors testGetStatus to use testSetStatus for improved clarity.
Introduced a utility method to copy properties from a ServiceInstance to a DefaultServiceInstance, streamlining property assignment between these types.
Introduced a new unit test to verify the setProperties method, ensuring that properties are correctly copied between service instances.
Updated ServiceInstanceUtils.setProperties to set the URI on the target DefaultServiceInstance using getUri(source) instead of setting host, port, and secure individually.
Added property copying for DefaultServiceInstance when converting SimpleDiscoveryProperties to SimpleReactiveDiscoveryProperties using setProperties. Also added @nonnull annotations to method parameters for better null safety.
Update ServiceInstanceUtils to use port 443 for secure instances and 80 for non-secure instances when the provided port is less than or equal to zero. This ensures generated URLs are always valid even if the ServiceInstance port is not set.
Added test cases to verify getUriString and getUri methods handle URIs without explicit ports, ensuring default ports (80 for HTTP, 443 for HTTPS) are appended as expected.
Replaces setting URI on target with setting secure, host, and port properties from the source ServiceInstance. This change ensures that DefaultServiceInstance receives these individual properties directly.
Cleaned up formatting by deleting an extra blank line in the getUriString test method.
Introduced LOAD_BALANCER_ENABLED_PROPERTY_NAME to represent the 'spring.cloud.loadbalancer.enabled' property, including relevant documentation and configuration property annotation.
Introduces SpringCloudPropertyConstantsTest to verify the values of property name constants in SpringCloudPropertyConstants.
Introduces a custom annotation that meta-annotates @ConditionalOnProperty for enabling LoadBalancer features based on the 'loadbalancer.enabled' property. This simplifies conditional bean registration for LoadBalancer-related components.
Introduces a unit test to verify the behavior of the @ConditionalOnLoadBalancerEnabled annotation, ensuring the Config bean is conditionally present based on the 'spring.cloud.loadbalancer.enabled' property.
Introduced UTIL_ENABLED_PROPERTY_NAME for enabling or disabling Spring Cloud Util via the 'spring.cloud.util.enabled' property. This addition aligns with the existing pattern for feature toggles and references UtilAutoConfiguration.
Added an assertion to verify the value of UTIL_ENABLED_PROPERTY_NAME in SpringCloudPropertyConstantsTest to ensure the constant is correctly defined.
Moved the @ConditionalOnLoadBalancerEnabled annotation from the inner Config class to the test class itself. Updated testConfigBean to reference the test class instead of the inner Config class, simplifying the test structure.
Introduces a custom annotation that meta-annotates @ConditionalOnProperty for UtilAutoConfiguration, enabling conditional configuration based on the UTIL_ENABLED_PROPERTY_NAME property.
Introduces ConditionalOnUtilEnabledTest to verify bean presence based on the 'spring.cloud.util.enabled' property. Ensures correct conditional behavior in Spring container.
Replaces usage of getClass() with explicit test class references in ConditionalOnUtilEnabledTest and ConditionalOnLoadBalancerEnabledTest to ensure correct bean presence checks.
Replaced imports of isBeanPresent from com.alibaba.spring.util.BeanUtils with io.microsphere.spring.beans.BeanUtils in ConditionalOnUtilEnabledTest and ConditionalOnLoadBalancerEnabledTest to reflect package changes.
Introduced ConditionalOnPropertyEnabledTest as a reusable abstract test class for @ConditionalOnProperty-based conditions. Updated ConditionalOnFeaturesEnabledTest, ConditionalOnUtilEnabledTest, and ConditionalOnLoadBalancerEnabledTest to extend this new base class, reducing code duplication and improving maintainability. Also set matchIfMissing=true for ConditionalOnFeaturesEnabled.
Eliminated the matchIfMissing attribute and its related @AliasFor usage from the ConditionalOnFeaturesEnabled annotation, simplifying the annotation as the property is already set via @ConditionalOnProperty.
Introduced test cases to verify the toList utility method in ReactiveDiscoveryClientAdapter using different schedulers. Ensures correct conversion of Flux to List under various scheduling scenarios.
@sonarqubecloud
Copy link

@mercyblitz mercyblitz merged commit 07c2f47 into main Oct 31, 2025
15 checks passed
@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ Complexity Δ
...ient/discovery/ReactiveDiscoveryClientAdapter.java 100.00% <100.00%> (ø) 9.00 <3.00> (+2.00)
...gure/ReactiveDiscoveryClientAutoConfiguration.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
...ng/cloud/client/discovery/util/DiscoveryUtils.java 100.00% <100.00%> (ø) 4.00 <4.00> (?)
...client/service/registry/SimpleServiceRegistry.java 100.00% <100.00%> (ø) 10.00 <3.00> (+2.00)
...loud/client/service/util/ServiceInstanceUtils.java 100.00% <100.00%> (ø) 21.00 <1.00> (+3.00)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants