Skip to content

Conversation

@mercyblitz
Copy link
Contributor

@mercyblitz mercyblitz commented Oct 31, 2025

This pull request introduces several enhancements and new utilities to improve integration and compatibility with Spring Cloud components, particularly around discovery and service registry functionality. The main themes are expanded support for reactive discovery, new utility classes, improvements to property handling, and some minor dependency and code quality adjustments.

Spring Cloud Discovery & Registry Enhancements:

  • Added DiscoveryUtils utility class with methods to convert and extract instance maps between SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties, improving interoperability between blocking and reactive discovery mechanisms.
  • Updated SimpleServiceRegistry to support both SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties, allowing it to register services regardless of the discovery implementation. [1] [2]
  • Improved ReactiveDiscoveryClientAdapter to handle blocking and non-blocking threads safely when converting a Flux to a List, preventing potential runtime issues in reactive contexts. [1] [2]

Spring Cloud Auto-configuration & Constants:

  • Enhanced ReactiveDiscoveryClientAutoConfiguration to support proper ordering with new Spring Cloud reactive discovery auto-configuration classes, and updated related constants in DiscoveryClientConstants. [1] [2] [3] [4] [5]

Property and Conditional Annotation Improvements:

  • Added new property constants for enabling/disabling Spring Cloud LoadBalancer and Util auto-configurations, and introduced the ConditionalOnUtilEnabled annotation for conditional bean registration based on the new property. [1] [2] [3]
  • Simplified and clarified the ConditionalOnFeaturesEnabled annotation to always default to matchIfMissing = true and removed redundant code. [1] [2]

Service Instance Utility Improvements:

  • Added a setProperties method to ServiceInstanceUtils for copying properties between service instances, and improved URI construction to handle default ports when not explicitly set. [1] [2] [3]

Dependency Updates:

  • Added spring-cloud-loadbalancer as an optional dependency in the project POM to support load balancing features.

Introduced DiscoveryUtils for utility methods related to discovery properties and conversions between SimpleDiscoveryProperties and SimpleReactiveDiscoveryProperties. Updated SimpleServiceRegistry to support both property types and refactored constructors. Added new constants for reactive auto-configuration classes and extended related tests to cover new utilities and constructors.
Updated ServiceInstanceUtils.setProperties to set the URI on the target DefaultServiceInstance instead of host, port, and secure fields. Adjusted DiscoveryUtils to use the new setProperties method and updated the related test to verify the new behavior.
Added @nonnull annotations to method parameters in DiscoveryUtils to improve null-safety and clarify API contracts. Also updated method signatures for better consistency.
Default ports are now set to 80 or 443 if the instance port is non-positive. Also, setHost and setPort are now called when copying properties to DefaultServiceInstance, and the URI is set directly from the source instance.
Added test cases to verify that default ports are appended to URIs without explicit port numbers in ServiceInstanceUtils. Also enhanced testGetUri to check for correct default port assignment and consistency with DefaultServiceInstance.getUri.
Included the 'spring-cloud-loadbalancer' dependency as optional in the module's pom.xml to support load balancing features when needed.
Introduced LOAD_BALANCER_ENABLED_PROPERTY_NAME and UTIL_ENABLED_PROPERTY_NAME to define property names for enabling Spring Cloud Load-Balancer and Util features. These additions improve configuration clarity and consistency.
Introduces a JUnit test class to verify the values of constants defined in SpringCloudPropertyConstants. Ensures that property names and prefixes are correctly set.
Introduces a custom annotation that meta-annotates @ConditionalOnProperty for enabling LoadBalancer based on the 'LOAD_BALANCER_ENABLED_PROPERTY_NAME' property. This simplifies conditional bean registration for LoadBalancer-related components.
Introduces ConditionalOnLoadBalancerEnabledTest to verify bean presence based on the 'spring.cloud.loadbalancer.enabled' property. Ensures correct conditional behavior in Spring context.
Introduces a new meta-annotation that applies @ConditionalOnProperty for the UtilAutoConfiguration enabled property. This simplifies 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.
Replaced 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 for @ConditionalOnProperty-based conditions. Updated ConditionalOnFeaturesEnabledTest, ConditionalOnUtilEnabledTest, and ConditionalOnLoadBalancerEnabledTest to extend this new base class, reducing code duplication and improving maintainability. Also updated ConditionalOnFeaturesEnabled to set matchIfMissing=true directly in the annotation.
Updated the toList method in ReactiveDiscoveryClientAdapter to use a non-blocking approach when called from a non-blocking thread, improving compatibility with reactive environments.
Introduced test cases to verify the toList utility method with different schedulers in ReactiveDiscoveryClientAdapterTest. Ensures correct conversion of Flux to List under various scheduling scenarios.
@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 <9.00> (?)
...utoconfigure/DiscoveryClientAutoConfiguration.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
...gure/ReactiveDiscoveryClientAutoConfiguration.java 100.00% <100.00%> (ø) 1.00 <1.00> (?)
...ng/cloud/client/discovery/util/DiscoveryUtils.java 100.00% <100.00%> (ø) 4.00 <4.00> (?)
...oud/client/event/ServiceInstancesChangedEvent.java 100.00% <ø> (ø) 5.00 <0.00> (ø)
...d/client/service/registry/DefaultRegistration.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
...ient/service/registry/InMemoryServiceRegistry.java 100.00% <ø> (ø) 10.00 <0.00> (ø)
...vice/registry/MultipleAutoServiceRegistration.java 100.00% <ø> (ø) 5.00 <0.00> (ø)
.../client/service/registry/MultipleRegistration.java 100.00% <ø> (ø) 16.00 <0.00> (ø)
...ient/service/registry/MultipleServiceRegistry.java 100.00% <ø> (ø) 14.00 <0.00> (ø)
... and 18 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud
Copy link

@mercyblitz mercyblitz merged commit d05e8d0 into release-1.x Oct 31, 2025
32 checks passed
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