Compare commits

...
Author SHA1 Message Date
Olga Maciaszek-Sharma 3ad4f3d7e8 Switch to Apache HC5 HttpClient. 2022-10-11 14:15:41 +02:00
buildmaster e5ccca6c2b Going back to snapshots 2022-10-06 01:44:01 +00:00
buildmaster 5ec430efb8 Update SNAPSHOT to 4.0.0-M1 2022-10-06 01:42:39 +00:00
spencergibb f6f4e0d80d Fixes css and js for eureka dashboard 2022-10-04 17:13:04 -04:00
spencergibb e8976ae344 Upgrade to 2.0.0-rc.3
Fixes gh-4122
2022-10-04 13:52:33 -04:00
buildmaster 09adda65c0 Bumping versions 2022-10-04 14:11:07 +00:00
spencergibb a3cfba7e3b Migrates to new AutoConfiguration.imports 2022-10-03 17:32:21 -04:00
spencergibb f76de4c481 injects OptionalArgs 2022-10-03 17:28:37 -04:00
spencergibb 6316953236 Fixes test assertion 2022-10-03 17:28:02 -04:00
spencergibb 3a91f2372c Disables test 2022-10-03 17:27:49 -04:00
spencergibb 4f2ddfd2ec removes unused tests 2022-10-03 17:27:35 -04:00
spencergibb dff98c48dd Adds / path mapping to test 2022-10-03 17:27:23 -04:00
spencergibb 4c77b6dd5d Migrates to new AutoConfiguration.imports 2022-10-03 17:27:02 -04:00
Spencer Gibb d0f8fbe274 Updates eureka to version 2.0.0-SNAPSHOT (#4120)
* Updates eureka to version 2.0.0-SNAPSHOT

* Updates to renamed jersey3 modules and classes

* Removes unused import

* Adds netflix snapshot repository
2022-10-03 16:34:25 -04:00
Olga Maciaszek-Sharma 67c227d9d7 Merge remote-tracking branch 'origin/3.1.x' 2022-09-01 15:59:37 +02:00
Olga Maciaszek-Sharma a30b87cdda Remove unused Codacy badge. Fixes gh-4105. 2022-09-01 15:58:57 +02:00
Olga Maciaszek-Sharma 01f72ff328 Merge remote-tracking branch 'origin/3.1.x' 2022-08-31 11:45:29 +02:00
Vilius Šumskas 20a3671055 Fix CSS and JS on Eureka Dashboard (#4096)
* Fix CSS and JS on Eureka Dashboard

The dashboard interface was broken after changes in
https://github.com/spring-cloud/spring-cloud-netflix/pull/4075.
Bootstrap has changed a lot since version 3.

This patch converts dashboard's CSS to Bootstrap v.5 API.

Also, remove unnecessary JavaScript. Table striping and tab activation
is done completely in Bootstrap now. While at it, remove IE support.
It is not supported in Bootstrap v.5 anymore.

* Fix dashboard navigation tests
2022-08-31 11:42:26 +02:00
spencergibb 01c2c04162 Removes compile dependency on config server.
Configures duplicate-finder-maven-plugin to ignore tests.
2022-08-05 16:32:28 -04:00
spencergibb 2497900d3e Removes compile dependency on config server.
Configures duplicate-finder-maven-plugin to ignore tests.
2022-08-05 16:29:25 -04:00
Olga Maciaszek-Sharma 65fb24e321 Fix merge. 2022-07-01 15:38:58 +02:00
Olga Maciaszek-Sharma 0188b2511d Merge remote-tracking branch 'origin/3.1.x' 2022-07-01 15:38:18 +02:00
Olga Maciaszek-Sharma c6a7ebb918 merge 3.0.x 2022-07-01 15:37:50 +02:00
buildmaster 9d6e3523dd Bumping versions 2022-06-30 14:26:40 +00:00
buildmaster 38e6b0b2b5 Bumping versions to 3.0.7-SNAPSHOT after release 2022-06-29 22:12:30 +00:00
buildmaster 1229e07636 Going back to snapshots 2022-06-29 22:12:30 +00:00
buildmaster 852e72f5e6 Update SNAPSHOT to 3.0.6 2022-06-29 22:10:18 +00:00
Olga Maciaszek-Sharma 8b2b6b5115 Update license dates for bugfix backport. 2022-06-29 15:42:19 +02:00
Weix Sun f015f5cad4 Fixes gh-4032 (#4086) 2022-06-29 15:14:48 +02:00
Olga Maciaszek-Sharma 612b6edb41 Add new tests and refactor. 2022-06-28 18:52:06 +02:00
Olga Maciaszek-Sharma b633c8af96 Bugfix. 2022-06-28 18:51:57 +02:00
Olga Maciaszek-Sharma 079ae668c0 Add resolving Health Status from composite indicators. 2022-06-28 18:51:44 +02:00
Olga Maciaszek-Sharma 3af988adcf Merge remote-tracking branch 'origin/3.1.x' 2022-06-13 18:58:12 +02:00
Olga Maciaszek-Sharma a5e038cf13 Do not set status to down. (#4102) 2022-06-13 18:57:46 +02:00
Ryan Baxter b8af1db32f Fixing compilation error 2022-06-03 16:20:41 -04:00
Ryan Baxter d831ca31c3 Merge branch '3.1.x' 2022-06-03 16:10:14 -04:00
Ryan Baxter ec903900c9 Return empty list in bootstraper when discovery client disabled. (#4099) 2022-06-03 16:03:21 -04:00
spencergibb 9b6b0aba4e Bumps to next snapshot version 2022-05-27 13:32:52 -04:00
buildmaster e5a52ee5ac Update SNAPSHOT to 3.1.3 2022-05-27 13:28:08 -04:00
Spencer Gibb 6548e0dab6 don't upload docs to maven central 2022-05-26 12:06:17 -04:00
Olga Maciaszek-Sharma 9e1f7f6aad Fix @LocalServerPort imports. 2022-05-18 14:04:49 +02:00
buildmaster 2899b42107 Bumping versions 2022-04-28 14:26:35 +00:00
buildmaster a06f6e98bd Bumping versions 2022-04-27 14:26:45 +00:00
buildmaster 2b51d15d87 Bumping versions to 3.1.3-SNAPSHOT after release 2022-04-27 10:49:16 +00:00
buildmaster cb3cc3234f Going back to snapshots 2022-04-27 10:49:15 +00:00
buildmaster b11c4c9b20 Update SNAPSHOT to 3.1.2 2022-04-27 10:47:33 +00:00
Olga Maciaszek-Sharma 4b5d0a0b86 Revert "Update SNAPSHOT to 3.1.2"
This reverts commit 96b10d40c3.
2022-04-27 11:08:20 +02:00
Olga Maciaszek-Sharma 4fda5b40b8 Revert "Going back to snapshots"
This reverts commit 872d64494b.
2022-04-27 11:08:15 +02:00
Olga Maciaszek-Sharma 719688f4c8 Revert "Bumping versions to 3.1.3-SNAPSHOT after release"
This reverts commit 162b1c8a9b.
2022-04-27 11:08:12 +02:00
buildmaster 162b1c8a9b Bumping versions to 3.1.3-SNAPSHOT after release 2022-04-26 15:58:48 +00:00
buildmaster 872d64494b Going back to snapshots 2022-04-26 15:58:48 +00:00
buildmaster 96b10d40c3 Update SNAPSHOT to 3.1.2 2022-04-26 15:57:09 +00:00
Marcin Grzejszczak 28f1848b85 Update runAcceptanceTests.sh 2022-04-20 13:05:58 +02:00
Marcin Grzejszczak 83c74b0017 Update runAcceptanceTests.sh 2022-04-20 13:05:45 +02:00
Olga Maciaszek-Sharma 27ac3379f6 Remove deprecated constructor. 2022-04-13 14:02:52 +02:00
Olga Maciaszek-Sharma e38cd1ef66 Merge remote-tracking branch 'origin/3.1.x' 2022-04-13 13:59:57 +02:00
Weix Sun a1a6ee244c Fixes gh-4032 (#4086) 2022-04-13 13:00:41 +02:00
Weix Sun 2a31d0e121 Fixes circleci (#4087) 2022-04-12 12:00:59 +02:00
Olga Maciaszek-Sharma 93913603eb Merge remote-tracking branch 'origin/3.1.x' 2022-03-18 13:12:56 +01:00
alceil 6aafd20d60 Documented eureka.server.defaultOpenForTrafficCount (#4083) 2022-03-18 13:09:02 +01:00
Olga Maciaszek-Sharma cdf89659e8 Merge remote-tracking branch 'origin/3.1.x' 2022-03-17 12:26:23 +01:00
Olga Maciaszek-Sharma 1efa843ed8 Get health from composite indicators (#4074) 2022-03-17 12:25:57 +01:00
Olga Maciaszek-Sharma fab3190ca4 Merge remote-tracking branch 'origin/3.1.x' 2022-03-17 11:10:30 +01:00
Koki Igarashi eafecd3b6a Documents the eureka version in the context path (#4079) 2022-03-17 10:55:24 +01:00
Olga Maciaszek-Sharma 2c22afa8bd Upgrade wro4j-maven-plugin to 0.10.1. Fixes gh-4076. 2022-03-11 16:31:59 +01:00
Olga Maciaszek-Sharma e33e5a54f6 Merge remote-tracking branch 'origin/3.1.x' 2022-03-11 16:30:58 +01:00
Olga Maciaszek-Sharma e757479f85 Upgrade Eureka Server GUI dependencies and components. (#4075) 2022-03-11 16:23:06 +01:00
buildmaster c350c88267 Bumping versions 2022-02-24 14:29:24 +00:00
buildmaster 827be605b3 Bumping versions 2022-02-24 07:49:06 +00:00
Olga Maciaszek-Sharma e5ba2575e6 Merge remote-tracking branch 'origin/3.1.x' 2022-02-22 17:51:59 +01:00
Olga Maciaszek-Sharma 8f9797627f Merge remote-tracking branch 'MI-cool/reduceHighLoadOnRenew' into 3.1.x 2022-02-22 17:24:48 +01:00
buildmaster 75d77cd38e Bumping versions to 3.1.2-SNAPSHOT after release 2022-02-17 16:51:33 +00:00
buildmaster b518187da8 Going back to snapshots 2022-02-17 16:51:33 +00:00
buildmaster c94923d0ce Update SNAPSHOT to 3.1.1 2022-02-17 16:49:51 +00:00
spencergibb 2532e3a263 Updates to version 4.0.0
Updates for java 17, framework 6, boot 3 and jakarta ee

Eureka still not compatible with jakarta ee
2022-01-13 16:12:57 -05:00
spencergibb fef3a9ea78 Updates to version 4.0.0
Updates for java 17, framework 6, boot 3 and jakarta ee

Eureka still not compatible with jakarta ee
2022-01-13 12:15:34 -05:00
Olga MaciaszekSharma dd80e2b23b Update license entries. 2022-01-11 19:07:29 +01:00
Olga MaciaszekSharma 872ac78396 Update license entries. 2022-01-11 18:58:20 +01:00
Olga MaciaszekSharma 91790a55a7 Merge remote-tracking branch 'origin/3.0.x' into 3.1.x 2022-01-11 15:06:43 +01:00
Olga MaciaszekSharma 927a51c21c Fix typo in EurekaController. 2022-01-11 15:06:18 +01:00
Olga MaciaszekSharma 39b4c8b578 Merge remote-tracking branch 'origin/3.0.x' into 3.1.x 2022-01-11 14:32:08 +01:00
Olga MaciaszekSharma 5da06943c0 Regenerate docs. 2022-01-11 14:08:00 +01:00
TAN ZHENG 912fa949ff Update spring-cloud-netflix.adoc 2022-01-11 14:03:39 +01:00
spencergibb 292b2ec83e Adds .sdkmanrc 2022-01-04 12:06:44 -05:00
MI-cool d5637172f2 fix test testRenew() 2021-12-27 14:45:50 +08:00
MI-cool b7bfc42697 remove unused import 2021-12-27 12:37:10 +08:00
buildmaster a86dba2659 Bumping versions to 3.0.6-SNAPSHOT after release 2021-12-15 16:56:44 +00:00
buildmaster 76ab698306 Going back to snapshots 2021-12-15 16:56:44 +00:00
buildmaster df6df5d1dd Update SNAPSHOT to 3.0.5 2021-12-15 16:55:17 +00:00
MI-cool 53392471a5 reduce high load caused by EurekaInstanceRenewedEvent 2021-12-10 14:48:41 +08:00
buildmaster c6c6783a0a Bumping versions 2021-12-02 04:22:33 +00:00
buildmaster 848c306d67 Bumping versions to 3.1.1-SNAPSHOT after release 2021-12-01 18:32:34 +00:00
buildmaster a70946fce5 Going back to snapshots 2021-12-01 18:32:33 +00:00
buildmaster 6303a7ea03 Update SNAPSHOT to 3.1.0 2021-12-01 18:30:33 +00:00
spencergibb dc67500445 Re-enables tests due to boot test env ordering issue
Fixes gh-4048
2021-11-29 12:30:14 -05:00
Olga Maciaszek-Sharma ed3834f781 Add and configure duplicate-finder plugin. Remove duplicates. (#4051) 2021-11-29 15:13:10 +01:00
buildmaster a4b06d37b7 Bumping versions 2021-11-27 04:22:35 +00:00
Olga MaciaszekSharma d71040222b Merge remote-tracking branch 'origin/3.0.x' 2021-11-25 16:18:38 +01:00
Olga MaciaszekSharma 1327bcb7d0 Upgrade Eureka to 1.10.17. Fixes gh-4050. Fixes gh-4030. 2021-11-25 16:17:17 +01:00
spencergibb f1ebbb98e8 Disables tests due to boot test env ordering issue
see gh-4048
2021-11-22 14:53:36 -05:00
buildmaster dc45b7f580 Going back to snapshots 2021-11-03 11:25:47 +00:00
buildmaster d5aa729711 Update SNAPSHOT to 3.1.0-RC1 2021-11-03 11:24:36 +00:00
buildmaster 88d8e08349 Going back to snapshots 2021-10-20 02:12:50 +00:00
buildmaster c9c737c11c Update SNAPSHOT to 3.1.0-M3 2021-10-20 02:11:30 +00:00
Olga MaciaszekSharma 519c1d2aaf Merge remote-tracking branch 'origin/3.0.x' 2021-10-04 18:59:27 +02:00
Olga MaciaszekSharma d925a03343 Rebuild docs. 2021-10-04 18:50:30 +02:00
Kaveh Shamsi e4e1003dd8 Fix the typo in the docs 2021-10-04 18:46:56 +02:00
buildmaster 1d9e0d5499 Going back to snapshots 2021-10-01 17:02:51 +00:00
buildmaster 8419b9b876 Update SNAPSHOT to 3.1.0-M2 2021-10-01 17:01:37 +00:00
buildmaster 5675aec402 Bumping versions 2021-09-28 04:22:03 +00:00
buildmaster 829c1773cf Bumping versions to 3.0.5-SNAPSHOT after release 2021-09-21 14:35:49 +00:00
buildmaster bf8ba5c7b5 Going back to snapshots 2021-09-21 14:35:48 +00:00
buildmaster d532f4de31 Update SNAPSHOT to 3.0.4 2021-09-21 14:33:39 +00:00
Olga MaciaszekSharma 44fa4a226e Merge remote-tracking branch 'origin/3.0.x' 2021-09-09 13:51:32 +02:00
Olga MaciaszekSharma 0490150344 Upgrade eureka-client and xstream. Fixes gh-4025. 2021-09-09 13:51:11 +02:00
Olga MaciaszekSharma 6356c11b45 Merge remote-tracking branch 'origin/3.0.x' 2021-09-09 13:14:14 +02:00
Olga MaciaszekSharma 86797d0f12 Fix outdated sagan description. Reformat. Fixes gh-4029. 2021-09-09 13:13:45 +02:00
buildmaster bf7699f4e6 Going back to snapshots 2021-07-30 18:06:04 +00:00
buildmaster 3c8e8feeea Update SNAPSHOT to 3.1.0-M1 2021-07-30 18:04:51 +00:00
buildmaster 45f2998b0b Bumping versions 2021-07-30 04:22:27 +00:00
spencergibb 1a0f10e79d Merge branch '3.0.x' 2021-07-29 13:52:39 -04:00
Robert McNees 960fb64e39 Merge pull request #4021 from robertmcnees/Eureka_fix
Modified config bootstrap to default eureka client enabled true
2021-07-29 13:49:47 -04:00
Robert McNees 02100d9d46 Modified config bootstrap to default eureka client enabled true 2021-07-29 13:44:20 -04:00
spencergibb 432eaa0d76 Merge branch '3.0.x' 2021-07-29 10:50:27 -04:00
Robert McNees 247832e106 Merge pull request #4019 from robertmcnees/Test_Fixes
Added public modifier for JUnit4 classes and methods
2021-07-29 10:46:31 -04:00
Robert McNees 5cf48fadfb Added public modifier for JUnit4 classes and methods 2021-07-29 09:55:41 -04:00
spencergibb 59deb14e38 Merge branch '3.0.x' 2021-07-28 21:18:48 -04:00
Robert McNees 76b21a4a2a Updates eureka client bootstrap config only when enabled (#4018)
Fixes gh- 4000
2021-07-28 21:17:44 -04:00
Olga MaciaszekSharma 8cbb4dbe20 Merge remote-tracking branch 'origin/3.0.x' 2021-07-26 16:06:22 +02:00
maniotie 81ee8de8a2 Updated class and method visibility for junit jupiter tests - issue 4011 (#4017) 2021-07-26 15:21:46 +02:00
Olga MaciaszekSharma aeeee56edc Merge remote-tracking branch 'origin/3.0.x' 2021-07-19 10:25:47 +02:00
maniotie cf9c645f4a switched junit4 tests to junit jupiter - issue 4011 (#4016) 2021-07-19 10:21:09 +02:00
Olga MaciaszekSharma 12ffaf1005 Fix checkstyle and outdated API use. 2021-07-15 16:21:17 +02:00
Olga MaciaszekSharma 2b10f19d1a Downgrade Maven Resources Plugin to 3.1.0. 2021-07-12 16:52:02 +02:00
Olga MaciaszekSharma 96eb785d07 Downgrade wro4j to 1.8.0. 2021-07-12 15:20:35 +02:00
Olga MaciaszekSharma d79b43fd28 Downgrade wro4j to 1.9.0. 2021-07-12 15:07:16 +02:00
Olga MaciaszekSharma f4baba128d Upgrade wro4j. Temporarily ignore test. 2021-07-12 14:25:57 +02:00
spencergibb ac2d4888b5 Updates version to 3.1.0-SNAPSHOT 2021-07-09 14:10:02 -04:00
spencergibb 3a402fbef5 Updates test to deal with changes to context refresher.
ConfigDataContextRefresher now runs all EnvironmentPostProcessors and needs a SpringApplication.
2021-07-07 17:19:57 -04:00
buildmaster 6b165d83f0 Bumping versions 2021-05-28 04:23:13 +00:00
buildmaster cac519d89c Going back to snapshots 2021-05-27 21:14:36 +00:00
155 changed files with 1714 additions and 1409 deletions
+12 -6
View File
@@ -1,9 +1,8 @@
version: 2
jobs:
build:
docker:
- image: springcloud/pipeline-base
user: appuser
machine:
image: "ubuntu-2004:202201-02"
environment:
_JAVA_OPTIONS: "-Xms1024m -Xmx2048m"
TERM: dumb
@@ -11,14 +10,21 @@ jobs:
ignore:
- gh-pages # list of branches to ignore
steps:
- run:
name: Install OpenJDK 17
command: |
wget -qO - https://adoptium.jfrog.io/adoptium/api/gpg/key/public | sudo apt-key add -
sudo add-apt-repository --yes https://adoptium.jfrog.io/adoptium/deb/
sudo apt-get update && sudo apt-get install temurin-17-jdk
sudo update-alternatives --set java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/temurin-17-jdk-amd64/bin/javac
java -version
- checkout
- restore_cache:
key: sc-netflix-{{ .Branch }}
- run:
name: "Download dependencies"
command: |
cd spring-cloud-netflix-hystrix-contract && ../mvnw clean install && \
./mvnw -s .settings.xml -U --fail-never dependency:go-offline || true
command: ./mvnw -s .settings.xml -U --fail-never dependency:go-offline || true
- save_cache:
key: sc-netflix-{{ .Branch }}
paths:
-1
View File
@@ -20,4 +20,3 @@ _site/
*.swo
.vscode/
.flattened-pom.xml
.sdkmanrc
+3
View File
@@ -0,0 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=17.0.1-tem
+55 -18
View File
@@ -23,7 +23,6 @@ Edit the files in the src/main/asciidoc/ directory instead.
image::https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/main.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/main"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/main/graph/badge.svg["Codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/main"]
image::https://api.codacy.com/project/badge/Grade/a6885a06921e4f72a0df0b7aabd6d118["Codacy code quality", link="https://www.codacy.com/app/Spring-Cloud/spring-cloud-netflix?utm_source=github.com&utm_medium=referral&utm_content=spring-cloud/spring-cloud-netflix&utm_campaign=Badge_Grade"]
:doctype: book
@@ -57,7 +56,8 @@ patterns provided include Service Discovery (Eureka).
== Building
:jdkversion: 1.8
:jdkversion: 17
=== Basic Compile and Test
@@ -83,23 +83,9 @@ the `.mvn` configuration, so if you find you have to do it to make a
build succeed, please raise a ticket to get the settings added to
source control.
For hints on how to build the project look in `.travis.yml` if there
is one. There should be a "script" and maybe "install" command. Also
look at the "services" section to see if any services need to be
running locally (e.g. mongo or rabbit). Ignore the git-related bits
that you might find in "before_install" since they're related to setting git
credentials and you already have those.
The projects that require middleware (i.e. Redis) for testing generally
require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running.
The projects that require middleware generally include a
`docker-compose.yml`, so consider using
https://docs.docker.com/compose/[Docker Compose] to run the middeware servers
in Docker containers. See the README in the
https://github.com/spring-cloud-samples/scripts[scripts demo
repository] for specific instructions about the common cases of mongo,
rabbit and redis.
NOTE: If all else fails, build with the command from `.travis.yml` (usually
`./mvnw install`).
=== Documentation
@@ -337,6 +323,57 @@ Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on t
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
=== Duplicate Finder
Spring Cloud Build brings along the `basepom:duplicate-finder-maven-plugin`, that enables flagging duplicate and conflicting classes and resources on the java classpath.
==== Duplicate Finder configuration
Duplicate finder is *enabled by default* and will run in the `verify` phase of your Maven build, but it will only take effect in your project if you add the `duplicate-finder-maven-plugin` to the `build` section of the projecst's `pom.xml`.
.pom.xml
[source,xml]
----
<build>
<plugins>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
----
For other properties, we have set defaults as listed in the https://github.com/basepom/duplicate-finder-maven-plugin/wiki[plugin documentation].
You can easily override them but setting the value of the selected property prefixed with `duplicate-finder-maven-plugin`. For example, set `duplicate-finder-maven-plugin.skip` to `true` in order to skip duplicates check in your build.
If you need to add `ignoredClassPatterns` or `ignoredResourcePatterns` to your setup, make sure to add them in the plugin configuration section of your project:
[source,xml]
----
<build>
<plugins>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<configuration>
<ignoredClassPatterns>
<ignoredClassPattern>org.joda.time.base.BaseDateTime</ignoredClassPattern>
<ignoredClassPattern>.*module-info</ignoredClassPattern>
</ignoredClassPatterns>
<ignoredResourcePatterns>
<ignoredResourcePattern>changelog.txt</ignoredResourcePattern>
</ignoredResourcePatterns>
</configuration>
</plugin>
</plugins>
</build>
----
== License
The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/main/LICENSE.txt[here].
+3 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>3.0.3</version>
<version>4.0.0-SNAPSHOT</version>
</parent>
<artifactId>spring-cloud-netflix-docs</artifactId>
<packaging>jar</packaging>
@@ -18,6 +18,8 @@
.*.eureka.*
</configprops.inclusionPattern>
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
<!-- Don't upload docs jar to central / repo.spring.io -->
<maven-deploy-plugin-default.phase>none</maven-deploy-plugin-default.phase>
</properties>
<dependencies>
<dependency>
-1
View File
@@ -2,7 +2,6 @@ include::_attributes.adoc[]
image::https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/main.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/main"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/main/graph/badge.svg["Codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/main"]
image::https://api.codacy.com/project/badge/Grade/a6885a06921e4f72a0df0b7aabd6d118["Codacy code quality", link="https://www.codacy.com/app/Spring-Cloud/spring-cloud-netflix?utm_source=github.com&utm_medium=referral&utm_content=spring-cloud/spring-cloud-netflix&utm_campaign=Badge_Grade"]
include::intro.adoc[]
+12 -12
View File
@@ -1,20 +1,20 @@
|===
|Name | Default | Description
|eureka.client.eureka-connection-idle-timeout-seconds | `30` | Indicates how much time (in seconds) that the HTTP connections to eureka server can stay idle before it can be closed. In the AWS environment, it is recommended that the values is 30 seconds or less, since the firewall cleans up the connection information after a few mins leaving the connection hanging in limbo.
|eureka.client.eureka-server-connect-timeout-seconds | `5` | Indicates how long to wait (in seconds) before a connection to eureka server needs to timeout. Note that the connections in the client are pooled by org.apache.http.client.HttpClient and this setting affects the actual connection creation and also the wait time to get the connection from the pool.
|eureka.client.eureka-connection-idle-timeout-seconds | `+++30+++` | Indicates how much time (in seconds) that the HTTP connections to eureka server can stay idle before it can be closed. In the AWS environment, it is recommended that the values is 30 seconds or less, since the firewall cleans up the connection information after a few mins leaving the connection hanging in limbo.
|eureka.client.eureka-server-connect-timeout-seconds | `+++5+++` | Indicates how long to wait (in seconds) before a connection to eureka server needs to timeout. Note that the connections in the client are pooled by {@link HttpClient} and this setting affects the actual connection creation and also the wait time to get the connection from the pool.
|eureka.client.eureka-server-d-n-s-name | | Gets the DNS name to be queried to get the list of eureka servers.This information is not required if the contract returns the service urls by implementing serviceUrls. The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
|eureka.client.eureka-server-port | | Gets the port to be used to construct the service url to contact eureka server when the list of eureka servers come from the DNS.This information is not required if the contract returns the service urls eurekaServerServiceUrls(String). The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
|eureka.client.eureka-server-read-timeout-seconds | `8` | Indicates how long to wait (in seconds) before a read from eureka server needs to timeout.
|eureka.client.eureka-server-total-connections | `200` | Gets the total number of connections that is allowed from eureka client to all eureka servers.
|eureka.client.eureka-server-total-connections-per-host | `50` | Gets the total number of connections that is allowed from eureka client to a eureka server host.
|eureka.client.eureka-server-read-timeout-seconds | `+++8+++` | Indicates how long to wait (in seconds) before a read from eureka server needs to timeout.
|eureka.client.eureka-server-total-connections | `+++200+++` | Gets the total number of connections that is allowed from eureka client to all eureka servers.
|eureka.client.eureka-server-total-connections-per-host | `+++50+++` | Gets the total number of connections that is allowed from eureka client to a eureka server host.
|eureka.client.eureka-server-u-r-l-context | | Gets the URL context to be used to construct the service url to contact eureka server when the list of eureka servers come from the DNS. This information is not required if the contract returns the service urls from eurekaServerServiceUrls. The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
|eureka.client.eureka-service-url-poll-interval-seconds | `0` | Indicates how often(in seconds) to poll for changes to eureka server information. Eureka servers could be added or removed and this setting controls how soon the eureka clients should know about it.
|eureka.client.prefer-same-zone-eureka | `true` | Indicates whether or not this instance should try to use the eureka server in the same zone for latency and/or other reason. Ideally eureka clients are configured to talk to servers in the same zone The changes are effective at runtime at the next registry fetch cycle as specified by registryFetchIntervalSeconds
|eureka.client.register-with-eureka | `true` | Indicates whether or not this instance should register its information with eureka server for discovery by others. In some cases, you do not want your instances to be discovered whereas you just want do discover other instances.
|eureka.server.peer-eureka-nodes-update-interval-ms | `0` |
|eureka.server.peer-eureka-status-refresh-time-interval-ms | `0` |
|ribbon.eureka.enabled | `true` | Enables the use of Eureka with Ribbon.
|spring.cloud.loadbalancer.eureka.approximate-zone-from-hostname | `false` | Used to determine whether we should try to get the `zone` value from host name.
|eureka.client.eureka-service-url-poll-interval-seconds | `+++0+++` | Indicates how often(in seconds) to poll for changes to eureka server information. Eureka servers could be added or removed and this setting controls how soon the eureka clients should know about it.
|eureka.client.prefer-same-zone-eureka | `+++true+++` | Indicates whether or not this instance should try to use the eureka server in the same zone for latency and/or other reason. Ideally eureka clients are configured to talk to servers in the same zone The changes are effective at runtime at the next registry fetch cycle as specified by registryFetchIntervalSeconds
|eureka.client.register-with-eureka | `+++true+++` | Indicates whether or not this instance should register its information with eureka server for discovery by others. In some cases, you do not want your instances to be discovered whereas you just want do discover other instances.
|eureka.server.peer-eureka-nodes-update-interval-ms | `+++0+++` |
|eureka.server.peer-eureka-status-refresh-time-interval-ms | `+++0+++` |
|ribbon.eureka.enabled | `+++true+++` | Enables the use of Eureka with Ribbon.
|spring.cloud.loadbalancer.eureka.approximate-zone-from-hostname | `+++false+++` | Used to determine whether we should try to get the `zone` value from host name.
|===
+1 -2
View File
@@ -10,13 +10,12 @@ Spring Cloud Netflix features:
## Getting Started
As long as Spring Cloud Netflix and Eureka Core are on the
classpath any Spring Boot application with `@EnableEurekaClient` will try to contact a Eureka
classpath any Spring Boot application with `spring-cloud-starter-netflix-eureka-client` in dependencies will try to contact a Eureka
server on `http://localhost:8761` (the default value of
`eureka.client.serviceUrl.defaultZone`):
```java
@SpringBootApplication
@EnableEurekaClient
@RestController
public class Application {
@@ -80,6 +80,9 @@ See {github-code}/spring-cloud-netflix-eureka-client/src/main/java/org/springfra
To disable the Eureka Discovery Client, you can set `eureka.client.enabled` to `false`. Eureka Discovery Client will also be disabled when `spring.cloud.discovery.enabled` is set to `false`.
NOTE: Specifying the version of the Spring Cloud Netflix Eureka server as a path parameter is not currently supported. This means you cannot set the version in the context path (`eurekaServerURLContext`). Instead, you can include the version in the server URL (for example, you can set `defaultZone: http://localhost:8761/eureka/v2`).
=== Authenticating with the Eureka Server
HTTP basic authentication is automatically added to your eureka client if one of the `eureka.client.serviceUrl.defaultZone` URLs has credentials embedded in it (curl style, as follows: `https://user:password@localhost:8761/eureka`).
@@ -266,7 +269,7 @@ Do not use the `EurekaClient` in a `@PostConstruct` method or in a `@Scheduled`
It is initialized in a `SmartLifecycle` (with `phase=0`), so the earliest you can rely on it being available is in another `SmartLifecycle` with a higher phase.
====
==== EurekaClient without Jersey
==== EurekaClient with Jersey
By default, EurekaClient uses Spring's `RestTemplate` for HTTP communication.
If you wish to use Jersey instead, you need to add the Jersey dependencies to your classpath.
@@ -355,7 +358,7 @@ the ability to refresh Eureka clients. To do this set `eureka.client.refresh.en
We offer support for the Spring Cloud LoadBalancer `ZonePreferenceServiceInstanceListSupplier`.
The `zone` value from the Eureka instance metadata (`eureka.instance.metadataMap.zone`) is used for setting the
value of `spring-clod-loadbalancer-zone` property that is used to filter service instances by zone.
value of `spring-cloud-loadbalancer-zone` property that is used to filter service instances by zone.
If that is missing and if the `spring.cloud.loadbalancer.eureka.approximateZoneFromHostname` flag is set to `true`,
it can use the domain name from the server hostname as a proxy for the zone.
@@ -430,6 +433,10 @@ dependencyManagement {
----
====
=== `defaultOpenForTrafficCount` and its effect on EurekaServer warmup time
Netflix Eureka's `waitTimeInMsWhenSyncEmpty` setting is not taken into account in Spring Cloud Eureka server at the beginning. In order to enable the warmup time, set `eureka.server.defaultOpenForTrafficCount=0`.
[[spring-cloud-eureka-server-zones-and-regions]]
=== High Availability, Zones and Regions
+36 -38
View File
@@ -3,14 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-netflix</artifactId>
<version>3.0.3</version>
<version>4.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Spring Cloud Netflix</name>
<description>Spring Cloud Netflix</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>3.0.3</version>
<version>4.0.0-SNAPSHOT</version>
<relativePath />
</parent>
<scm>
@@ -21,15 +21,17 @@
</scm>
<properties>
<bintray.package>netflix</bintray.package>
<spring-cloud-commons.version>3.0.3</spring-cloud-commons.version>
<spring-cloud-config.version>3.0.4</spring-cloud-config.version>
<spring-cloud-commons.version>4.0.0-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>4.0.0-SNAPSHOT</spring-cloud-config.version>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<eureka-jersey.version>1.19.4</eureka-jersey.version>
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<!-- FIXME: 4.0.0 -->
<duplicate-finder-maven-plugin.skip>true</duplicate-finder-maven-plugin.skip>
</properties>
<build>
<plugins>
@@ -55,14 +57,6 @@
</additionalConfig>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
@@ -71,6 +65,18 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<configuration>
<ignoredResourcePatterns>
<ignoredResourcePattern>about.html</ignoredResourcePattern>
<ignoredResourcePattern>plugin.properties</ignoredResourcePattern>
<ignoredResourcePattern>mozilla/public-suffix-list.txt</ignoredResourcePattern>
</ignoredResourcePatterns>
<checkTestClasspath>false</checkTestClasspath>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
@@ -108,31 +114,6 @@
<version>1</version>
</dependency>
<!-- Eureka core dep that is now optional -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${eureka-jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${eureka-jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${eureka-jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${eureka-jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client4</artifactId>
<version>${eureka-jersey.version}</version>
</dependency>
<!-- end eureka deps -->
</dependencies>
</dependencyManagement>
@@ -184,6 +165,23 @@
<enabled>false</enabled>
</snapshots>
</repository>
<!-- FIXME: 4.0 -->
<repository>
<id>netflix-snapshots</id>
<name>Netflix Snapshots</name>
<url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>netflix-candidates</id>
<name>Netflix Candidates</name>
<url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
+1 -1
View File
@@ -4,7 +4,7 @@ set -o errexit
mkdir -p target
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/main/runAcceptanceTests.sh"
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/3.1.x/runAcceptanceTests.sh"
AT_WHAT_TO_TEST="EUREKA"
cd target
+21 -3
View File
@@ -5,16 +5,16 @@
<parent>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>3.0.3</version>
<version>4.0.0-SNAPSHOT</version>
<relativePath/>
</parent>
<artifactId>spring-cloud-netflix-dependencies</artifactId>
<version>3.0.3</version>
<version>4.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>spring-cloud-netflix-dependencies</name>
<description>Spring Cloud Netflix Dependencies</description>
<properties>
<eureka.version>1.10.14</eureka.version>
<eureka.version>2.0.0-rc.3</eureka.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -112,6 +112,24 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-core-jersey3</artifactId>
<version>${eureka.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client-jersey3</artifactId>
<!-- FIXME: 4.0 -->
<version>${eureka.version}</version>
<exclusions>
<exclusion>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- TODO: Move back to Eureka dependency when 1.10.17 released -->
</dependencies>
</dependencyManagement>
<profiles>
@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>3.0.3</version>
<version>4.0.0-SNAPSHOT</version>
<relativePath>..</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>spring-cloud-netflix-eureka-client-tls-tests</artifactId>
@@ -56,6 +56,12 @@
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -76,6 +82,11 @@
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -22,9 +22,9 @@ import java.util.List;
import java.util.Map;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.test.TestSocketUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.SocketUtils;
public class AppRunner implements AutoCloseable {
@@ -56,7 +56,7 @@ public class AppRunner implements AutoCloseable {
}
private int availabeTcpPort() {
return SocketUtils.findAvailableTcpPort();
return TestSocketUtils.findAvailableTcpPort();
}
private String[] props() {
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -24,15 +24,16 @@ import java.util.function.Supplier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import static org.assertj.core.api.Assertions.assertThat;
public abstract class BaseCertTest {
abstract class BaseCertTest {
private static final Log log = LogFactory.getLog(BaseCertTest.class);
@@ -94,8 +95,8 @@ public abstract class BaseCertTest {
}
}
@BeforeClass
public static void createCertificates() throws Exception {
@BeforeAll
static void createCertificates() throws Exception {
KeyTool tool = new KeyTool();
KeyAndCert ca = tool.createCA("MyCA");
@@ -113,8 +114,8 @@ public abstract class BaseCertTest {
wrongClientCert = saveKeyAndCert(wrongClient);
}
@AfterClass
public static void afterClass() {
@AfterAll
static void afterClass() {
log.info("Tests finished!");
}
@@ -125,11 +126,11 @@ public abstract class BaseCertTest {
* purpose explicitly.
*/
@Test
public void clientCertCanWork() {
void clientCertCanWork() {
}
@Test
public void noCertCannotWork() {
void noCertCannotWork() {
try (EurekaClientRunner client = createEurekaClient()) {
client.disableTls();
client.start();
@@ -138,7 +139,7 @@ public abstract class BaseCertTest {
}
@Test
public void wrongCertCannotWork() {
void wrongCertCannotWork() {
try (EurekaClientRunner client = createEurekaClient()) {
enableTlsClient(client);
client.setKeyStore(wrongClientCert);
@@ -147,24 +148,28 @@ public abstract class BaseCertTest {
}
}
@Test(expected = BeanCreationException.class)
public void wrongPasswordCauseFailure() {
@Test
void wrongPasswordCauseFailure() {
EurekaClientRunner client = createEurekaClient();
enableTlsClient(client);
client.setKeyStore(clientCert, WRONG_PASSWORD, WRONG_PASSWORD);
client.start();
}
@Test(expected = BeanCreationException.class)
public void nonExistKeyStoreCauseFailure() {
EurekaClientRunner client = createEurekaClient();
enableTlsClient(client);
client.setKeyStore(new File("nonExistFile"));
client.start();
Assertions.assertThrows(BeanCreationException.class, () -> {
client.start();
});
}
@Test
public void wrongTrustStoreCannotWork() {
void nonExistKeyStoreCauseFailure() {
EurekaClientRunner client = createEurekaClient();
enableTlsClient(client);
client.setKeyStore(new File("nonExistFile"));
Assertions.assertThrows(BeanCreationException.class, () -> {
client.start();
});
}
@Test
void wrongTrustStoreCannotWork() {
try (EurekaClientRunner client = createEurekaClient()) {
enableTlsClient(client);
client.setTrustStore(wrongCaCert);
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -16,17 +16,14 @@
package org.springframework.cloud.netflix.eureka;
import com.netflix.discovery.DiscoveryClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import static org.assertj.core.api.Assertions.assertThat;
public class EurekaClientTest extends BaseCertTest {
private static final Log log = LogFactory.getLog(EurekaClientTest.class);
@@ -35,13 +32,14 @@ public class EurekaClientTest extends BaseCertTest {
static EurekaClientRunner service;
@BeforeClass
@BeforeAll
public static void setupAll() {
server = startEurekaServer(EurekaClientTest.TestEurekaServer.class);
service = startService(server, EurekaClientTest.TestApp.class);
// Will use Jersey
assertThat(service.discoveryClientOptionalArgs())
.isInstanceOf(DiscoveryClient.DiscoveryClientOptionalArgs.class);
// FIXME: 4.0
// assertThat(service.discoveryClientOptionalArgs())
// .isInstanceOf(DiscoveryClient.DiscoveryClientOptionalArgs.class);
log.info("Successfully asserted that Jersey will be used");
waitForRegistration(() -> new EurekaClientTest().createEurekaClient());
}
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 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.
@@ -21,8 +21,8 @@ import java.security.GeneralSecurityException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -43,7 +43,7 @@ public class RestTemplateEurekaClientTest extends BaseCertTest {
private static EurekaClientRunner service;
@BeforeClass
@BeforeAll
public static void setupAll() {
server = startEurekaServer(RestTemplateEurekaClientTest.RestTemplateTestEurekaServer.class);
service = startService(server, RestTemplateEurekaClientTest.RestTemplateTestApp.class);
@@ -53,7 +53,7 @@ public class RestTemplateEurekaClientTest extends BaseCertTest {
waitForRegistration(() -> new RestTemplateEurekaClientTest().createEurekaClient());
}
@AfterClass
@AfterAll
public static void tearDownAll() {
stopService(service);
stopEurekaServer(server);
+15 -37
View File
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>3.0.3</version>
<version>4.0.0-SNAPSHOT</version>
<relativePath>..</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
@@ -14,7 +15,7 @@
<description>Spring Cloud Netflix Eureka Client</description>
<properties>
<!-- Why do I need this now? -->
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
</properties>
<dependencies>
<dependency>
@@ -40,7 +41,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
@@ -50,39 +51,6 @@
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client</artifactId>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client4</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${eureka-jersey.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${eureka-jersey.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client4</artifactId>
<version>${eureka-jersey.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
@@ -100,6 +68,10 @@
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
@@ -124,6 +96,12 @@
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -25,6 +25,7 @@ import java.util.Objects;
import com.netflix.appinfo.EurekaAccept;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.EurekaTransportConfig;
import org.apache.hc.client5.http.classic.HttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -126,14 +127,14 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
/**
* Indicates how long to wait (in seconds) before a connection to eureka server needs
* to timeout. Note that the connections in the client are pooled by
* org.apache.http.client.HttpClient and this setting affects the actual connection
* creation and also the wait time to get the connection from the pool.
* {@link HttpClient} and this setting affects the actual connection creation and also
* the wait time to get the connection from the pool.
*/
private int eurekaServerConnectTimeoutSeconds = 5;
/**
* Gets the name of the implementation which implements BackupRegistry to fetch the
* registry information as a fall back option for only the first time when the eureka
* registry information as a fallback option for only the first time when the eureka
* client starts.
*
* This may be needed for applications which needs additional resiliency for registry
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2013-2022 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.
@@ -19,19 +19,21 @@ package org.springframework.cloud.netflix.eureka;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import reactor.core.publisher.Mono;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.actuate.health.CompositeHealthContributor;
import org.springframework.boot.actuate.health.CompositeReactiveHealthContributor;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthContributor;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.NamedContributor;
import org.springframework.boot.actuate.health.ReactiveHealthContributor;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.actuate.health.StatusAggregator;
@@ -58,6 +60,7 @@ import org.springframework.util.Assert;
* @author Spencer Gibb
* @author Nowrin Anwar Joyita
* @author Bertrand Renuart
* @author Olga Maciaszek-Sharma
* @see HealthCheckHandler
* @see StatusAggregator
*/
@@ -67,7 +70,7 @@ public class EurekaHealthCheckHandler
private static final Map<Status, InstanceInfo.InstanceStatus> STATUS_MAPPING = new HashMap<Status, InstanceInfo.InstanceStatus>() {
{
put(Status.UNKNOWN, InstanceStatus.UNKNOWN);
put(Status.OUT_OF_SERVICE, InstanceStatus.OUT_OF_SERVICE);
put(Status.OUT_OF_SERVICE, InstanceStatus.DOWN);
put(Status.DOWN, InstanceStatus.DOWN);
put(Status.UP, InstanceStatus.UP);
}
@@ -77,14 +80,14 @@ public class EurekaHealthCheckHandler
private ApplicationContext applicationContext;
private Map<String, HealthIndicator> healthIndicators = new HashMap<>();
private Map<String, HealthContributor> healthContributors = new HashMap<>();
/**
* {@code true} until the context is stopped.
*/
private boolean running = true;
private Map<String, ReactiveHealthIndicator> reactiveHealthIndicators = new HashMap<>();
private Map<String, ReactiveHealthContributor> reactiveHealthContributors = new HashMap<>();
public EurekaHealthCheckHandler(StatusAggregator statusAggregator) {
this.statusAggregator = statusAggregator;
@@ -99,39 +102,28 @@ public class EurekaHealthCheckHandler
@Override
public void afterPropertiesSet() {
final Map<String, HealthIndicator> healthIndicators = applicationContext.getBeansOfType(HealthIndicator.class);
final Map<String, ReactiveHealthIndicator> reactiveHealthIndicators = applicationContext
.getBeansOfType(ReactiveHealthIndicator.class);
populateHealthIndicators(healthIndicators);
populateReactiveHealthIndicators(reactiveHealthIndicators);
populateHealthContributors(applicationContext.getBeansOfType(HealthContributor.class));
reactiveHealthContributors.putAll(applicationContext.getBeansOfType(ReactiveHealthContributor.class));
}
void populateHealthIndicators(Map<String, HealthIndicator> healthIndicators) {
for (Map.Entry<String, HealthIndicator> entry : healthIndicators.entrySet()) {
void populateHealthContributors(Map<String, HealthContributor> healthContributors) {
for (Map.Entry<String, HealthContributor> entry : healthContributors.entrySet()) {
// ignore EurekaHealthIndicator and flatten the rest of the composite
// otherwise there is a never ending cycle of down. See gh-643
if (entry.getValue() instanceof DiscoveryCompositeHealthContributor) {
DiscoveryCompositeHealthContributor indicator = (DiscoveryCompositeHealthContributor) entry.getValue();
indicator.forEach(contributor -> {
if (!(contributor.getContributor() instanceof EurekaHealthIndicator)) {
this.healthIndicators.put(contributor.getName(),
(HealthIndicator) contributor.getContributor());
indicator.getIndicators().forEach((name, discoveryHealthIndicator) -> {
if (!(discoveryHealthIndicator instanceof EurekaHealthIndicator)) {
this.healthContributors.put(name, (HealthIndicator) discoveryHealthIndicator::health);
}
});
}
else {
this.healthIndicators.put(entry.getKey(), entry.getValue());
this.healthContributors.put(entry.getKey(), entry.getValue());
}
}
}
void populateReactiveHealthIndicators(Map<String, ReactiveHealthIndicator> reactiveHealthIndicators) {
for (Map.Entry<String, ReactiveHealthIndicator> entry : reactiveHealthIndicators.entrySet()) {
this.reactiveHealthIndicators.put(entry.getKey(), entry.getValue());
}
}
@Override
public InstanceStatus getStatus(InstanceStatus instanceStatus) {
if (running) {
@@ -151,21 +143,39 @@ public class EurekaHealthCheckHandler
}
protected Status getStatus(StatusAggregator statusAggregator) {
Status status;
Set<Status> statusSet = new HashSet<>();
if (healthIndicators != null) {
statusSet.addAll(healthIndicators.values().stream().map(HealthIndicator::health).map(Health::getStatus)
.collect(Collectors.toSet()));
for (HealthContributor contributor : healthContributors.values()) {
processContributor(statusSet, contributor);
}
if (reactiveHealthIndicators != null) {
statusSet.addAll(reactiveHealthIndicators.values().stream().map(ReactiveHealthIndicator::health)
.map(Mono::block).filter(Objects::nonNull).map(Health::getStatus).collect(Collectors.toSet()));
for (ReactiveHealthContributor contributor : reactiveHealthContributors.values()) {
processContributor(statusSet, contributor);
}
return statusAggregator.getAggregateStatus(statusSet);
}
status = statusAggregator.getAggregateStatus(statusSet);
return status;
private void processContributor(Set<Status> statusSet, HealthContributor contributor) {
if (contributor instanceof CompositeHealthContributor) {
for (NamedContributor<HealthContributor> contrib : (CompositeHealthContributor) contributor) {
processContributor(statusSet, contrib.getContributor());
}
}
else if (contributor instanceof HealthIndicator) {
statusSet.add(((HealthIndicator) contributor).health().getStatus());
}
}
private void processContributor(Set<Status> statusSet, ReactiveHealthContributor contributor) {
if (contributor instanceof CompositeReactiveHealthContributor) {
for (NamedContributor<ReactiveHealthContributor> contrib : (CompositeReactiveHealthContributor) contributor) {
processContributor(statusSet, contrib.getContributor());
}
}
else if (contributor instanceof ReactiveHealthIndicator) {
Health health = ((ReactiveHealthIndicator) contributor).health().block();
if (health != null) {
statusSet.add(health.getStatus());
}
}
}
protected InstanceStatus mapToInstanceStatus(Status status) {
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -16,28 +16,24 @@
package org.springframework.cloud.netflix.eureka;
import java.util.Collection;
import java.util.LinkedHashSet;
import com.netflix.discovery.DiscoveryClient.DiscoveryClientOptionalArgs;
import com.sun.jersey.api.client.filter.ClientFilter;
/**
* @author Dave Syer
*/
public class MutableDiscoveryClientOptionalArgs extends DiscoveryClientOptionalArgs {
// FIXME: 4.0
public class MutableDiscoveryClientOptionalArgs {
private Collection<ClientFilter> additionalFilters;
@Override
public void setAdditionalFilters(Collection<ClientFilter> additionalFilters) {
additionalFilters = new LinkedHashSet<>(additionalFilters);
this.additionalFilters = additionalFilters;
super.setAdditionalFilters(additionalFilters);
}
public Collection<ClientFilter> getAdditionalFilters() {
return this.additionalFilters;
}
}
} /*
* extends DiscoveryClientOptionalArgs {
*
* private Collection<ClientFilter> additionalFilters;
*
* @Override public void setAdditionalFilters(Collection<ClientFilter>
* additionalFilters) { additionalFilters = new LinkedHashSet<>(additionalFilters);
* this.additionalFilters = additionalFilters;
* super.setAdditionalFilters(additionalFilters); }
*
* public Collection<ClientFilter> getAdditionalFilters() { return
* this.additionalFilters; }
*
* }
*/
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -33,7 +33,6 @@ import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.configuration.SSLContextFactory;
import org.springframework.cloud.configuration.TlsProperties;
import org.springframework.cloud.netflix.eureka.MutableDiscoveryClientOptionalArgs;
import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs;
@@ -79,16 +78,20 @@ public class DiscoveryClientOptionalArgsConfiguration {
return new DefaultEurekaClientHttpRequestFactorySupplier();
}
@Bean
@ConditionalOnClass(name = "com.sun.jersey.api.client.filter.ClientFilter")
@ConditionalOnMissingBean(value = AbstractDiscoveryClientOptionalArgs.class, search = SearchStrategy.CURRENT)
public MutableDiscoveryClientOptionalArgs discoveryClientOptionalArgs(TlsProperties tlsProperties)
throws GeneralSecurityException, IOException {
logger.info("Eureka HTTP Client uses Jersey");
MutableDiscoveryClientOptionalArgs result = new MutableDiscoveryClientOptionalArgs();
setupTLS(result, tlsProperties);
return result;
}
// FIXME: 4.0
/*
* @Bean
*
* @ConditionalOnClass(name = "com.sun.jersey.api.client.filter.ClientFilter")
*
* @ConditionalOnMissingBean(value = AbstractDiscoveryClientOptionalArgs.class, search
* = SearchStrategy.CURRENT) public MutableDiscoveryClientOptionalArgs
* discoveryClientOptionalArgs(TlsProperties tlsProperties) throws
* GeneralSecurityException, IOException {
* logger.info("Eureka HTTP Client uses Jersey"); MutableDiscoveryClientOptionalArgs
* result = new MutableDiscoveryClientOptionalArgs(); setupTLS(result, tlsProperties);
* return result; }
*/
private static void setupTLS(AbstractDiscoveryClientOptionalArgs<?> args, TlsProperties properties)
throws GeneralSecurityException, IOException {
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -16,17 +16,16 @@
package org.springframework.cloud.netflix.eureka.config;
import javax.annotation.PostConstruct;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.EurekaClient;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
/**
@@ -36,21 +35,22 @@ import org.springframework.util.StringUtils;
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@ConditionalOnClass({ EurekaInstanceConfigBean.class, EurekaClient.class, ConfigServerProperties.class })
@ConditionalOnClass(value = { EurekaInstanceConfigBean.class, EurekaClient.class },
name = "org.springframework.cloud.config.server.config.ConfigServerProperties")
public class EurekaClientConfigServerAutoConfiguration {
@Autowired(required = false)
private EurekaInstanceConfig instance;
@Autowired(required = false)
private ConfigServerProperties server;
@Autowired
private Environment env;
@PostConstruct
public void init() {
if (this.instance == null || this.server == null) {
if (this.instance == null) {
return;
}
String prefix = this.server.getPrefix();
String prefix = this.env.getProperty("spring.cloud.config.server.prefix");
if (StringUtils.hasText(prefix) && !StringUtils.hasText(this.instance.getMetadataMap().get("configPath"))) {
this.instance.getMetadataMap().put("configPath", prefix);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -21,6 +21,7 @@ import com.netflix.discovery.shared.transport.EurekaHttpClient;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -39,6 +40,7 @@ import org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClient
import org.springframework.cloud.netflix.eureka.http.WebClientEurekaHttpClient;
import org.springframework.cloud.netflix.eureka.http.WebClientTransportClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.lang.Nullable;
@@ -51,7 +53,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* @author Dave Syer
*/
@ConditionalOnClass(ConfigServicePropertySourceLocator.class)
@ConditionalOnProperty("spring.cloud.config.discovery.enabled")
@Conditional(EurekaConfigServerBootstrapConfiguration.EurekaConfigServerBootstrapCondition.class)
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
public class EurekaConfigServerBootstrapConfiguration {
@@ -102,4 +104,22 @@ public class EurekaConfigServerBootstrapConfiguration {
}
static class EurekaConfigServerBootstrapCondition extends AllNestedConditions {
EurekaConfigServerBootstrapCondition() {
super(ConfigurationPhase.REGISTER_BEAN);
}
@ConditionalOnProperty("spring.cloud.config.discovery.enabled")
static class OnCloudConfigProperty {
}
@ConditionalOnProperty(value = "eureka.client.enabled", matchIfMissing = true)
static class OnEurekaClient {
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -16,10 +16,12 @@
package org.springframework.cloud.netflix.eureka.config;
import java.util.Collections;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.Bootstrapper;
import org.springframework.boot.BootstrapRegistryInitializer;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.cloud.config.client.ConfigClientProperties;
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
@@ -30,10 +32,10 @@ import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFact
import org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClientFactory;
import org.springframework.util.ClassUtils;
public class EurekaConfigServerBootstrapper implements Bootstrapper {
public class EurekaConfigServerBootstrapper implements BootstrapRegistryInitializer {
@Override
public void intitialize(BootstrapRegistry registry) {
public void initialize(BootstrapRegistry registry) {
if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerInstanceProvider", null)) {
return;
}
@@ -50,7 +52,7 @@ public class EurekaConfigServerBootstrapper implements Bootstrapper {
registry.registerIfAbsent(ConfigServerInstanceProvider.Function.class, context -> {
Binder binder = context.get(Binder.class);
if (!getDiscoveryEnabled(binder)) {
return null;
return (id) -> Collections.emptyList();
}
EurekaClientConfigBean config = context.get(EurekaClientConfigBean.class);
EurekaHttpClient httpClient = new RestTemplateTransportClientFactory(
@@ -63,7 +65,9 @@ public class EurekaConfigServerBootstrapper implements Bootstrapper {
}
private Boolean getDiscoveryEnabled(Binder binder) {
return binder.bind(ConfigClientProperties.CONFIG_DISCOVERY_ENABLED, Boolean.class).orElse(false);
return binder.bind(ConfigClientProperties.CONFIG_DISCOVERY_ENABLED, Boolean.class).orElse(false)
&& binder.bind("eureka.client.enabled", Boolean.class).orElse(true)
&& binder.bind("spring.cloud.discovery.enabled", Boolean.class).orElse(true);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -18,6 +18,7 @@ package org.springframework.cloud.netflix.eureka.config;
import java.util.List;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.endpoint.EndpointUtils;
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
@@ -26,7 +27,7 @@ import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
final class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandomizer {
public final class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandomizer {
private final String hostname;
@@ -56,18 +57,18 @@ final class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandom
}
}
static String getEurekaUrl(EurekaClientConfigBean config, String hostname) {
public static String getEurekaUrl(EurekaClientConfig config, String hostname) {
List<String> urls = EndpointUtils.getDiscoveryServiceUrls(config, EurekaClientConfigBean.DEFAULT_ZONE,
new HostnameBasedUrlRandomizer(hostname));
return urls.get(0);
}
static DefaultEndpoint randomEndpoint(EurekaClientConfigBean config, Environment env) {
public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, Environment env) {
String hostname = env.getProperty("eureka.instance.hostname");
return new DefaultEndpoint(getEurekaUrl(config, hostname));
}
static DefaultEndpoint randomEndpoint(EurekaClientConfigBean config, Binder binder) {
public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, Binder binder) {
String hostname = binder.bind("eureka.instance.hostname", String.class).orElseGet(() -> null);
return new DefaultEndpoint(getEurekaUrl(config, hostname));
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -19,9 +19,12 @@ package org.springframework.cloud.netflix.eureka.http;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
@@ -32,18 +35,16 @@ import org.springframework.lang.Nullable;
* {@link HttpClients}.
*
* @author Marcin Grzejszczak
* @author Olga Maciaszek-Sharma
* @since 3.0.0
*/
public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClientHttpRequestFactorySupplier {
@Override
public ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVerifier hostnameVerifier) {
HttpClientBuilder httpClientBuilder = HttpClients.custom();
if (sslContext != null) {
httpClientBuilder = httpClientBuilder.setSSLContext(sslContext);
}
if (hostnameVerifier != null) {
httpClientBuilder = httpClientBuilder.setSSLHostnameVerifier(hostnameVerifier);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
if (sslContext != null || hostnameVerifier != null) {
httpClientBuilder.setConnectionManager(buildConnectionManager(sslContext, hostnameVerifier));
}
CloseableHttpClient httpClient = httpClientBuilder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
@@ -51,4 +52,18 @@ public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClie
return requestFactory;
}
private HttpClientConnectionManager buildConnectionManager(SSLContext sslContext,
HostnameVerifier hostnameVerifier) {
SSLConnectionSocketFactoryBuilder sslConnectionSocketFactoryBuilder = SSLConnectionSocketFactoryBuilder
.create();
if (sslContext != null) {
sslConnectionSocketFactoryBuilder.setSslContext(sslContext);
}
if (hostnameVerifier != null) {
sslConnectionSocketFactoryBuilder.setHostnameVerifier(hostnameVerifier);
}
return PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(sslConnectionSocketFactoryBuilder.build()).build();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -25,7 +25,6 @@ import javax.net.ssl.SSLContext;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.TransportClientFactory;
import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
/**
@@ -39,12 +38,6 @@ public class RestTemplateTransportClientFactories implements TransportClientFact
this.args = args;
}
@Override
public TransportClientFactory newTransportClientFactory(Collection<Void> additionalFilters,
EurekaJerseyClient providedJerseyClient) {
throw new UnsupportedOperationException();
}
@Override
public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig,
Collection<Void> additionalFilters, InstanceInfo myInstanceInfo) {
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -44,7 +44,7 @@ import com.netflix.discovery.shared.transport.TransportClientFactory;
import org.springframework.cloud.configuration.SSLContextFactory;
import org.springframework.cloud.configuration.TlsProperties;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.support.BasicAuthenticationInterceptor;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@@ -200,7 +200,7 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
class ErrorHandler extends DefaultResponseErrorHandler {
@Override
protected boolean hasError(HttpStatus statusCode) {
protected boolean hasError(HttpStatusCode statusCode) {
/**
* When the Eureka server restarts and a client tries to sent a heartbeat the
* server will respond with a 404. By default RestTemplate will throw an
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -26,7 +26,6 @@ import javax.net.ssl.SSLContext;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.TransportClientFactory;
import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.springframework.web.reactive.function.client.WebClient;
@@ -43,12 +42,6 @@ public class WebClientTransportClientFactories implements TransportClientFactori
this.builder = builder;
}
@Override
public TransportClientFactory newTransportClientFactory(Collection<Void> additionalFilters,
EurekaJerseyClient providedJerseyClient) {
throw new UnsupportedOperationException();
}
@Override
public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig,
Collection<Void> additionalFilters, InstanceInfo myInstanceInfo) {
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -16,10 +16,9 @@
package org.springframework.cloud.netflix.eureka.loadbalancer;
import javax.annotation.PostConstruct;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.EurekaClientConfig;
import jakarta.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -59,7 +59,7 @@ public class EurekaRegistration implements Registration {
private ObjectProvider<HealthCheckHandler> healthCheckHandler;
private EurekaRegistration(CloudEurekaInstanceConfig instanceConfig, EurekaClient eurekaClient,
public EurekaRegistration(CloudEurekaInstanceConfig instanceConfig, EurekaClient eurekaClient,
ApplicationInfoManager applicationInfoManager, ObjectProvider<HealthCheckHandler> healthCheckHandler) {
this.eurekaClient = eurekaClient;
this.instanceConfig = instanceConfig;
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -1,13 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration,\
org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration,\
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration,\
org.springframework.cloud.netflix.eureka.reactive.EurekaReactiveDiscoveryClientConfiguration,\
org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.netflix.eureka.config.EurekaConfigServerBootstrapConfiguration
org.springframework.boot.Bootstrapper=\
org.springframework.boot.BootstrapRegistryInitializer=\
org.springframework.cloud.netflix.eureka.config.EurekaConfigServerBootstrapper
@@ -0,0 +1,6 @@
org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration
org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
org.springframework.cloud.netflix.eureka.reactive.EurekaReactiveDiscoveryClientConfiguration
org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 the original author or authors.
* Copyright 2015-2022 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.
@@ -16,7 +16,7 @@
package org.springframework.cloud.netflix.eureka;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer
* @author Biju Kunjummen
*/
public class ConditionalOnRefreshScopeTests {
class ConditionalOnRefreshScopeTests {
@Test
public void refreshScopeIncluded() {
void refreshScopeIncluded() {
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
.withUserConfiguration(Beans.class).run(c -> {
assertThat(c).hasSingleBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class);
@@ -44,7 +44,7 @@ public class ConditionalOnRefreshScopeTests {
}
@Test
public void refreshScopeIncludedAndPropertyDisabled() {
void refreshScopeIncludedAndPropertyDisabled() {
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
.withPropertyValues("eureka.client.refresh.enable=false").withUserConfiguration(Beans.class).run(c -> {
assertThat(c).hasSingleBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class);
@@ -54,7 +54,7 @@ public class ConditionalOnRefreshScopeTests {
}
@Test
public void refreshScopeNotIncluded() {
void refreshScopeNotIncluded() {
new ApplicationContextRunner().withUserConfiguration(Beans.class).run(c -> {
assertThat(c).doesNotHaveBean("foo");
assertThat(c.getBean("bar")).isEqualTo("bar");
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -18,30 +18,27 @@ package org.springframework.cloud.netflix.eureka;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.InstanceInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Spencer Gibb
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class EurekaClientAutoConfigurationRandomPortTests {
class EurekaClientAutoConfigurationRandomPortTests {
@Autowired
private ApplicationInfoManager infoManager;
@Test
public void instanceInfoPortShouldNotBeZero() {
void instanceInfoPortShouldNotBeZero() {
InstanceInfo info = infoManager.getInfo();
assertThat(info.getPort()).isGreaterThan(0);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -23,20 +23,21 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient;
import com.sun.jersey.client.apache4.ApacheHttpClient4;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -51,6 +52,7 @@ import org.springframework.cloud.context.scope.GenericScope;
import org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration;
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -69,12 +71,12 @@ import static org.assertj.core.api.AssertionsForClassTypes.fail;
* @author Olga Maciaszek-Sharma
* @author Tim Ysewyn
*/
public class EurekaClientAutoConfigurationTests {
class EurekaClientAutoConfigurationTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@After
public void after() {
@AfterEach
void after() {
if (this.context != null && this.context.isActive()) {
this.context.close();
}
@@ -92,7 +94,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void shouldSetManagementPortInMetadataMapIfEqualToServerPort() throws Exception {
void shouldSetManagementPortInMetadataMapIfEqualToServerPort() throws Exception {
TestPropertyValues.of("server.port=8989").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -102,7 +104,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void shouldNotSetManagementAndJmxPortsInMetadataMap() throws Exception {
void shouldNotSetManagementAndJmxPortsInMetadataMap() throws Exception {
TestPropertyValues.of("server.port=8989", "management.server.port=0").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -113,7 +115,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void shouldSetManagementAndJmxPortsInMetadataMap() throws Exception {
void shouldSetManagementAndJmxPortsInMetadataMap() throws Exception {
TestPropertyValues.of("management.server.port=9999", "com.sun.management.jmxremote.port=6789")
.applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -124,7 +126,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void shouldNotResetManagementAndJmxPortsInMetadataMap() throws Exception {
void shouldNotResetManagementAndJmxPortsInMetadataMap() throws Exception {
TestPropertyValues.of("management.server.port=9999", "eureka.instance.metadata-map.jmx.port=9898",
"eureka.instance.metadata-map.management.port=7878").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -135,28 +137,28 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void nonSecurePortPeriods() {
void nonSecurePortPeriods() {
testNonSecurePort("server.port");
}
@Test
public void nonSecurePortUnderscores() {
void nonSecurePortUnderscores() {
testNonSecurePortSystemProp("SERVER_PORT");
}
@Test
public void nonSecurePort() {
void nonSecurePort() {
testNonSecurePortSystemProp("PORT");
assertThat(this.context.getBeanDefinition("eurekaClient").getFactoryMethodName()).isEqualTo("eurekaClient");
}
@Test
public void securePortPeriods() {
void securePortPeriods() {
testSecurePort("server.port");
}
@Test
public void securePortUnderscores() {
void securePortUnderscores() {
TestPropertyValues.of("eureka.instance.secure-port-enabled=true").applyTo(this.context);
addSystemEnvironment(this.context.getEnvironment(), "SERVER_PORT:8443");
setupContext();
@@ -164,13 +166,13 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void securePort() {
void securePort() {
testSecurePort("PORT");
assertThat(this.context.getBeanDefinition("eurekaClient").getFactoryMethodName()).isEqualTo("eurekaClient");
}
@Test
public void managementPort() {
void managementPort() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
@@ -179,7 +181,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlPathAndManagementPort() {
void statusPageUrlPathAndManagementPort() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
"eureka.instance.statusPageUrlPath=/myStatusPage").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -189,7 +191,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathAndManagementPort() {
void healthCheckUrlPathAndManagementPort() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
"eureka.instance.healthCheckUrlPath=/myHealthCheck").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -199,7 +201,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() throws Exception {
void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() throws Exception {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "server.contextPath=/service")
.applyTo(this.context);
@@ -212,7 +214,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_context_path() throws Exception {
TestPropertyValues.of("server.port=8989", "management.server.servlet.context-path=/management")
.applyTo(this.context);
@@ -225,7 +227,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port() throws Exception {
TestPropertyValues.of("server.port=0", "management.server.servlet.context-path=/management")
.applyTo(this.context);
@@ -238,7 +240,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlPathAndManagementPortAndContextPath() {
void statusPageUrlPathAndManagementPortAndContextPath() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
"management.server.servlet.context-path=/manage", "eureka.instance.status-page-url-path=/myStatusPage")
.applyTo(this.context);
@@ -249,7 +251,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathAndManagementPortAndContextPath() {
void healthCheckUrlPathAndManagementPortAndContextPath() {
TestPropertyValues
.of("server.port=8989", "management.server.port=9999", "management.server.servlet.context-path=/manage",
"eureka.instance.health-check-url-path=/myHealthCheck")
@@ -261,7 +263,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlPathAndManagementPortAndContextPathKebobCase() {
void statusPageUrlPathAndManagementPortAndContextPathKebobCase() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
"management.server.servlet.context-path=/manage", "eureka.instance.status-page-url-path=/myStatusPage")
.applyTo(this.context);
@@ -272,7 +274,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathAndManagementPortAndContextPathKebobCase() {
void healthCheckUrlPathAndManagementPortAndContextPathKebobCase() {
TestPropertyValues
.of("server.port=8989", "management.server.port=9999", "management.server.servlet.context-path=/manage",
"eureka.instance.health-check-url-path=/myHealthCheck")
@@ -284,7 +286,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrl_and_healthCheckUrl_contain_management_base_path() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_base_path() throws Exception {
TestPropertyValues.of("server.port=8989", "management.server.base-path=/management").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -296,7 +298,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrl_and_healthCheckUrl_contain_management_base_path_random_port() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_base_path_random_port() throws Exception {
TestPropertyValues.of("server.port=0", "management.server.base-path=/management").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -308,7 +310,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlPathAndManagementPortAndBasePath() {
void statusPageUrlPathAndManagementPortAndBasePath() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "management.server.base-path=/manage",
"eureka.instance.status-page-url-path=/myStatusPage").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -318,7 +320,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathAndManagementPortAndBasePath() {
void healthCheckUrlPathAndManagementPortAndBasePath() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "management.server.base-path=/manage",
"eureka.instance.health-check-url-path=/myHealthCheck").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -328,7 +330,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlPathAndManagementPortAndBasePathKebobCase() {
void statusPageUrlPathAndManagementPortAndBasePathKebobCase() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "management.server.base-path=/manage",
"eureka.instance.status-page-url-path=/myStatusPage").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -338,7 +340,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathAndManagementPortAndBasePathKebobCase() {
void healthCheckUrlPathAndManagementPortAndBasePathKebobCase() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "management.server.base-path=/manage",
"eureka.instance.health-check-url-path=/myHealthCheck").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -348,7 +350,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathWithServerPortAndContextPathKebobCase() {
void healthCheckUrlPathWithServerPortAndContextPathKebobCase() {
TestPropertyValues
.of("server.port=8989", "server.servlet.context-path=/servletContextPath",
"eureka.instance.health-check-url-path=${server.servlet.context-path:}/myHealthCheck")
@@ -360,7 +362,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlPathAndManagementPortKabobCase() {
void statusPageUrlPathAndManagementPortKabobCase() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
"eureka.instance.status-page-url-path=/myStatusPage").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -370,7 +372,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlAndPreferIpAddress() {
void statusPageUrlAndPreferIpAddress() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "eureka.instance.hostname=foo",
"eureka.instance.prefer-ip-address:true").applyTo(this.context);
@@ -384,7 +386,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageAndHealthCheckUrlsShouldSetUserDefinedIpAddress() {
void statusPageAndHealthCheckUrlsShouldSetUserDefinedIpAddress() {
TestPropertyValues
.of("server.port=8989", "management.server.port=9999", "eureka.instance.hostname=foo",
"eureka.instance.ip-address:192.168.13.90", "eureka.instance.prefer-ip-address:true")
@@ -400,7 +402,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathAndManagementPortKabobCase() {
void healthCheckUrlPathAndManagementPortKabobCase() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999",
"eureka.instance.health-check-url-path=/myHealthCheck").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -410,7 +412,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void statusPageUrlPathAndManagementPortUpperCase() {
void statusPageUrlPathAndManagementPortUpperCase() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999").applyTo(this.context);
addSystemEnvironment(this.context.getEnvironment(), "EUREKA_INSTANCE_STATUS_PAGE_URL_PATH=/myStatusPage");
setupContext(RefreshAutoConfiguration.class);
@@ -420,7 +422,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void healthCheckUrlPathAndManagementPortUpperCase() {
void healthCheckUrlPathAndManagementPortUpperCase() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999").applyTo(this.context);
addSystemEnvironment(this.context.getEnvironment(), "EUREKA_INSTANCE_HEALTH_CHECK_URL_PATH=/myHealthCheck");
setupContext(RefreshAutoConfiguration.class);
@@ -430,7 +432,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void hostname() {
void hostname() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "eureka.instance.hostname=foo")
.applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -440,7 +442,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void refreshScopedBeans() {
void refreshScopedBeans() {
setupContext(RefreshAutoConfiguration.class);
assertThat(this.context.getBeanDefinition("eurekaClient").getBeanClassName())
.startsWith(GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
@@ -448,9 +450,13 @@ public class EurekaClientAutoConfigurationTests {
.startsWith(GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void shouldReregisterHealthCheckHandlerAfterRefresh() throws Exception {
TestPropertyValues.of("eureka.client.healthcheck.enabled=true").applyTo(this.context);
void shouldReregisterHealthCheckHandlerAfterRefresh() throws Exception {
TestPropertyValues
.of("eureka.client.healthcheck.enabled=true", "spring.cloud.config.import-check.enabled=false",
"spring.cloud.refresh.additionalPropertySourcesToRetain=test")
.applyTo(this.context);
setupContext(RefreshAutoConfiguration.class, AutoServiceRegistrationConfiguration.class);
EurekaClient oldEurekaClient = getLazyInitEurekaClient();
@@ -462,6 +468,11 @@ public class EurekaClientAutoConfigurationTests {
assertThat(oldEurekaClient.getHealthCheckHandler()).isSameAs(healthCheckHandler);
ContextRefresher refresher = this.context.getBean(ContextRefresher.class);
if (refresher instanceof ApplicationListener) {
ApplicationListener<ApplicationPreparedEvent> listener = (ApplicationListener) refresher;
listener.onApplicationEvent(
new ApplicationPreparedEvent(Mockito.mock(SpringApplication.class), new String[0], this.context));
}
refresher.refresh();
EurekaClient newEurekaClient = getLazyInitEurekaClient();
@@ -474,7 +485,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void shouldCloseDiscoveryClient() throws Exception {
void shouldCloseDiscoveryClient() throws Exception {
TestPropertyValues.of("eureka.client.healthcheck.enabled=true").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class, AutoServiceRegistrationConfiguration.class);
@@ -489,7 +500,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void basicAuth() {
void basicAuth() {
TestPropertyValues
.of("server.port=8989", "eureka.client.serviceUrl.defaultZone=https://user:foo@example.com:80/eureka")
.applyTo(this.context);
@@ -499,7 +510,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void testDefaultAppName() throws Exception {
void testDefaultAppName() throws Exception {
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("unknown");
assertThat(getInstanceConfig().getVirtualHostName()).isEqualTo("unknown");
@@ -507,7 +518,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void testAppName() throws Exception {
void testAppName() throws Exception {
TestPropertyValues.of("spring.application.name=mytest").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytest");
@@ -516,7 +527,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void testAppNameUpper() throws Exception {
void testAppNameUpper() throws Exception {
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestupper");
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytestupper");
@@ -558,7 +569,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void testInstanceNamePreferred() throws Exception {
void testInstanceNamePreferred() throws Exception {
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestspringappname");
TestPropertyValues.of("eureka.instance.appname=mytesteurekaappname").applyTo(this.context);
setupContext();
@@ -566,13 +577,13 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void eurekaHealthIndicatorCreated() {
void eurekaHealthIndicatorCreated() {
setupContext();
this.context.getBean(EurekaHealthIndicator.class);
}
@Test
public void eurekaClientClosed() {
void eurekaClientClosed() {
setupContext(TestEurekaClientConfiguration.class);
if (this.context != null) {
CountDownLatch latch = this.context.getBean(CountDownLatch.class);
@@ -582,7 +593,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void eurekaConfigNotLoadedWhenDiscoveryClientDisabled() {
void eurekaConfigNotLoadedWhenDiscoveryClientDisabled() {
TestPropertyValues.of("spring.cloud.discovery.enabled=false").applyTo(this.context);
setupContext(TestConfiguration.class);
assertBeanNotPresent(EurekaClientConfigBean.class);
@@ -593,7 +604,7 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void shouldNotHaveDiscoveryClientWhenBlockingDiscoveryDisabled() {
void shouldNotHaveDiscoveryClientWhenBlockingDiscoveryDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
DiscoveryClientOptionalArgsConfiguration.class, EurekaClientAutoConfiguration.class,
@@ -659,8 +670,8 @@ public class EurekaClientAutoConfigurationTests {
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class, search = SearchStrategy.CURRENT)
public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config,
ApplicationContext context) {
return new CloudEurekaClient(manager, config, null, context) {
ApplicationContext context, AbstractDiscoveryClientOptionalArgs optionalArgs) {
return new CloudEurekaClient(manager, config, optionalArgs, context) {
@Override
public synchronized void shutdown() {
CountDownLatch latch = countDownLatch();
@@ -677,17 +688,15 @@ public class EurekaClientAutoConfigurationTests {
@Configuration(proxyBeanMethods = false)
protected static class MockClientConfiguration {
@Bean
public EurekaJerseyClient jerseyClient() {
EurekaJerseyClient mock = Mockito.mock(EurekaJerseyClient.class);
Mockito.when(mock.getClient()).thenReturn(apacheClient());
return mock;
}
@Bean
public ApacheHttpClient4 apacheClient() {
return Mockito.mock(ApacheHttpClient4.class);
}
// FIXME: 4.0
/*
* @Bean public EurekaJerseyClient jerseyClient() { EurekaJerseyClient mock =
* Mockito.mock(EurekaJerseyClient.class);
* Mockito.when(mock.getClient()).thenReturn(apacheClient()); return mock; }
*
* @Bean public ApacheHttpClient4 apacheClient() { return
* Mockito.mock(ApacheHttpClient4.class); }
*/
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -18,8 +18,8 @@ package org.springframework.cloud.netflix.eureka;
import java.util.Collections;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -34,19 +34,19 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
*/
public class EurekaClientConfigBeanTests {
class EurekaClientConfigBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@After
public void init() {
@AfterEach
void init() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void basicBinding() {
void basicBinding() {
TestPropertyValues.of("eureka.client.proxyHost=example.com").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
this.context.refresh();
@@ -54,7 +54,7 @@ public class EurekaClientConfigBeanTests {
}
@Test
public void serviceUrl() {
void serviceUrl() {
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:https://example.com").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
this.context.refresh();
@@ -64,7 +64,7 @@ public class EurekaClientConfigBeanTests {
}
@Test
public void serviceUrlWithCompositePropertySource() {
void serviceUrlWithCompositePropertySource() {
CompositePropertySource source = new CompositePropertySource("composite");
this.context.getEnvironment().getPropertySources().addFirst(source);
source.addPropertySource(new MapPropertySource("config", Collections.<String, Object>singletonMap(
@@ -79,7 +79,7 @@ public class EurekaClientConfigBeanTests {
}
@Test
public void serviceUrlWithDefault() {
void serviceUrlWithDefault() {
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:https://example.com").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
this.context.refresh();
@@ -87,7 +87,7 @@ public class EurekaClientConfigBeanTests {
}
@Test
public void serviceUrlWithCustomZone() {
void serviceUrlWithCustomZone() {
TestPropertyValues.of("eureka.client.serviceUrl.customZone:https://custom-example.com").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
this.context.refresh();
@@ -95,7 +95,7 @@ public class EurekaClientConfigBeanTests {
}
@Test
public void serviceUrlWithEmptyServiceUrls() {
void serviceUrlWithEmptyServiceUrls() {
TestPropertyValues.of("eureka.client.serviceUrl.defaultZone:").applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
this.context.refresh();
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -16,18 +16,23 @@
package org.springframework.cloud.netflix.eureka;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
import org.springframework.boot.actuate.health.CompositeHealthContributor;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthContributor;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.NamedContributor;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.boot.actuate.health.SimpleStatusAggregator;
import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicator;
@@ -44,26 +49,27 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Jakub Narloch
* @author Nowrin Anwar Joyita
* @author Olga Maciaszek-Sharma
*/
public class EurekaHealthCheckHandlerTests {
class EurekaHealthCheckHandlerTests {
private EurekaHealthCheckHandler healthCheckHandler;
@Before
public void setUp() {
@BeforeEach
void setUp() {
healthCheckHandler = new EurekaHealthCheckHandler(new SimpleStatusAggregator());
}
@Test
public void testNoHealthCheckRegistered() {
void testNoHealthCheckRegistered() {
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
assertThat(status).isEqualTo(InstanceStatus.UNKNOWN);
}
@Test
public void testAllUp() throws Exception {
void testAllUp() {
initialize(UpHealthConfiguration.class, ReactiveUpHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
@@ -71,7 +77,7 @@ public class EurekaHealthCheckHandlerTests {
}
@Test
public void testHealthCheckNotReturnedWhenStopped() throws Exception {
void testHealthCheckNotReturnedWhenStopped() {
initialize(UpHealthConfiguration.class);
healthCheckHandler.stop();
@@ -84,7 +90,7 @@ public class EurekaHealthCheckHandlerTests {
}
@Test
public void testDownWithBlockingIndicators() throws Exception {
void testDownWithBlockingIndicators() {
initialize(UpHealthConfiguration.class, DownHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
@@ -92,7 +98,7 @@ public class EurekaHealthCheckHandlerTests {
}
@Test
public void testDownWithReactiveIndicators() throws Exception {
void testDownWithReactiveIndicators() {
initialize(UpHealthConfiguration.class, ReactiveDownHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
@@ -100,7 +106,7 @@ public class EurekaHealthCheckHandlerTests {
}
@Test
public void testDownWhenBlockingIndicatorUpAndReactiveDown() throws Exception {
void testDownWhenBlockingIndicatorUpAndReactiveDown() {
initialize(ReactiveUpHealthConfiguration.class, DownHealthConfiguration.class);
InstanceStatus status = this.healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
@@ -108,7 +114,7 @@ public class EurekaHealthCheckHandlerTests {
}
@Test
public void testDownWhenBlockingIndicatorDownAndReactiveUp() throws Exception {
void testDownWhenBlockingIndicatorDownAndReactiveUp() {
initialize(ReactiveUpHealthConfiguration.class, ReactiveDownHealthConfiguration.class);
InstanceStatus status = this.healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
@@ -116,7 +122,7 @@ public class EurekaHealthCheckHandlerTests {
}
@Test
public void testUnknown() throws Exception {
void testUnknown() {
initialize(FatalHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
@@ -124,15 +130,38 @@ public class EurekaHealthCheckHandlerTests {
}
@Test
@Ignore // FIXME: 3.0.0
public void testEurekaIgnored() throws Exception {
void testEurekaIgnored() {
initialize(EurekaDownHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UP);
assertThat(status).isEqualTo(InstanceStatus.UP);
}
private void initialize(Class<?>... configurations) throws Exception {
@Test
void testCompositeComponentsDown() {
initialize(CompositeComponentsDownHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UP);
assertThat(status).isEqualTo(InstanceStatus.DOWN);
}
@Test
void testCompositeComponentsUp() {
initialize(CompositeComponentsUpHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UP);
assertThat(status).isEqualTo(InstanceStatus.UP);
}
@Test
void testCompositeComponentsOneDown() {
initialize(CompositeComponentsOneDownHealthConfiguration.class);
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UP);
assertThat(status).isEqualTo(InstanceStatus.DOWN);
}
private void initialize(Class<?>... configurations) {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(configurations);
healthCheckHandler.setApplicationContext(applicationContext);
healthCheckHandler.afterPropertiesSet();
@@ -144,7 +173,7 @@ public class EurekaHealthCheckHandlerTests {
public HealthIndicator healthIndicator() {
return new AbstractHealthIndicator() {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
builder.up();
}
};
@@ -158,7 +187,7 @@ public class EurekaHealthCheckHandlerTests {
public HealthIndicator healthIndicator() {
return new AbstractHealthIndicator() {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
builder.down();
}
};
@@ -172,7 +201,7 @@ public class EurekaHealthCheckHandlerTests {
public HealthIndicator healthIndicator() {
return new AbstractHealthIndicator() {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
builder.status("fatal");
}
};
@@ -238,4 +267,76 @@ public class EurekaHealthCheckHandlerTests {
}
protected static class CompositeComponentsDownHealthConfiguration {
@Bean
public CompositeHealthContributor compositeHealthContributor() {
return new TestCompositeHealthContributor(InstanceStatus.DOWN, InstanceStatus.DOWN);
}
}
protected static class CompositeComponentsUpHealthConfiguration {
@Bean
public CompositeHealthContributor compositeHealthContributor() {
return new TestCompositeHealthContributor(InstanceStatus.UP, InstanceStatus.UP);
}
}
protected static class CompositeComponentsOneDownHealthConfiguration {
@Bean
public CompositeHealthContributor compositeHealthContributor() {
return new TestCompositeHealthContributor(InstanceStatus.UP, InstanceStatus.DOWN);
}
}
static class TestCompositeHealthContributor implements CompositeHealthContributor {
private final Map<String, HealthContributor> contributorMap = new HashMap<>();
TestCompositeHealthContributor(InstanceStatus firstContributorStatus, InstanceStatus secondContributorStatus) {
contributorMap.put("first", new AbstractHealthIndicator() {
@Override
protected void doHealthCheck(Health.Builder builder) {
builder.status(firstContributorStatus.name());
}
});
contributorMap.put("second", new AbstractHealthIndicator() {
@Override
protected void doHealthCheck(Health.Builder builder) {
builder.status(secondContributorStatus.name());
}
});
}
@Override
public HealthContributor getContributor(String name) {
return contributorMap.get(name);
}
@Override
public Iterator<NamedContributor<HealthContributor>> iterator() {
Iterator<Map.Entry<String, HealthContributor>> iterator = contributorMap.entrySet().iterator();
return new Iterator<NamedContributor<HealthContributor>>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public NamedContributor<HealthContributor> next() {
Map.Entry<String, HealthContributor> entry = iterator.next();
return NamedContributor.of(entry.getKey(), entry.getValue());
}
};
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -17,9 +17,10 @@
package org.springframework.cloud.netflix.eureka;
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Ryan Baxter
* @author Tim Ysewyn
*/
public class EurekaInstanceConfigBeanTests {
class EurekaInstanceConfigBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@@ -51,8 +52,8 @@ public class EurekaInstanceConfigBeanTests {
private String ipAddress;
@Before
public void init() throws Exception {
@BeforeEach
void init() throws Exception {
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
InetUtils.HostInfo hostInfo = utils.findFirstNonLoopbackHostInfo();
this.hostName = hostInfo.getHostname();
@@ -60,29 +61,29 @@ public class EurekaInstanceConfigBeanTests {
}
}
@After
public void clear() {
@AfterEach
void clear() {
if (this.context != null) {
this.context.close();
}
}
@Test
public void basicBinding() {
void basicBinding() {
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getAppGroupName()).isEqualTo("mygroup");
}
@Test
public void nonSecurePort() {
void nonSecurePort() {
TestPropertyValues.of("eureka.instance.nonSecurePort:8888").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getNonSecurePort()).isEqualTo(8888);
}
@Test
public void instanceId() {
void instanceId() {
TestPropertyValues.of("eureka.instance.instanceId:special").applyTo(this.context);
setupContext();
EurekaInstanceConfigBean instance = getInstanceConfig();
@@ -90,7 +91,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void initialHostName() {
void initialHostName() {
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
setupContext();
if (this.hostName != null) {
@@ -99,7 +100,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void refreshHostName() {
void refreshHostName() {
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
setupContext();
ReflectionTestUtils.setField(getInstanceConfig(), "hostname", "marvin");
@@ -111,7 +112,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void refreshHostNameWhenSetByUser() {
void refreshHostNameWhenSetByUser() {
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
setupContext();
getInstanceConfig().setHostname("marvin");
@@ -121,7 +122,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void initialIpAddress() {
void initialIpAddress() {
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
setupContext();
if (this.ipAddress != null) {
@@ -130,7 +131,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void refreshIpAddress() {
void refreshIpAddress() {
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
setupContext();
ReflectionTestUtils.setField(getInstanceConfig(), "ipAddress", "10.0.0.1");
@@ -142,7 +143,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void refreshIpAddressWhenSetByUser() {
void refreshIpAddressWhenSetByUser() {
TestPropertyValues.of("eureka.instance.appGroupName=mygroup").applyTo(this.context);
setupContext();
getInstanceConfig().setIpAddress("10.0.0.1");
@@ -152,26 +153,27 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void testDefaultInitialStatus() {
void testDefaultInitialStatus() {
setupContext();
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong").isEqualTo(InstanceStatus.UP);
}
@Test(expected = BeanCreationException.class)
public void testBadInitialStatus() {
void testBadInitialStatus() {
TestPropertyValues.of("eureka.instance.initial-status:FOO").applyTo(this.context);
setupContext();
Assertions.assertThrows(BeanCreationException.class, () -> {
setupContext();
});
}
@Test
public void testCustomInitialStatus() {
void testCustomInitialStatus() {
TestPropertyValues.of("eureka.instance.initial-status:STARTING").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong").isEqualTo(InstanceStatus.STARTING);
}
@Test
public void testPreferIpAddress() throws Exception {
void testPreferIpAddress() throws Exception {
TestPropertyValues.of("eureka.instance.preferIpAddress:true").applyTo(this.context);
setupContext();
EurekaInstanceConfigBean instance = getInstanceConfig();
@@ -181,7 +183,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void testDefaultVirtualHostName() throws Exception {
void testDefaultVirtualHostName() throws Exception {
TestPropertyValues.of("spring.application.name:myapp").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getVirtualHostName()).as("virtualHostName wrong").isEqualTo("myapp");
@@ -190,7 +192,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void testCustomVirtualHostName() throws Exception {
void testCustomVirtualHostName() throws Exception {
TestPropertyValues.of("spring.application.name:myapp", "eureka.instance.virtualHostName=myvirthost",
"eureka.instance.secureVirtualHostName=mysecurevirthost").applyTo(this.context);
setupContext();
@@ -201,7 +203,7 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void testDefaultAppName() throws Exception {
void testDefaultAppName() throws Exception {
setupContext();
assertThat(getInstanceConfig().getAppname()).as("default app name is wrong").isEqualTo("unknown");
assertThat(getInstanceConfig().getVirtualHostName()).as("default virtual hostname is wrong")
@@ -211,21 +213,21 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public void testCustomInstanceId() throws Exception {
void testCustomInstanceId() throws Exception {
TestPropertyValues.of("eureka.instance.instanceId=myinstance").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
}
@Test
public void testCustomInstanceIdWithMetadata() throws Exception {
void testCustomInstanceIdWithMetadata() throws Exception {
TestPropertyValues.of("eureka.instance.metadataMap.instanceId=myinstance").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
}
@Test
public void testDefaultInstanceId() throws Exception {
void testDefaultInstanceId() throws Exception {
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("default instance id is wrong").isEqualTo(null);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -18,12 +18,12 @@ package org.springframework.cloud.netflix.eureka;
import com.netflix.appinfo.InstanceInfo;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class EurekaServiceInstanceTests {
class EurekaServiceInstanceTests {
@Test
public void getSchemeReturnsNonNull() {
void getSchemeReturnsNonNull() {
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test").setHostName("myhost")
.setPort(8080).build();
EurekaServiceInstance instance = new EurekaServiceInstance(instanceInfo);
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -19,7 +19,7 @@ package org.springframework.cloud.netflix.eureka;
import java.io.IOException;
import com.netflix.appinfo.InstanceInfo;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -32,12 +32,12 @@ import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
public class InstanceInfoFactoryTests {
class InstanceInfoFactoryTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test
public void instanceIdIsHostNameByDefault() throws IOException {
void instanceIdIsHostNameByDefault() throws IOException {
InstanceInfo instanceInfo = setupInstance();
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
assertThat(instanceInfo.getId()).isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname());
@@ -45,13 +45,13 @@ public class InstanceInfoFactoryTests {
}
@Test
public void instanceIdIsIpWhenIpPreferred() throws Exception {
void instanceIdIsIpWhenIpPreferred() throws Exception {
InstanceInfo instanceInfo = setupInstance("eureka.instance.preferIpAddress:true");
assertThat(instanceInfo.getId().matches("(\\d+\\.){3}\\d+")).isTrue();
}
@Test
public void instanceInfoIdIsInstanceIdWhenSet() {
void instanceInfoIdIsInstanceIdWhenSet() {
InstanceInfo instanceInfo = setupInstance("eureka.instance.instanceId:special");
assertThat(instanceInfo.getId()).isEqualTo("special");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -17,15 +17,13 @@
package org.springframework.cloud.netflix.eureka.config;
import com.netflix.discovery.EurekaClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.cloud.netflix.eureka.sample.RefreshEurekaSampleApplication;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.context.junit4.SpringRunner;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -34,9 +32,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
/**
* @author Ryan Baxter
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = RefreshEurekaSampleApplication.class)
public class ConfigRefreshTests {
class ConfigRefreshTests {
@Autowired
private ApplicationEventPublisher publisher;
@@ -51,7 +48,7 @@ public class ConfigRefreshTests {
// EurekaClientConfigurationRefresher.onApplicationEvent
// ensures that the EurekaClient bean is recreated after a refresh event and that we
// reregister the client with the server
public void verifyGetApplications() {
void verifyGetApplications() {
if (publisher != null) {
publisher.publishEvent(new RefreshScopeRefreshedEvent());
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -17,7 +17,7 @@
package org.springframework.cloud.netflix.eureka.config;
import com.netflix.appinfo.EurekaInstanceConfig;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer
* @author Biju Kunjummen
*/
public class EurekaClientConfigServerAutoConfigurationTests {
class EurekaClientConfigServerAutoConfigurationTests {
@Test
public void offByDefault() {
void offByDefault() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class)).run(c -> {
assertThat(c.getBeanNamesForType(EurekaInstanceConfigBean.class).length).isEqualTo(0);
@@ -41,7 +41,7 @@ public class EurekaClientConfigServerAutoConfigurationTests {
}
@Test
public void onWhenRequested() {
void onWhenRequested() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class,
ConfigServerProperties.class, EurekaInstanceConfigBean.class))
@@ -53,7 +53,7 @@ public class EurekaClientConfigServerAutoConfigurationTests {
}
@Test
public void notOverridingMetamapSettings() {
void notOverridingMetamapSettings() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class,
ConfigServerProperties.class, EurekaInstanceConfigBean.class))
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -33,6 +33,7 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
@@ -63,20 +64,101 @@ public class EurekaConfigServerBootstrapConfigurationTests {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.run(context -> {
assertThat(context).doesNotHaveBean(EurekaClientConfigBean.class);
assertThat(context).doesNotHaveBean(EurekaHttpClient.class);
assertThat(context).doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
assertEurekaBeansNotPresent(context);
});
}
@Test
public void properBeansCreatedWhenEnabled() {
public void properBeansCreatedWhenDiscoveryEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
assertEurekaBeansPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.disabled").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenEurekaClientEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.enabled=true").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenEurekaClientNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.enabled=false").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenEurekaClientDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.disabled").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void properBeansCreatedWhenDiscoveryEnabled_EurekaEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true")
.run(context -> {
assertEurekaBeansPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryEnabled_EurekaNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=false")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=true")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=false")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@@ -84,7 +166,7 @@ public class EurekaConfigServerBootstrapConfigurationTests {
public void eurekaDnsConfigurationWorks() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true",
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true",
"eureka.instance.hostname=eurekaclient1",
"eureka.client.use-dns-for-fetching-service-urls=true",
"eureka.client.eureka-server-d-n-s-name=myeurekahost",
@@ -100,6 +182,7 @@ public class EurekaConfigServerBootstrapConfigurationTests {
TomcatURLStreamHandlerFactory.disable();
new SpringApplicationBuilder(TestConfigDiscoveryConfiguration.class)
.properties("spring.config.use-legacy-processing=true", "spring.cloud.config.discovery.enabled=true",
"eureka.client.enabled=true",
"spring.main.sources=" + TestConfigDiscoveryBootstrapConfiguration.class.getName(),
"logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
.run();
@@ -107,6 +190,18 @@ public class EurekaConfigServerBootstrapConfigurationTests {
.contains("eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
}
private void assertEurekaBeansPresent(AssertableApplicationContext context) {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
}
private void assertEurekaBeansNotPresent(AssertableApplicationContext context) {
assertThat(context).doesNotHaveBean(EurekaClientConfigBean.class);
assertThat(context).doesNotHaveBean(EurekaHttpClient.class);
assertThat(context).doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
}
@SpringBootConfiguration
@EnableAutoConfiguration
protected static class TestConfigDiscoveryConfiguration {
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -22,7 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.netflix.eureka.http.WebClientEurekaHttpClient;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -38,11 +38,10 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
/**
* @author Spencer Gibb
*/
@SpringBootTest(
properties = { "spring.cloud.config.discovery.enabled=true", "spring.config.use-legacy-processing=true",
"eureka.client.webclient.enabled=true", "spring.codec.max-in-memory-size=310000" },
webEnvironment = RANDOM_PORT)
public class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@SpringBootTest(properties = { "spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true",
"spring.config.use-legacy-processing=true", "eureka.client.webclient.enabled=true",
"spring.codec.max-in-memory-size=310000" }, webEnvironment = RANDOM_PORT)
class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@LocalServerPort
private int port;
@@ -51,7 +50,7 @@ public class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
private WebClientEurekaHttpClient eurekaHttpClient;
@Test
public void webClientRespectsCodecProperties() {
void webClientRespectsCodecProperties() {
WebClient webClient = eurekaHttpClient.getWebClient();
ClientResponse response = webClient.get().uri("http://localhost:" + port).exchange().block();
assertThat(response).isNotNull();
@@ -64,7 +63,7 @@ public class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@RestController
static class WebClientController extends WebSecurityConfigurerAdapter {
@GetMapping
@GetMapping("/")
public String hello() {
StringBuilder s = new StringBuilder();
for (int i = 0; i < 300000; i++) {
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -16,7 +16,7 @@
package org.springframework.cloud.netflix.eureka.config;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -30,13 +30,13 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Spencer Gibb
*/
public class EurekaConfigServerBootstrapConfigurationWebClientTests {
class EurekaConfigServerBootstrapConfigurationWebClientTests {
@Test
public void properBeansCreatedWhenEnabled() {
void properBeansCreatedWhenEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true",
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true",
"eureka.client.webclient.enabled=true")
.run(context -> {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
@@ -46,10 +46,11 @@ public class EurekaConfigServerBootstrapConfigurationWebClientTests {
}
@Test
public void properBeansCreatedWhenEnabledWebClientDisabled() {
void properBeansCreatedWhenEnabledWebClientDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true")
.run(context -> {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).doesNotHaveBean(WebClientEurekaHttpClient.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -22,33 +22,59 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
import org.springframework.web.client.ResourceAccessException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
public class EurekaConfigServerBootstrapperTests {
class EurekaConfigServerBootstrapperTests {
@Test
public void notEnabledDoesNotAddInstanceProviderFn() {
void notEnabledReturnsEmptyList() {
new SpringApplicationBuilder(TestConfig.class)
.properties("spring.cloud.service-registry.auto-registration.enabled=false")
.addBootstrapper(registry -> registry.addCloseListener(event -> {
.addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> {
ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext()
.get(ConfigServerInstanceProvider.Function.class);
assertThat(providerFn).as("ConfigServerInstanceProvider.Function was created when it shouldn't")
.isNull();
assertThat(providerFn.apply("id")).as("Should return empty list").isEmpty();
})).run().close();
}
@Test
public void enabledAddsInstanceProviderFn() {
public void discoveryClientNotEnabledProvidesEmptyList() {
new SpringApplicationBuilder(TestConfig.class)
.properties("spring.cloud.config.discovery.enabled=true", "spring.cloud.discovery.enabled=false",
"spring.cloud.service-registry.auto-registration.enabled=false")
.addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> {
ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext()
.get(ConfigServerInstanceProvider.Function.class);
assertThat(providerFn.apply("id")).as("Should return empty list").isEmpty();
})).run().close();
}
@Test
public void eurekaClientNotEnabledProvidesEmptyList() {
new SpringApplicationBuilder(TestConfig.class)
.properties("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=false",
"spring.cloud.service-registry.auto-registration.enabled=false")
.addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> {
ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext()
.get(ConfigServerInstanceProvider.Function.class);
assertThat(providerFn.apply("id")).as("Should return empty list").isEmpty();
})).run().close();
}
@Test
void enabledAddsInstanceProviderFn() {
new SpringApplicationBuilder(TestConfig.class)
.properties("spring.cloud.config.discovery.enabled=true",
"spring.cloud.service-registry.auto-registration.enabled=false")
.addBootstrapper(registry -> registry.addCloseListener(event -> {
.addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> {
ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext()
.get(ConfigServerInstanceProvider.Function.class);
assertThat(providerFn).as("ConfigServerInstanceProvider.Function was not created when it should.")
.isNotNull();
assertThatThrownBy(() -> providerFn.apply("id")).isInstanceOf(ResourceAccessException.class)
.hasMessageContaining("I/O error on GET request for \"http://localhost:8761/eureka/apps/\"")
.as("Should have tried to connect to Eureka to fetch instances.");
})).run().close();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -52,7 +52,7 @@ public class EurekaHttpClientsOptionalArgsConfigurationNoWebfluxTest {
}
catch (Exception e) {
// this is the desired state
assertThat(e).hasMessageContaining("WebClient is not on the classpath");
assertThat(e).hasStackTraceContaining("WebClient is not on the classpath");
}
if (ctx != null) {
ctx.close();
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -16,33 +16,28 @@
package org.springframework.cloud.netflix.eureka.config;
import com.netflix.discovery.DiscoveryClient.DiscoveryClientOptionalArgs;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.netflix.eureka.sample.EurekaSampleApplication;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Daniel Lavoie
*/
@DirtiesContext
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class JerseyOptionalArgsConfigurationTest {
class JerseyOptionalArgsConfigurationTest {
@Autowired
private DiscoveryClientOptionalArgs optionalArgs;
// @Autowired
// private DiscoveryClientOptionalArgs optionalArgs;
@Test
public void contextLoads() {
assertThat(optionalArgs).isNotNull();
@Disabled // FIXME: 4.0.0
void contextLoads() {
// assertThat(optionalArgs).isNotNull();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 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.
@@ -18,8 +18,7 @@ package org.springframework.cloud.netflix.eureka.healthcheck;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
@@ -30,7 +29,6 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,24 +36,36 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests the Eureka health check handler.
*
* @author Jakub Narloch
* @author Olga Maciaszek-Sharma
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = EurekaHealthCheckTests.EurekaHealthCheckApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT, value = { "eureka.client.healthcheck.enabled=true", "debug=true" })
@DirtiesContext
public class EurekaHealthCheckTests {
class EurekaHealthCheckTests {
@Autowired
private EurekaClient discoveryClient;
@Test
public void shouldRegisterService() {
void shouldRegisterService() {
System.setProperty("status", "UP");
InstanceInfo.InstanceStatus status = this.discoveryClient.getHealthCheckHandler()
.getStatus(InstanceInfo.InstanceStatus.UNKNOWN);
assertThat(status).isNotNull();
assertThat(status).isEqualTo(InstanceInfo.InstanceStatus.OUT_OF_SERVICE);
assertThat(status).isEqualTo(InstanceInfo.InstanceStatus.UP);
}
@Test
void shouldMapOutOfServiceToDown() {
System.setProperty("status", "OUT_OF_SERVICE");
InstanceInfo.InstanceStatus status = this.discoveryClient.getHealthCheckHandler()
.getStatus(InstanceInfo.InstanceStatus.UNKNOWN);
assertThat(status).isNotNull();
assertThat(status).isEqualTo(InstanceInfo.InstanceStatus.DOWN);
}
@Configuration(proxyBeanMethods = false)
@@ -64,7 +74,7 @@ public class EurekaHealthCheckTests {
@Bean
public HealthIndicator healthIndicator() {
return () -> new Health.Builder().outOfService().build();
return () -> new Health.Builder().status(System.getProperty("status")).build();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -19,7 +19,8 @@ package org.springframework.cloud.netflix.eureka.http;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.Applications;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
@@ -28,80 +29,81 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Haytham Mohamed
**/
public abstract class AbstractEurekaHttpClientTest {
abstract class AbstractEurekaHttpClientTest {
protected EurekaHttpClient eurekaHttpClient;
protected InstanceInfo info;
abstract public void setup();
abstract void setup();
@Test
public void testRegister() {
void testRegister() {
assertThat(eurekaHttpClient.register(info).getStatusCode()).isEqualTo(HttpStatus.OK.value());
}
@Test
public void testCancel() {
void testCancel() {
assertThat(eurekaHttpClient.cancel("test", "test").getStatusCode()).isEqualTo(HttpStatus.OK.value());
}
@Test
public void testSendHeartBeat() {
void testSendHeartBeat() {
assertThat(eurekaHttpClient.sendHeartBeat("test", "test", info, null).getStatusCode())
.isEqualTo(HttpStatus.OK.value());
}
@Test
public void testSendHeartBeatFourOFour() {
void testSendHeartBeatFourOFour() {
assertThat(eurekaHttpClient.sendHeartBeat("fourOFour", "test", info, null).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND.value());
}
@Test
public void testStatusUpdate() {
void testStatusUpdate() {
assertThat(eurekaHttpClient.statusUpdate("test", "test", InstanceInfo.InstanceStatus.UP, info).getStatusCode())
.isEqualTo(HttpStatus.OK.value());
}
@Test
public void testDeleteStatusOverride() {
void testDeleteStatusOverride() {
assertThat(eurekaHttpClient.deleteStatusOverride("test", "test", info).getStatusCode())
.isEqualTo(HttpStatus.OK.value());
}
@Test
public void testGetApplications() {
@Disabled // FIXME: 4.0
void testGetApplications() {
Applications entity = eurekaHttpClient.getApplications().getEntity();
assertThat(entity).isNotNull();
assertThat(eurekaHttpClient.getApplications("us", "eu").getEntity()).isNotNull();
}
@Test
public void testGetDelta() {
void testGetDelta() {
eurekaHttpClient.getDelta().getEntity();
eurekaHttpClient.getDelta("us", "eu").getEntity();
}
@Test
public void testGetVips() {
void testGetVips() {
eurekaHttpClient.getVip("test");
eurekaHttpClient.getVip("test", "us", "eu");
}
@Test
public void testGetSecureVip() {
void testGetSecureVip() {
eurekaHttpClient.getSecureVip("test");
eurekaHttpClient.getSecureVip("test", "us", "eu");
}
@Test
public void testGetApplication() {
void testGetApplication() {
eurekaHttpClient.getApplication("test");
}
@Test
public void testGetInstance() {
void testGetInstance() {
eurekaHttpClient.getInstance("test");
eurekaHttpClient.getInstance("test", "test");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -54,7 +54,7 @@ import static com.netflix.appinfo.InstanceInfo.DEFAULT_SECURE_PORT;
import static org.springframework.util.Assert.isTrue;
/**
* Mocked Eureka Server
* Mocked Eureka Server.
*
* @author Daniel Lavoie
*/
@@ -86,7 +86,7 @@ public class EurekaServerMockApplication {
/**
* Simulates Eureka Server own's serialization.
* @return
* @return converter
*/
@Bean
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -18,8 +18,7 @@ package org.springframework.cloud.netflix.eureka.http;
import com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider;
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -28,16 +27,14 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Daniel Lavoie
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = EurekaServerMockApplication.class,
properties = { "debug=true", "security.basic.enabled=true" }, webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class RestTemplateEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
class RestTemplateEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
@Autowired
private InetUtils inetUtils;
@@ -45,8 +42,8 @@ public class RestTemplateEurekaHttpClientTest extends AbstractEurekaHttpClientTe
@Value("http://${security.user.name}:${security.user.password}@localhost:${local.server.port}")
private String serviceUrl;
@Before
public void setup() {
@BeforeEach
void setup() {
eurekaHttpClient = new RestTemplateTransportClientFactory().newClient(new DefaultEndpoint(serviceUrl));
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
@@ -1,32 +0,0 @@
/*
* Copyright 2017-2020 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.netflix.eureka.http;
import org.junit.Test;
/**
* @author Daniel Lavoie
*/
public class RestTemplateTransportClientFactoriesTest {
@Test(expected = UnsupportedOperationException.class)
public void testJerseyIsUnsuported() {
new RestTemplateTransportClientFactories(new RestTemplateDiscoveryClientOptionalArgs(null))
.newTransportClientFactory(null, null);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -17,39 +17,39 @@
package org.springframework.cloud.netflix.eureka.http;
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* @author Daniel Lavoie
*/
public class RestTemplateTransportClientFactoryTest {
class RestTemplateTransportClientFactoryTest {
private RestTemplateTransportClientFactory transportClientFatory;
@Before
public void setup() {
@BeforeEach
void setup() {
transportClientFatory = new RestTemplateTransportClientFactory();
}
@Test
public void testWithoutUserInfo() {
void testWithoutUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://localhost:8761"));
}
@Test
public void testInvalidUserInfo() {
void testInvalidUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://test@localhost:8761"));
}
@Test
public void testUserInfo() {
void testUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://test:test@localhost:8761"));
}
@After
public void shutdown() {
@AfterEach
void shutdown() {
transportClientFatory.shutdown();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -18,8 +18,7 @@ package org.springframework.cloud.netflix.eureka.http;
import com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider;
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -28,18 +27,16 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.reactive.function.client.WebClient;
/**
* @author Daniel Lavoie
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = EurekaServerMockApplication.class,
properties = { "debug=true", "security.basic.enabled=true", "eureka.client.webclient.enabled=true" },
webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class WebClientEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
class WebClientEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
@Autowired
private InetUtils inetUtils;
@@ -47,8 +44,8 @@ public class WebClientEurekaHttpClientTest extends AbstractEurekaHttpClientTest
@Value("http://${security.user.name}:${security.user.password}@localhost:${local.server.port}")
private String serviceUrl;
@Before
public void setup() {
@BeforeEach
void setup() {
eurekaHttpClient = new WebClientTransportClientFactory(WebClient::builder)
.newClient(new DefaultEndpoint(serviceUrl));
@@ -1,33 +0,0 @@
/*
* Copyright 2017-2020 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.netflix.eureka.http;
import org.junit.Test;
import org.springframework.web.reactive.function.client.WebClient;
/**
* @author Daniel Lavoie
*/
public class WebClientTransportClientFactoriesTest {
@Test(expected = UnsupportedOperationException.class)
public void testJerseyIsUnsuported() {
new WebClientTransportClientFactories(WebClient::builder).newTransportClientFactory(null, null);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -17,41 +17,41 @@
package org.springframework.cloud.netflix.eureka.http;
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.web.reactive.function.client.WebClient;
/**
* @author Daniel Lavoie
*/
public class WebClientTransportClientFactoryTest {
class WebClientTransportClientFactoryTest {
private WebClientTransportClientFactory transportClientFatory;
@Before
public void setup() {
@BeforeEach
void setup() {
transportClientFatory = new WebClientTransportClientFactory(WebClient::builder);
}
@Test
public void testWithoutUserInfo() {
void testWithoutUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://localhost:8761"));
}
@Test
public void testInvalidUserInfo() {
void testInvalidUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://test@localhost:8761"));
}
@Test
public void testUserInfo() {
void testUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://test:test@localhost:8761"));
}
@After
public void shutdown() {
@AfterEach
void shutdown() {
transportClientFatory.shutdown();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 the original author or authors.
* Copyright 2015-2022 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.
@@ -57,14 +57,14 @@ class EurekaLoadBalancerClientConfigurationTests {
}
@Test
public void shouldSetZoneToDefaultWhenNotSetInMetadata() {
void shouldSetZoneToDefaultWhenNotSetInMetadata() {
postprocessor.postprocess();
assertThat(zoneConfig.getZone()).isEqualTo("defaultZone");
}
@Test
public void shouldResolveApproximateZoneFromHost() {
void shouldResolveApproximateZoneFromHost() {
eurekaInstanceConfig.setHostname("this.is.a.test.com");
eurekaLoadBalancerProperties.setApproximateZoneFromHostname(true);
@@ -74,7 +74,7 @@ class EurekaLoadBalancerClientConfigurationTests {
}
@Test
public void disabledViaProperty() {
void disabledViaProperty() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(LoadBalancerEurekaAutoConfiguration.class))
.withPropertyValues("eureka.client.enabled=false").run(context -> {
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2022 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.
@@ -16,8 +16,8 @@
package org.springframework.cloud.netflix.eureka.metadata;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
@@ -26,14 +26,14 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class DefaultManagementMetadataProviderTest {
class DefaultManagementMetadataProviderTest {
private static final EurekaInstanceConfigBean INSTANCE = mock(EurekaInstanceConfigBean.class);
private final ManagementMetadataProvider provider = new DefaultManagementMetadataProvider();
@Before
public void setUp() throws Exception {
@BeforeEach
void setUp() throws Exception {
when(INSTANCE.getHostname()).thenReturn("host");
when(INSTANCE.getHealthCheckUrlPath()).thenReturn("health");
when(INSTANCE.getStatusPageUrlPath()).thenReturn("info");
@@ -41,7 +41,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortIsRandomAndManagementPortIsNull() throws Exception {
void serverPortIsRandomAndManagementPortIsNull() throws Exception {
int serverPort = 0;
String serverContextPath = "/";
String managementContextPath = null;
@@ -53,7 +53,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void managementPortIsRandom() throws Exception {
void managementPortIsRandom() throws Exception {
int serverPort = 0;
String serverContextPath = "/";
String managementContextPath = null;
@@ -65,7 +65,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPort() throws Exception {
void serverPort() throws Exception {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = null;
@@ -80,7 +80,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortManagementPort() throws Exception {
void serverPortManagementPort() throws Exception {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = null;
@@ -95,7 +95,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortManagementPortServerContextPath() throws Exception {
void serverPortManagementPortServerContextPath() throws Exception {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = null;
@@ -110,7 +110,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortManagementPortServerContextPathManagementContextPath() throws Exception {
void serverPortManagementPortServerContextPathManagementContextPath() throws Exception {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = "/Management";
@@ -125,7 +125,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortServerContextPathManagementContextPath() throws Exception {
void serverPortServerContextPathManagementContextPath() throws Exception {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = "/Management";
@@ -140,7 +140,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortManagementContextPath() throws Exception {
void serverPortManagementContextPath() throws Exception {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -155,7 +155,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortServerContextPath() throws Exception {
void serverPortServerContextPath() throws Exception {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = null;
@@ -170,7 +170,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void serverPortManagementPortManagementContextPath() throws Exception {
void serverPortManagementPortManagementContextPath() throws Exception {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -186,7 +186,7 @@ public class DefaultManagementMetadataProviderTest {
}
@Test
public void setSecureHealthCheckUrl() throws Exception {
void setSecureHealthCheckUrl() throws Exception {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2022 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.
@@ -41,7 +41,7 @@ class EurekaReactiveDiscoveryClientConfigurationTests {
DiscoveryClientOptionalArgsConfiguration.class, EurekaReactiveDiscoveryClientConfiguration.class));
@Test
public void shouldWorkWithDefaults() {
void shouldWorkWithDefaults() {
contextRunner.run(context -> {
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
@@ -49,7 +49,7 @@ class EurekaReactiveDiscoveryClientConfigurationTests {
}
@Test
public void shouldNotHaveDiscoveryClientWhenDiscoveryDisabled() {
void shouldNotHaveDiscoveryClientWhenDiscoveryDisabled() {
contextRunner.withPropertyValues("spring.cloud.discovery.enabled=false").run(context -> {
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
@@ -57,7 +57,7 @@ class EurekaReactiveDiscoveryClientConfigurationTests {
}
@Test
public void shouldNotHaveDiscoveryClientWhenReactiveDiscoveryDisabled() {
void shouldNotHaveDiscoveryClientWhenReactiveDiscoveryDisabled() {
contextRunner.withPropertyValues("spring.cloud.discovery.reactive.enabled=false").run(context -> {
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
@@ -65,7 +65,7 @@ class EurekaReactiveDiscoveryClientConfigurationTests {
}
@Test
public void shouldNotHaveDiscoveryClientWhenEurekaClientDisabled() {
void shouldNotHaveDiscoveryClientWhenEurekaClientDisabled() {
contextRunner.withPropertyValues("eureka.client.enabled=false").run(context -> {
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
@@ -73,7 +73,7 @@ class EurekaReactiveDiscoveryClientConfigurationTests {
}
@Test
public void worksWithoutWebflux() {
void worksWithoutWebflux() {
contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.web.reactive")).run(context -> {
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
@@ -81,7 +81,7 @@ class EurekaReactiveDiscoveryClientConfigurationTests {
}
@Test
public void worksWithoutActuator() {
void worksWithoutActuator() {
contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")).run(context -> {
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2022 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.
@@ -54,13 +54,13 @@ class EurekaReactiveDiscoveryClientTests {
private EurekaReactiveDiscoveryClient client;
@Test
public void verifyDefaults() {
void verifyDefaults() {
assertThat(client.description()).isEqualTo("Spring Cloud Eureka Reactive Discovery Client");
assertThat(client.getOrder()).isEqualTo(ReactiveDiscoveryClient.DEFAULT_ORDER);
}
@Test
public void verifyDefaultsWhenUsingEurekaClientConfigBean() {
void verifyDefaultsWhenUsingEurekaClientConfigBean() {
EurekaClientConfigBean configBean = new EurekaClientConfigBean();
configBean.setOrder(1);
EurekaReactiveDiscoveryClient client = new EurekaReactiveDiscoveryClient(eurekaClient, configBean);
@@ -69,14 +69,14 @@ class EurekaReactiveDiscoveryClientTests {
}
@Test
public void shouldReturnEmptyFluxOfServices() {
void shouldReturnEmptyFluxOfServices() {
when(eurekaClient.getApplications()).thenReturn(new Applications());
Flux<String> services = this.client.getServices();
StepVerifier.create(services).expectNextCount(0).expectComplete().verify();
}
@Test
public void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() {
void shouldReturnEmptyFluxOfServicesWhenNoInstancesFound() {
Applications applications = new Applications();
applications.addApplication(new Application("my-service"));
when(eurekaClient.getApplications()).thenReturn(applications);
@@ -85,7 +85,7 @@ class EurekaReactiveDiscoveryClientTests {
}
@Test
public void shouldReturnFluxOfServices() {
void shouldReturnFluxOfServices() {
Applications applications = new Applications();
Application app = new Application("my-service");
app.addInstance(new InstanceInfo("instance", "my-service", "", "127.0.0.1", "", null, null, "", "", "", "", "",
@@ -97,14 +97,14 @@ class EurekaReactiveDiscoveryClientTests {
}
@Test
public void shouldReturnEmptyFluxForNonExistingService() {
void shouldReturnEmptyFluxForNonExistingService() {
when(eurekaClient.getInstancesByVipAddress("nonexistent-service", false)).thenReturn(emptyList());
Flux<ServiceInstance> instances = this.client.getInstances("nonexistent-service");
StepVerifier.create(instances).expectNextCount(0).expectComplete().verify();
}
@Test
public void shouldReturnFluxOfServiceInstances() {
void shouldReturnFluxOfServiceInstances() {
InstanceInfo instanceInfo = new InstanceInfo(
new InstanceInfo("instance", "my-service", "", "127.0.0.1", "", null, null, "", "", "", "", "", "", 0,
null, "", null, null, null, null, null, null, null, null, null, null));

Some files were not shown because too many files have changed in this diff Show More