mirror of
https://github.com/spring-cloud/spring-cloud-netflix.git
synced 2026-09-17 23:59:04 +00:00
Compare commits
99
Commits
v3.0.0-RC1
...
v3.0.6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
852e72f5e6 | ||
|
|
8b2b6b5115 | ||
|
|
f015f5cad4 | ||
|
|
612b6edb41 | ||
|
|
b633c8af96 | ||
|
|
079ae668c0 | ||
|
|
83c74b0017 | ||
|
|
827be605b3 | ||
|
|
927a51c21c | ||
|
|
5da06943c0 | ||
|
|
912fa949ff | ||
|
|
a86dba2659 | ||
|
|
76ab698306 | ||
|
|
df6df5d1dd | ||
|
|
1327bcb7d0 | ||
|
|
d925a03343 | ||
|
|
e4e1003dd8 | ||
|
|
829c1773cf | ||
|
|
bf8ba5c7b5 | ||
|
|
d532f4de31 | ||
|
|
0490150344 | ||
|
|
86797d0f12 | ||
|
|
960fb64e39 | ||
|
|
02100d9d46 | ||
|
|
247832e106 | ||
|
|
5cf48fadfb | ||
|
|
76b21a4a2a | ||
|
|
81ee8de8a2 | ||
|
|
cf9c645f4a | ||
|
|
3a402fbef5 | ||
|
|
6b165d83f0 | ||
|
|
cac519d89c | ||
|
|
04937f0113 | ||
|
|
e723f67f5a | ||
|
|
2176987868 | ||
|
|
1d46777c20 | ||
|
|
3e60fd4096 | ||
|
|
89c37a3842 | ||
|
|
17e72988dc | ||
|
|
849f1e7e99 | ||
|
|
3f4c702aa5 | ||
|
|
907c85f7c2 | ||
|
|
1bd64613d1 | ||
|
|
6648caf96d | ||
|
|
80e4408de7 | ||
|
|
86101cd733 | ||
|
|
1cb2aa34d3 | ||
|
|
a5734695b7 | ||
|
|
14c7ac2dda | ||
|
|
f151c881de | ||
|
|
e839d1dfbd | ||
|
|
6ad1ab2c76 | ||
|
|
e8ed3c3bd1 | ||
|
|
c5268f0d89 | ||
|
|
2b33f7a8b6 | ||
|
|
848bfab4ee | ||
|
|
4646484a30 | ||
|
|
6f1332ee72 | ||
|
|
98048189dd | ||
|
|
43fe8c1e62 | ||
|
|
ec6b111956 | ||
|
|
a1e166a814 | ||
|
|
a562fd0815 | ||
|
|
d9bc811fac | ||
|
|
806025307e | ||
|
|
92e7f572ba | ||
|
|
bff9419201 | ||
|
|
7b90195ee8 | ||
|
|
df7ecf81c9 | ||
|
|
e2236a816e | ||
|
|
f2526d5e03 | ||
|
|
8e00d28bcc | ||
|
|
92cb1a7aa0 | ||
|
|
8ecb3dca51 | ||
|
|
53e3639366 | ||
|
|
c145e4610d | ||
|
|
659a97ad63 | ||
|
|
51918d1659 | ||
|
|
63134d9f47 | ||
|
|
df64a02013 | ||
|
|
2aedbcaaa6 | ||
|
|
74f7c0eefd | ||
|
|
47e4d6396b | ||
|
|
ca65e05acb | ||
|
|
bb72b973bf | ||
|
|
4978f8f7de | ||
|
|
0b490f6d27 | ||
|
|
0092fb50d9 | ||
|
|
c6141c5b15 | ||
|
|
992269781a | ||
|
|
1d6a5876fb | ||
|
|
de5d517bfe | ||
|
|
7bf8f60c0e | ||
|
|
cdbbb7ad10 | ||
|
|
47c678f53b | ||
|
|
5d19ac3b08 | ||
|
|
9c40720aa6 | ||
|
|
1e45946555 | ||
|
|
e44e36d31a |
@@ -3,7 +3,7 @@
|
||||
|
||||
Spring Cloud is released under the non-restrictive Apache 2.0 license,
|
||||
and follows a very standard Github development process, using Github
|
||||
tracker for issues and merging pull requests into master. If you want
|
||||
tracker for issues and merging pull requests into main. If you want
|
||||
to contribute even something trivial please do not hesitate, but
|
||||
follow the guidelines below.
|
||||
|
||||
@@ -17,7 +17,7 @@ given the ability to merge pull requests.
|
||||
|
||||
## Code of Conduct
|
||||
This project adheres to the Contributor Covenant [code of
|
||||
conduct](https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc). By participating, you are expected to uphold this code. Please report
|
||||
conduct](https://github.com/spring-cloud/spring-cloud-build/blob/main/docs/src/main/asciidoc/code-of-conduct.adoc). By participating, you are expected to uphold this code. Please report
|
||||
unacceptable behavior to spring-code-of-conduct@pivotal.io.
|
||||
|
||||
## Code Conventions and Housekeeping
|
||||
@@ -27,7 +27,7 @@ added after the original pull request but before a merge.
|
||||
* Use the Spring Framework code format conventions. If you use Eclipse
|
||||
you can import formatter settings using the
|
||||
`eclipse-code-formatter.xml` file from the
|
||||
[Spring Cloud Build](https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml) project. If using IntelliJ, you can use the
|
||||
[Spring Cloud Build](https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-dependencies-parent/eclipse-code-formatter.xml) project. If using IntelliJ, you can use the
|
||||
[Eclipse Code Formatter Plugin](https://plugins.jetbrains.com/plugin/6546) to import the same file.
|
||||
* Make sure all new `.java` files to have a simple Javadoc class comment with at least an
|
||||
`@author` tag identifying you, and preferably at least a paragraph on what the class is
|
||||
@@ -38,7 +38,7 @@ added after the original pull request but before a merge.
|
||||
than cosmetic changes).
|
||||
* Add some Javadocs and, if you change the namespace, some XSD doc elements.
|
||||
* A few unit tests would help a lot as well -- someone has to do it.
|
||||
* If no-one else is using your branch, please rebase it against the current master (or
|
||||
* If no-one else is using your branch, please rebase it against the current main (or
|
||||
other target branch in the main project).
|
||||
* When writing a commit message please follow [these conventions](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html),
|
||||
if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
require 'asciidoctor'
|
||||
require 'erb'
|
||||
|
||||
options = {:mkdirs => true, :safe => :unsafe, :attributes => ['linkcss', 'allow-uri-read']}
|
||||
|
||||
guard 'shell' do
|
||||
watch(/^docs\/[A-Z-a-z][^#]*\.adoc$/) {|m|
|
||||
Asciidoctor.load_file('docs/src/main/asciidoc/README.adoc', :to_file => './README.adoc', safe: :safe, parse: false, attributes: 'allow-uri-read')
|
||||
Asciidoctor.render_file('docs/src/main/asciidoc/spring-cloud-netflix.adoc', options.merge(:to_dir => 'target/generated-docs'))
|
||||
}
|
||||
end
|
||||
+69
-66
@@ -4,6 +4,7 @@ Manual changes to this file will be lost when it is generated again.
|
||||
Edit the files in the src/main/asciidoc/ directory instead.
|
||||
////
|
||||
|
||||
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
@@ -20,8 +21,8 @@ Edit the files in the src/main/asciidoc/ directory instead.
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Netflix
|
||||
|
||||
image::https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/master.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/master"]
|
||||
image::https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/master/graph/badge.svg["Codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/master"]
|
||||
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"]
|
||||
|
||||
|
||||
@@ -45,63 +46,19 @@ This project provides Netflix OSS integrations for Spring Boot apps through auto
|
||||
and binding to the Spring Environment and other Spring programming model idioms. With a few
|
||||
simple annotations you can quickly enable and configure the common patterns inside your
|
||||
application and build large distributed systems with battle-tested Netflix components. The
|
||||
patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix),
|
||||
Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon).
|
||||
patterns provided include Service Discovery (Eureka).
|
||||
|
||||
|
||||
== Features
|
||||
|
||||
* Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
|
||||
* Service Discovery: an embedded Eureka server can be created with declarative Java configuration
|
||||
* Circuit Breaker: Hystrix clients can be built with a simple annotation-driven method decorator
|
||||
* Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration
|
||||
* Client Side Load Balancer: Ribbon
|
||||
* External Configuration: a bridge from the Spring Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions)
|
||||
* Router and Filter: automatic registration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation
|
||||
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
:sectnums:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:docinfo: shared,private
|
||||
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Netflix
|
||||
|
||||
== Modules In Maintenance Mode
|
||||
|
||||
Placing a module in maintenance mode means that the Spring Cloud team will no longer be adding new features to the module.
|
||||
We will fix blocker bugs and security issues, and we will also consider and review small pull requests from the community.
|
||||
|
||||
We intend to continue to support these modules for a period of at least a year from the general availability
|
||||
of the Greenwich release train.
|
||||
|
||||
The following Spring Cloud Netflix modules and corresponding starters will be placed into maintenance mode:
|
||||
|
||||
* spring-cloud-netflix-archaius
|
||||
* spring-cloud-netflix-concurrency-limits
|
||||
* spring-cloud-netflix-hystrix-contract
|
||||
* spring-cloud-netflix-hystrix-dashboard
|
||||
* spring-cloud-netflix-hystrix-stream
|
||||
* spring-cloud-netflix-hystrix
|
||||
* spring-cloud-netflix-ribbon
|
||||
* spring-cloud-netflix-turbine-stream
|
||||
* spring-cloud-netflix-turbine
|
||||
* spring-cloud-netflix-zuul
|
||||
|
||||
NOTE: This does not include the Eureka modules.
|
||||
|
||||
|
||||
== Building
|
||||
|
||||
:jdkversion: 1.8
|
||||
|
||||
:jdkversion: 17
|
||||
|
||||
=== Basic Compile and Test
|
||||
|
||||
@@ -127,23 +84,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
|
||||
|
||||
@@ -163,6 +106,11 @@ https://eclipse.org[Eclipse] when working with the code. We use the
|
||||
https://eclipse.org/m2e/[m2eclipse] eclipse plugin for maven support. Other IDEs and tools
|
||||
should also work without issue as long as they use Maven 3.3.3 or better.
|
||||
|
||||
==== Activate the Spring Maven profile
|
||||
Spring Cloud projects require the 'spring' Maven profile to be activated to resolve
|
||||
the spring milestone and snapshot repositories. Use your preferred IDE to set this
|
||||
profile to be active, or you may experience build errors.
|
||||
|
||||
==== Importing into eclipse with m2eclipse
|
||||
We recommend the https://eclipse.org/m2e/[m2eclipse] eclipse plugin when working with
|
||||
eclipse. If you don't already have m2eclipse installed it is available from the "eclipse
|
||||
@@ -374,4 +322,59 @@ Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on t
|
||||
- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL.
|
||||
- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`.
|
||||
|
||||
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
|
||||
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].
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
To report security vulnerabilities, please go to https://pivotal.io/security.
|
||||
@@ -1,383 +0,0 @@
|
||||
////
|
||||
DO NOT EDIT THIS FILE. IT WAS GENERATED.
|
||||
Manual changes to this file will be lost when it is generated again.
|
||||
Edit the files in the src/main/asciidoc/ directory instead.
|
||||
////
|
||||
|
||||
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
:sectnums:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:docinfo: shared,private
|
||||
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Netflix
|
||||
|
||||
image::https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/master.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/master"]
|
||||
image::https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/master/graph/badge.svg["Codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/master"]
|
||||
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
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
:sectnums:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:docinfo: shared,private
|
||||
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Netflix
|
||||
|
||||
This project provides Netflix OSS integrations for Spring Boot apps through autoconfiguration
|
||||
and binding to the Spring Environment and other Spring programming model idioms. With a few
|
||||
simple annotations you can quickly enable and configure the common patterns inside your
|
||||
application and build large distributed systems with battle-tested Netflix components. The
|
||||
patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix),
|
||||
Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon).
|
||||
|
||||
|
||||
== Features
|
||||
|
||||
* Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
|
||||
* Service Discovery: an embedded Eureka server can be created with declarative Java configuration
|
||||
* Circuit Breaker: Hystrix clients can be built with a simple annotation-driven method decorator
|
||||
* Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration
|
||||
* Client Side Load Balancer: Ribbon
|
||||
* External Configuration: a bridge from the Spring Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions)
|
||||
* Router and Filter: automatic registration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation
|
||||
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
:sectnums:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:docinfo: shared,private
|
||||
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Netflix
|
||||
|
||||
== Modules In Maintenance Mode
|
||||
|
||||
Placing a module in maintenance mode means that the Spring Cloud team will no longer be adding new features to the module.
|
||||
We will fix blocker bugs and security issues, and we will also consider and review small pull requests from the community.
|
||||
|
||||
We intend to continue to support these modules for a period of at least a year from the general availability
|
||||
of the Greenwich release train.
|
||||
|
||||
The following Spring Cloud Netflix modules and corresponding starters will be placed into maintenance mode:
|
||||
|
||||
* spring-cloud-netflix-archaius
|
||||
* spring-cloud-netflix-concurrency-limits
|
||||
* spring-cloud-netflix-hystrix-contract
|
||||
* spring-cloud-netflix-hystrix-dashboard
|
||||
* spring-cloud-netflix-hystrix-stream
|
||||
* spring-cloud-netflix-hystrix
|
||||
* spring-cloud-netflix-ribbon
|
||||
* spring-cloud-netflix-turbine-stream
|
||||
* spring-cloud-netflix-turbine
|
||||
* spring-cloud-netflix-zuul
|
||||
|
||||
NOTE: This does not include the Eureka modules.
|
||||
|
||||
|
||||
== Building
|
||||
|
||||
:jdkversion: 1.8
|
||||
|
||||
=== Basic Compile and Test
|
||||
|
||||
To build the source you will need to install JDK {jdkversion}.
|
||||
|
||||
Spring Cloud uses Maven for most build-related activities, and you
|
||||
should be able to get off the ground quite quickly by cloning the
|
||||
project you are interested in and typing
|
||||
|
||||
----
|
||||
$ ./mvnw install
|
||||
----
|
||||
|
||||
NOTE: You can also install Maven (>=3.3.3) yourself and run the `mvn` command
|
||||
in place of `./mvnw` in the examples below. If you do that you also
|
||||
might need to add `-P spring` if your local Maven settings do not
|
||||
contain repository declarations for spring pre-release artifacts.
|
||||
|
||||
NOTE: Be aware that you might need to increase the amount of memory
|
||||
available to Maven by setting a `MAVEN_OPTS` environment variable with
|
||||
a value like `-Xmx512m -XX:MaxPermSize=128m`. We try to cover this in
|
||||
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 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
|
||||
|
||||
The spring-cloud-build module has a "docs" profile, and if you switch
|
||||
that on it will try to build asciidoc sources from
|
||||
`src/main/asciidoc`. As part of that process it will look for a
|
||||
`README.adoc` and process it by loading all the includes, but not
|
||||
parsing or rendering it, just copying it to `${main.basedir}`
|
||||
(defaults to `${basedir}`, i.e. the root of the project). If there are
|
||||
any changes in the README it will then show up after a Maven build as
|
||||
a modified file in the correct place. Just commit it and push the change.
|
||||
|
||||
=== Working with the code
|
||||
If you don't have an IDE preference we would recommend that you use
|
||||
https://www.springsource.com/developer/sts[Spring Tools Suite] or
|
||||
https://eclipse.org[Eclipse] when working with the code. We use the
|
||||
https://eclipse.org/m2e/[m2eclipse] eclipse plugin for maven support. Other IDEs and tools
|
||||
should also work without issue as long as they use Maven 3.3.3 or better.
|
||||
|
||||
==== Activate the Spring Maven profile
|
||||
Spring Cloud projects require the 'spring' Maven profile to be activated to resolve
|
||||
the spring milestone and snapshot repositories. Use your preferred IDE to set this
|
||||
profile to be active, or you may experience build errors.
|
||||
|
||||
==== Importing into eclipse with m2eclipse
|
||||
We recommend the https://eclipse.org/m2e/[m2eclipse] eclipse plugin when working with
|
||||
eclipse. If you don't already have m2eclipse installed it is available from the "eclipse
|
||||
marketplace".
|
||||
|
||||
NOTE: Older versions of m2e do not support Maven 3.3, so once the
|
||||
projects are imported into Eclipse you will also need to tell
|
||||
m2eclipse to use the right profile for the projects. If you
|
||||
see many different errors related to the POMs in the projects, check
|
||||
that you have an up to date installation. If you can't upgrade m2e,
|
||||
add the "spring" profile to your `settings.xml`. Alternatively you can
|
||||
copy the repository settings from the "spring" profile of the parent
|
||||
pom into your `settings.xml`.
|
||||
|
||||
==== Importing into eclipse without m2eclipse
|
||||
If you prefer not to use m2eclipse you can generate eclipse project metadata using the
|
||||
following command:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
$ ./mvnw eclipse:eclipse
|
||||
----
|
||||
|
||||
The generated eclipse projects can be imported by selecting `import existing projects`
|
||||
from the `file` menu.
|
||||
|
||||
|
||||
|
||||
NOTE: To build the module `spring-cloud-netflix-hystrix-contract` along with the entire Netflix project run the
|
||||
`build.sh` script in the `scripts` directory.
|
||||
|
||||
== Contributing
|
||||
|
||||
:spring-cloud-build-branch: master
|
||||
|
||||
Spring Cloud is released under the non-restrictive Apache 2.0 license,
|
||||
and follows a very standard Github development process, using Github
|
||||
tracker for issues and merging pull requests into master. If you want
|
||||
to contribute even something trivial please do not hesitate, but
|
||||
follow the guidelines below.
|
||||
|
||||
=== Sign the Contributor License Agreement
|
||||
Before we accept a non-trivial patch or pull request we will need you to sign the
|
||||
https://cla.pivotal.io/sign/spring[Contributor License Agreement].
|
||||
Signing the contributor's agreement does not grant anyone commit rights to the main
|
||||
repository, but it does mean that we can accept your contributions, and you will get an
|
||||
author credit if we do. Active contributors might be asked to join the core team, and
|
||||
given the ability to merge pull requests.
|
||||
|
||||
=== Code of Conduct
|
||||
This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of
|
||||
conduct]. By participating, you are expected to uphold this code. Please report
|
||||
unacceptable behavior to spring-code-of-conduct@pivotal.io.
|
||||
|
||||
=== Code Conventions and Housekeeping
|
||||
None of these is essential for a pull request, but they will all help. They can also be
|
||||
added after the original pull request but before a merge.
|
||||
|
||||
* Use the Spring Framework code format conventions. If you use Eclipse
|
||||
you can import formatter settings using the
|
||||
`eclipse-code-formatter.xml` file from the
|
||||
https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring
|
||||
Cloud Build] project. If using IntelliJ, you can use the
|
||||
https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter
|
||||
Plugin] to import the same file.
|
||||
* Make sure all new `.java` files to have a simple Javadoc class comment with at least an
|
||||
`@author` tag identifying you, and preferably at least a paragraph on what the class is
|
||||
for.
|
||||
* Add the ASF license header comment to all new `.java` files (copy from existing files
|
||||
in the project)
|
||||
* Add yourself as an `@author` to the .java files that you modify substantially (more
|
||||
than cosmetic changes).
|
||||
* Add some Javadocs and, if you change the namespace, some XSD doc elements.
|
||||
* A few unit tests would help a lot as well -- someone has to do it.
|
||||
* If no-one else is using your branch, please rebase it against the current master (or
|
||||
other target branch in the main project).
|
||||
* When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions],
|
||||
if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
|
||||
message (where XXXX is the issue number).
|
||||
|
||||
=== Checkstyle
|
||||
|
||||
Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are:
|
||||
|
||||
.spring-cloud-build-tools/
|
||||
----
|
||||
└── src
|
||||
├── checkstyle
|
||||
│ └── checkstyle-suppressions.xml <3>
|
||||
└── main
|
||||
└── resources
|
||||
├── checkstyle-header.txt <2>
|
||||
└── checkstyle.xml <1>
|
||||
----
|
||||
<1> Default Checkstyle rules
|
||||
<2> File header setup
|
||||
<3> Default suppression rules
|
||||
|
||||
==== Checkstyle configuration
|
||||
|
||||
Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins.
|
||||
|
||||
.pom.xml
|
||||
----
|
||||
<properties>
|
||||
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError> <1>
|
||||
<maven-checkstyle-plugin.failsOnViolation>true
|
||||
</maven-checkstyle-plugin.failsOnViolation> <2>
|
||||
<maven-checkstyle-plugin.includeTestSourceDirectory>true
|
||||
</maven-checkstyle-plugin.includeTestSourceDirectory> <3>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin> <4>
|
||||
<groupId>io.spring.javaformat</groupId>
|
||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin> <5>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin> <5>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</build>
|
||||
----
|
||||
<1> Fails the build upon Checkstyle errors
|
||||
<2> Fails the build upon Checkstyle violations
|
||||
<3> Checkstyle analyzes also the test sources
|
||||
<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules
|
||||
<5> Add checkstyle plugin to your build and reporting phases
|
||||
|
||||
If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example:
|
||||
|
||||
.projectRoot/src/checkstyle/checkstyle-suppresions.xml
|
||||
----
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE suppressions PUBLIC
|
||||
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||
"https://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||
<suppressions>
|
||||
<suppress files=".*ConfigServerApplication\.java" checks="HideUtilityClassConstructor"/>
|
||||
<suppress files=".*ConfigClientWatch\.java" checks="LineLengthCheck"/>
|
||||
</suppressions>
|
||||
----
|
||||
|
||||
It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script:
|
||||
|
||||
```bash
|
||||
$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
|
||||
$ touch .springformat
|
||||
```
|
||||
|
||||
=== IDE setup
|
||||
|
||||
==== Intellij IDEA
|
||||
|
||||
In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.
|
||||
The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project.
|
||||
|
||||
.spring-cloud-build-tools/
|
||||
----
|
||||
└── src
|
||||
├── checkstyle
|
||||
│ └── checkstyle-suppressions.xml <3>
|
||||
└── main
|
||||
└── resources
|
||||
├── checkstyle-header.txt <2>
|
||||
├── checkstyle.xml <1>
|
||||
└── intellij
|
||||
├── Intellij_Project_Defaults.xml <4>
|
||||
└── Intellij_Spring_Boot_Java_Conventions.xml <5>
|
||||
----
|
||||
<1> Default Checkstyle rules
|
||||
<2> File header setup
|
||||
<3> Default suppression rules
|
||||
<4> Project defaults for Intellij that apply most of Checkstyle rules
|
||||
<5> Project style conventions for Intellij that apply most of Checkstyle rules
|
||||
|
||||
.Code style
|
||||
|
||||
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style]
|
||||
|
||||
Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file.
|
||||
|
||||
.Inspection profiles
|
||||
|
||||
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style]
|
||||
|
||||
Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file.
|
||||
|
||||
.Checkstyle
|
||||
|
||||
To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions
|
||||
|
||||
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle]
|
||||
|
||||
Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables:
|
||||
|
||||
- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL.
|
||||
- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL.
|
||||
- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`.
|
||||
|
||||
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
|
||||
+2
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix</artifactId>
|
||||
<version>3.0.0-RC1</version>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-netflix-docs</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -13,6 +13,7 @@
|
||||
<description>Spring Cloud Docs</description>
|
||||
<properties>
|
||||
<docs.main>spring-cloud-netflix</docs.main>
|
||||
<main.basedir>${basedir}/..</main.basedir>
|
||||
<configprops.inclusionPattern>
|
||||
.*.eureka.*
|
||||
</configprops.inclusionPattern>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
include::_attributes.adoc[]
|
||||
|
||||
image::https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/master.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-netflix/tree/master"]
|
||||
image::https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/master/graph/badge.svg["Codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/master"]
|
||||
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"]
|
||||
|
||||
|
||||
@@ -11,21 +11,19 @@ include::intro.adoc[]
|
||||
|
||||
* Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
|
||||
* Service Discovery: an embedded Eureka server can be created with declarative Java configuration
|
||||
* Circuit Breaker: Hystrix clients can be built with a simple annotation-driven method decorator
|
||||
* Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration
|
||||
* Client Side Load Balancer: Ribbon
|
||||
* External Configuration: a bridge from the Spring Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions)
|
||||
* Router and Filter: automatic registration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation
|
||||
|
||||
include::maintenance-mode.adoc[]
|
||||
|
||||
== Building
|
||||
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/building-jdk8.adoc[]
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/src/main/asciidoc/building-jdk8.adoc[]
|
||||
|
||||
NOTE: To build the module `spring-cloud-netflix-hystrix-contract` along with the entire Netflix project run the
|
||||
`build.sh` script in the `scripts` directory.
|
||||
|
||||
== Contributing
|
||||
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/contributing.adoc[]
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/src/main/asciidoc/contributing.adoc[]
|
||||
|
||||
== License
|
||||
|
||||
The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/main/LICENSE.txt[here].
|
||||
@@ -39,7 +39,7 @@ function check_if_anything_to_sync() {
|
||||
}
|
||||
|
||||
function retrieve_current_branch() {
|
||||
# Code getting the name of the current branch. For master we want to publish as we did until now
|
||||
# Code getting the name of the current branch. For main we want to publish as we did until now
|
||||
# https://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch
|
||||
# If there is a branch already passed will reuse it - otherwise will try to find it
|
||||
CURRENT_BRANCH=${BRANCH}
|
||||
@@ -134,8 +134,8 @@ function add_docs_from_target() {
|
||||
|
||||
# Copies the docs by using the retrieved properties from Maven build
|
||||
function copy_docs_for_current_version() {
|
||||
if [[ "${CURRENT_BRANCH}" == "master" ]] ; then
|
||||
echo -e "Current branch is master - will copy the current docs only to the root folder"
|
||||
if [[ "${CURRENT_BRANCH}" == "main" ]] ; then
|
||||
echo -e "Current branch is main - will copy the current docs only to the root folder"
|
||||
for f in docs/target/generated-docs/*; do
|
||||
file=${f#docs/target/generated-docs/*}
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then
|
||||
@@ -216,7 +216,7 @@ function commit_changes_if_applicable() {
|
||||
git commit -a -m "Sync docs from ${CURRENT_BRANCH} to gh-pages" && COMMIT_SUCCESSFUL="yes" || echo "Failed to commit changes"
|
||||
|
||||
# Uncomment the following push if you want to auto push to
|
||||
# the gh-pages branch whenever you commit to master locally.
|
||||
# the gh-pages branch whenever you commit to main locally.
|
||||
# This is a little extreme. Use with care!
|
||||
###################################################################
|
||||
if [[ "${COMMIT_SUCCESSFUL}" == "yes" ]] ; then
|
||||
@@ -249,7 +249,7 @@ The idea of this script is to update gh-pages branch with the generated docs. Wi
|
||||
the script will work in the following manner:
|
||||
|
||||
- if there's no gh-pages / target for docs module then the script ends
|
||||
- for master branch the generated docs are copied to the root of gh-pages branch
|
||||
- for main branch the generated docs are copied to the root of gh-pages branch
|
||||
- for any other branch (if that branch is allowed) a subfolder with branch name is created
|
||||
and docs are copied there
|
||||
- if the version switch is passed (-v) then a tag with (v) prefix will be retrieved and a folder
|
||||
|
||||
@@ -4,6 +4,5 @@ This project provides Netflix OSS integrations for Spring Boot apps through auto
|
||||
and binding to the Spring Environment and other Spring programming model idioms. With a few
|
||||
simple annotations you can quickly enable and configure the common patterns inside your
|
||||
application and build large distributed systems with battle-tested Netflix components. The
|
||||
patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix),
|
||||
Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon).
|
||||
patterns provided include Service Discovery (Eureka).
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
include::_attributes.adoc[]
|
||||
|
||||
== Modules In Maintenance Mode
|
||||
|
||||
Placing a module in maintenance mode means that the Spring Cloud team will no longer be adding new features to the module.
|
||||
We will fix blocker bugs and security issues, and we will also consider and review small pull requests from the community.
|
||||
|
||||
We intend to continue to support these modules for a period of at least a year from the general availability
|
||||
of the Greenwich release train.
|
||||
|
||||
The following Spring Cloud Netflix modules and corresponding starters will be placed into maintenance mode:
|
||||
|
||||
* spring-cloud-netflix-archaius
|
||||
* spring-cloud-netflix-concurrency-limits
|
||||
* spring-cloud-netflix-hystrix-contract
|
||||
* spring-cloud-netflix-hystrix-dashboard
|
||||
* spring-cloud-netflix-hystrix-stream
|
||||
* spring-cloud-netflix-hystrix
|
||||
* spring-cloud-netflix-ribbon
|
||||
* spring-cloud-netflix-turbine-stream
|
||||
* spring-cloud-netflix-turbine
|
||||
* spring-cloud-netflix-zuul
|
||||
|
||||
NOTE: This does not include the Eureka modules.
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
include::_attributes.adoc[]
|
||||
@@ -1,4 +1,4 @@
|
||||
Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon)..
|
||||
Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka).
|
||||
|
||||
## Features
|
||||
|
||||
@@ -6,23 +6,16 @@ Spring Cloud Netflix features:
|
||||
|
||||
* Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
|
||||
* Service Discovery: an embedded Eureka server can be created with declarative Java configuration
|
||||
* Circuit Breaker: Hystrix clients can be built with a simple annotation-driven method decorator
|
||||
* Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration
|
||||
* Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations
|
||||
* Client Side Load Balancer: Ribbon
|
||||
* External Configuration: a bridge from the Spring Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions)
|
||||
* Router and Filter: automatic registration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation
|
||||
|
||||
## 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 {
|
||||
|
||||
@@ -39,3 +32,17 @@ public class Application {
|
||||
```
|
||||
|
||||
To run your own server use the `spring-cloud-starter-netflix-eureka-server` dependency and `@EnableEurekaServer`.
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome contributions. You can read more on how to contribute to the project https://github.com/spring-cloud/spring-cloud-netflix#contributing[here].
|
||||
|
||||
## Community Support
|
||||
|
||||
* You can report issues through https://github.com/spring-cloud/spring-cloud-netflix/issues[Github].
|
||||
* We monitor https://stackoverflow.com/[StackOverflow] for questions with the `spring-cloud-netflix` tag.
|
||||
* You can contact our team at https://gitter.im/spring-cloud/spring-cloud[Gitter].
|
||||
|
||||
## Commercial Support
|
||||
|
||||
Commercial Support is provided as part of the https://spring.io/support[VMware Spring Runtime] offering.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
include::_attributes.adoc[]
|
||||
|
||||
|
||||
:github-tag: master
|
||||
:github-tag: main
|
||||
:github-repo: spring-cloud/spring-cloud-netflix
|
||||
:github-raw: https://raw.github.com/{github-repo}/{github-tag}
|
||||
:github-code: https://github.com/{github-repo}/tree/{github-tag}
|
||||
:all: {asterisk}{asterisk}
|
||||
:nofooter:
|
||||
:branch: master
|
||||
:branch: main
|
||||
|
||||
= Spring Cloud Netflix
|
||||
|
||||
@@ -107,6 +107,8 @@ The `eureka.client.tls.enabled` needs to be true to enable Eureka client side TL
|
||||
|
||||
NOTE: Because of a limitation in Eureka, it is not possible to support per-server basic auth credentials, so only the first set that are found is used.
|
||||
|
||||
If you want to customize the RestTemplate used by the Eureka HTTP Client you may want to create a bean of `EurekaClientHttpRequestFactorySupplier` and provide your own logic for generating a `ClientHttpRequestFactory` instance.
|
||||
|
||||
=== Status Page and Health Indicator
|
||||
|
||||
The status page and health indicators for a Eureka instance default to `/info` and `/health` respectively, which are the default locations of useful endpoints in a Spring Boot Actuator application.
|
||||
@@ -226,7 +228,7 @@ public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
|
||||
A vanilla Netflix Eureka instance is registered with an ID that is equal to its host name (that is, there is only one service per host).
|
||||
Spring Cloud Eureka provides a sensible default, which is defined as follows:
|
||||
|
||||
`${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}}`
|
||||
`${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}`
|
||||
|
||||
An example is `myhost:myappname:8080`.
|
||||
|
||||
@@ -264,31 +266,24 @@ 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 Jersey for HTTP communication.
|
||||
If you wish to avoid dependencies from Jersey, you can exclude it from your dependencies.
|
||||
Spring Cloud auto-configures a transport client based on Spring `RestTemplate`.
|
||||
The following example shows Jersey being excluded:
|
||||
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.
|
||||
The following example shows the dependencies you need to add:
|
||||
|
||||
----
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
<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>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-apache-client4</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
@@ -297,7 +292,6 @@ The following example shows Jersey being excluded:
|
||||
You need not use the raw Netflix `EurekaClient`.
|
||||
Also, it is usually more convenient to use it behind a wrapper of some sort.
|
||||
Spring Cloud has support for <<spring-cloud-feign, Feign>> (a REST client builder) and <<spring-cloud-ribbon, Spring `RestTemplate`>> through the logical Eureka service identifiers (VIPs) instead of physical URLs.
|
||||
To configure Ribbon with a fixed list of physical servers, you can set `<client>.ribbon.listOfServers` to a comma-separated list of physical addresses (or hostnames), where `<client>` is the ID of the client.
|
||||
|
||||
You can also use the `org.springframework.cloud.client.discovery.DiscoveryClient`, which provides a simple API (not specific to Netflix) for discovery clients, as shown in the following example:
|
||||
|
||||
@@ -361,7 +355,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.
|
||||
@@ -445,8 +439,6 @@ Clients also have an in-memory cache of Eureka registrations (so they do not hav
|
||||
By default, every Eureka server is also a Eureka client and requires (at least one) service URL to locate a peer.
|
||||
If you do not provide it, the service runs and works, but it fills your logs with a lot of noise about not being able to register with the peer.
|
||||
|
||||
See also <<spring-cloud-ribbon,below for details of Ribbon support>> on the client side for Zones and Regions.
|
||||
|
||||
[[spring-cloud-eureka-server-standalone-mode]]
|
||||
=== Standalone Mode
|
||||
|
||||
|
||||
@@ -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.0-RC1</version>
|
||||
<version>3.0.6</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.0-RC1</version>
|
||||
<version>3.0.5</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
<scm>
|
||||
@@ -21,8 +21,8 @@
|
||||
</scm>
|
||||
<properties>
|
||||
<bintray.package>netflix</bintray.package>
|
||||
<spring-cloud-commons.version>3.0.0-RC1</spring-cloud-commons.version>
|
||||
<spring-cloud-config.version>3.0.0-RC1</spring-cloud-config.version>
|
||||
<spring-cloud-commons.version>3.0.6</spring-cloud-commons.version>
|
||||
<spring-cloud-config.version>3.0.7</spring-cloud-config.version>
|
||||
|
||||
<!-- Sonar -->
|
||||
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
|
||||
@@ -30,7 +30,6 @@
|
||||
<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>
|
||||
<xstream.version>1.4.14</xstream.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -134,11 +133,6 @@
|
||||
<artifactId>jersey-apache-client4</artifactId>
|
||||
<version>${eureka-jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>${xstream.version}</version>
|
||||
</dependency>
|
||||
<!-- end eureka deps -->
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
@@ -4,7 +4,7 @@ set -o errexit
|
||||
|
||||
mkdir -p target
|
||||
|
||||
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/master/runAcceptanceTests.sh"
|
||||
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/2020.0.x/runAcceptanceTests.sh"
|
||||
AT_WHAT_TO_TEST="EUREKA"
|
||||
|
||||
cd target
|
||||
@@ -18,7 +18,7 @@ echo "Killing all running apps"
|
||||
|
||||
./runAcceptanceTests.sh -t "${AT_WHAT_TO_TEST}" --killattheend
|
||||
|
||||
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/tests/master/scripts/runTests.sh"
|
||||
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/tests/main/scripts/runTests.sh"
|
||||
|
||||
curl "${SCRIPT_URL}" --output runIntegrationTests.sh
|
||||
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
<parent>
|
||||
<artifactId>spring-cloud-dependencies-parent</artifactId>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<version>3.0.0-RC1</version>
|
||||
<version>3.0.5</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-netflix-dependencies</artifactId>
|
||||
<version>3.0.0-RC1</version>
|
||||
<version>3.0.6</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>spring-cloud-netflix-dependencies</name>
|
||||
<description>Spring Cloud Netflix Dependencies</description>
|
||||
<properties>
|
||||
<eureka.version>1.10.10</eureka.version>
|
||||
<eureka.version>1.10.17</eureka.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -112,6 +112,7 @@
|
||||
</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.0-RC1</version>
|
||||
<version>3.0.6</version>
|
||||
<relativePath>..</relativePath> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<artifactId>spring-cloud-netflix-eureka-client-tls-tests</artifactId>
|
||||
@@ -90,14 +90,25 @@
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>1.67</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>2.1</version>
|
||||
<version>1.68</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Suite.java</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/*Test.java</exclude>
|
||||
<exclude>**/*Tests.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
+11
@@ -46,6 +46,7 @@ public class AppRunner implements AutoCloseable {
|
||||
public void start() {
|
||||
if (app == null) {
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder(appClass);
|
||||
builder.properties("spring.application.name=" + appClass.getName());
|
||||
builder.properties("spring.jmx.enabled=false");
|
||||
builder.properties(String.format("server.port=%d", availabeTcpPort()));
|
||||
builder.properties(props());
|
||||
@@ -72,6 +73,16 @@ public class AppRunner implements AutoCloseable {
|
||||
public void stop() {
|
||||
if (app != null) {
|
||||
app.stop();
|
||||
int attempts = 5;
|
||||
while (app.isRunning() && attempts > 0) {
|
||||
attempts = attempts - 1;
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
app = null;
|
||||
}
|
||||
}
|
||||
|
||||
+119
-4
@@ -20,10 +20,22 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public abstract class BaseCertTest {
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
abstract class BaseCertTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(BaseCertTest.class);
|
||||
|
||||
protected static final String KEY_STORE_PASSWORD = "test-key-store-password";
|
||||
|
||||
@@ -44,8 +56,47 @@ public abstract class BaseCertTest {
|
||||
protected BaseCertTest() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void createCertificates() throws Exception {
|
||||
static EurekaServerRunner startEurekaServer(Class config) {
|
||||
EurekaServerRunner server = new EurekaServerRunner(config);
|
||||
server.enableTls();
|
||||
server.setKeyStore(serverCert, KEY_STORE_PASSWORD, "server", KEY_PASSWORD);
|
||||
server.setTrustStore(caCert, KEY_STORE_PASSWORD);
|
||||
|
||||
server.start();
|
||||
return server;
|
||||
}
|
||||
|
||||
static void stopEurekaServer(EurekaServerRunner server) {
|
||||
server.stop();
|
||||
}
|
||||
|
||||
static EurekaClientRunner startService(EurekaServerRunner server, Class config) {
|
||||
EurekaClientRunner service = new EurekaClientRunner(config, server, "testservice");
|
||||
enableTlsClient(service);
|
||||
service.start();
|
||||
return service;
|
||||
}
|
||||
|
||||
static void stopService(EurekaClientRunner service) {
|
||||
service.stop();
|
||||
}
|
||||
|
||||
static void enableTlsClient(EurekaClientRunner runner) {
|
||||
runner.enableTls();
|
||||
runner.setKeyStore(clientCert, KEY_STORE_PASSWORD, KEY_PASSWORD);
|
||||
runner.setTrustStore(caCert, KEY_STORE_PASSWORD);
|
||||
}
|
||||
|
||||
static void waitForRegistration(Supplier<EurekaClientRunner> clientSupplier) {
|
||||
try (EurekaClientRunner client = clientSupplier.get()) {
|
||||
enableTlsClient(client);
|
||||
client.start();
|
||||
client.waitServiceViaEureka(60);
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
static void createCertificates() throws Exception {
|
||||
KeyTool tool = new KeyTool();
|
||||
|
||||
KeyAndCert ca = tool.createCA("MyCA");
|
||||
@@ -63,6 +114,70 @@ public abstract class BaseCertTest {
|
||||
wrongClientCert = saveKeyAndCert(wrongClient);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void afterClass() {
|
||||
log.info("Tests finished!");
|
||||
}
|
||||
|
||||
abstract EurekaClientRunner createEurekaClient();
|
||||
|
||||
/**
|
||||
* Already proved this in waitForRegistration(). Keep this Test to express test
|
||||
* purpose explicitly.
|
||||
*/
|
||||
@Test
|
||||
void clientCertCanWork() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void noCertCannotWork() {
|
||||
try (EurekaClientRunner client = createEurekaClient()) {
|
||||
client.disableTls();
|
||||
client.start();
|
||||
assertThat(client.foundServiceViaEureka()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongCertCannotWork() {
|
||||
try (EurekaClientRunner client = createEurekaClient()) {
|
||||
enableTlsClient(client);
|
||||
client.setKeyStore(wrongClientCert);
|
||||
client.start();
|
||||
assertThat(client.foundServiceViaEureka()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongPasswordCauseFailure() {
|
||||
EurekaClientRunner client = createEurekaClient();
|
||||
enableTlsClient(client);
|
||||
client.setKeyStore(clientCert, WRONG_PASSWORD, WRONG_PASSWORD);
|
||||
Assertions.assertThrows(BeanCreationException.class, () -> {
|
||||
client.start();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
client.start();
|
||||
assertThat(client.foundServiceViaEureka()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
private static File saveKeyAndCert(KeyAndCert keyCert) throws Exception {
|
||||
return saveKeyStore(keyCert.subject(), () -> keyCert.storeKeyAndCert(KEY_PASSWORD));
|
||||
}
|
||||
|
||||
+6
@@ -19,6 +19,8 @@ package org.springframework.cloud.netflix.eureka;
|
||||
import java.io.File;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
|
||||
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
|
||||
public class EurekaClientRunner extends AppRunner {
|
||||
@@ -96,4 +98,8 @@ public class EurekaClientRunner extends AppRunner {
|
||||
return !discovery.getServices().isEmpty();
|
||||
}
|
||||
|
||||
public AbstractDiscoveryClientOptionalArgs<Void> discoveryClientOptionalArgs() {
|
||||
return this.getBean(AbstractDiscoveryClientOptionalArgs.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2018-2019 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;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
/**
|
||||
* We need to use a suite cause we need to first run all the Eureka Servers, then close
|
||||
* all of them. We can't run one EurekaServer, close it and then run another one, cause
|
||||
* Eureka is using static executor services that are shutdown when we close a context.
|
||||
* That means that when the new context starts we will fail cause the executor service is
|
||||
* already shutdown.
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({ EurekaClientTest.class, RestTemplateEurekaClientTest.class })
|
||||
public class EurekaClientSuite {
|
||||
|
||||
}
|
||||
+18
-109
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.netflix.eureka;
|
||||
|
||||
import java.io.File;
|
||||
import com.netflix.discovery.DiscoveryClient;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
||||
@@ -31,117 +29,28 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EurekaClientTest extends BaseCertTest {
|
||||
|
||||
private static EurekaServerRunner server;
|
||||
private static final Log log = LogFactory.getLog(EurekaClientTest.class);
|
||||
|
||||
private static EurekaClientRunner service;
|
||||
static EurekaServerRunner server;
|
||||
|
||||
@BeforeClass
|
||||
static EurekaClientRunner service;
|
||||
|
||||
@BeforeAll
|
||||
public static void setupAll() {
|
||||
startEurekaServer();
|
||||
startService();
|
||||
waitForRegistration();
|
||||
server = startEurekaServer(EurekaClientTest.TestEurekaServer.class);
|
||||
service = startService(server, EurekaClientTest.TestApp.class);
|
||||
// Will use Jersey
|
||||
assertThat(service.discoveryClientOptionalArgs())
|
||||
.isInstanceOf(DiscoveryClient.DiscoveryClientOptionalArgs.class);
|
||||
log.info("Successfully asserted that Jersey will be used");
|
||||
waitForRegistration(() -> new EurekaClientTest().createEurekaClient());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAll() {
|
||||
stopService();
|
||||
stopEurekaServer();
|
||||
}
|
||||
|
||||
private static void startEurekaServer() {
|
||||
server = new EurekaServerRunner(TestEurekaServer.class);
|
||||
server.enableTls();
|
||||
server.setKeyStore(serverCert, KEY_STORE_PASSWORD, "server", KEY_PASSWORD);
|
||||
server.setTrustStore(caCert, KEY_STORE_PASSWORD);
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
private static void stopEurekaServer() {
|
||||
server.stop();
|
||||
}
|
||||
|
||||
private static void startService() {
|
||||
service = new EurekaClientRunner(TestApp.class, server, "testservice");
|
||||
enableTlsClient(service);
|
||||
service.start();
|
||||
}
|
||||
|
||||
private static void stopService() {
|
||||
service.stop();
|
||||
}
|
||||
|
||||
private static void waitForRegistration() {
|
||||
try (EurekaClientRunner client = createEurekaClient()) {
|
||||
enableTlsClient(client);
|
||||
client.start();
|
||||
client.waitServiceViaEureka(60);
|
||||
}
|
||||
}
|
||||
|
||||
private static EurekaClientRunner createEurekaClient() {
|
||||
@Override
|
||||
EurekaClientRunner createEurekaClient() {
|
||||
return new EurekaClientRunner(TestApp.class, server);
|
||||
}
|
||||
|
||||
private static void enableTlsClient(EurekaClientRunner runner) {
|
||||
runner.enableTls();
|
||||
runner.setKeyStore(clientCert, KEY_STORE_PASSWORD, KEY_PASSWORD);
|
||||
runner.setTrustStore(caCert, KEY_STORE_PASSWORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Already proved this in waitForRegistration(). Keep this Test to express test
|
||||
* purpose explicitly.
|
||||
*/
|
||||
@Test
|
||||
public void clientCertCanWork() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noCertCannotWork() {
|
||||
try (EurekaClientRunner client = createEurekaClient()) {
|
||||
client.disableTls();
|
||||
client.start();
|
||||
assertThat(client.foundServiceViaEureka()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongCertCannotWork() {
|
||||
try (EurekaClientRunner client = createEurekaClient()) {
|
||||
enableTlsClient(client);
|
||||
client.setKeyStore(wrongClientCert);
|
||||
client.start();
|
||||
assertThat(client.foundServiceViaEureka()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public 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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongTrustStoreCannotWork() {
|
||||
try (EurekaClientRunner client = createEurekaClient()) {
|
||||
enableTlsClient(client);
|
||||
client.setTrustStore(wrongCaCert);
|
||||
client.start();
|
||||
assertThat(client.foundServiceViaEureka()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
public static class TestApp {
|
||||
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2018-2019 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.configuration.TlsProperties;
|
||||
import org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration;
|
||||
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
|
||||
import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs;
|
||||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class RestTemplateEurekaClientTest extends BaseCertTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(RestTemplateEurekaClientTest.class);
|
||||
|
||||
private static EurekaServerRunner server;
|
||||
|
||||
private static EurekaClientRunner service;
|
||||
|
||||
@BeforeAll
|
||||
public static void setupAll() {
|
||||
server = startEurekaServer(RestTemplateEurekaClientTest.RestTemplateTestEurekaServer.class);
|
||||
service = startService(server, RestTemplateEurekaClientTest.RestTemplateTestApp.class);
|
||||
// Will use RestTemplate
|
||||
assertThat(service.discoveryClientOptionalArgs()).isInstanceOf(RestTemplateDiscoveryClientOptionalArgs.class);
|
||||
log.info("Successfully asserted that RestTemplate will be used");
|
||||
waitForRegistration(() -> new RestTemplateEurekaClientTest().createEurekaClient());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void tearDownAll() {
|
||||
stopService(service);
|
||||
stopEurekaServer(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
EurekaClientRunner createEurekaClient() {
|
||||
return new EurekaClientRunner(RestTemplateTestApp.class, server);
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
public static class RestTemplateTestApp {
|
||||
|
||||
// Want to force reusing exactly the same bean as on production without excluding
|
||||
// jersey from the classpath
|
||||
@Bean
|
||||
public RestTemplateDiscoveryClientOptionalArgs forceRestTemplateDiscoveryClientOptionalArgs(
|
||||
TlsProperties tlsProperties, DiscoveryClientOptionalArgsConfiguration configuration,
|
||||
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier)
|
||||
throws GeneralSecurityException, IOException {
|
||||
return configuration.restTemplateDiscoveryClientOptionalArgs(tlsProperties,
|
||||
eurekaClientHttpRequestFactorySupplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
@EnableEurekaServer
|
||||
public static class RestTemplateTestEurekaServer {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix</artifactId>
|
||||
<version>3.0.0-RC1</version>
|
||||
<version>3.0.6</version>
|
||||
<relativePath>..</relativePath> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
|
||||
@@ -95,16 +95,6 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- Eureka core deps that are now optional -->
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>com.netflix.netflix-commons</groupId>
|
||||
<artifactId>netflix-eventbus</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
|
||||
+5
@@ -133,7 +133,12 @@ public class EurekaClientAutoConfiguration {
|
||||
int serverPort = Integer.parseInt(env.getProperty("server.port", env.getProperty("port", "8080")));
|
||||
|
||||
Integer managementPort = env.getProperty("management.server.port", Integer.class);
|
||||
|
||||
String managementContextPath = env.getProperty("management.server.servlet.context-path");
|
||||
if (!StringUtils.hasText(managementContextPath)) {
|
||||
managementContextPath = env.getProperty("management.server.base-path");
|
||||
}
|
||||
|
||||
Integer jmxPort = env.getProperty("com.sun.management.jmxremote.port", Integer.class);
|
||||
EurekaInstanceConfigBean instance = new EurekaInstanceConfigBean(inetUtils);
|
||||
|
||||
|
||||
+94
-38
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2020 the original author or authors.
|
||||
* Copyright 2013-2021 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,25 +19,29 @@ 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;
|
||||
import org.springframework.cloud.client.discovery.health.DiscoveryCompositeHealthContributor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -48,13 +52,20 @@ import org.springframework.util.Assert;
|
||||
* {@link HealthCheckHandler}. By default this implementation will perform aggregation of
|
||||
* all registered {@link HealthIndicator} through registered {@link StatusAggregator}.
|
||||
*
|
||||
* A {@code null} status is returned when the application context is closed (or in the
|
||||
* process of being closed). This prevents Eureka from updating the health status and only
|
||||
* consider the status present in the current InstanceInfo.
|
||||
*
|
||||
* @author Jakub Narloch
|
||||
* @author Spencer Gibb
|
||||
* @author Nowrin Anwar Joyita
|
||||
* @author Bertrand Renuart
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @see HealthCheckHandler
|
||||
* @see StatusAggregator
|
||||
*/
|
||||
public class EurekaHealthCheckHandler implements HealthCheckHandler, ApplicationContextAware, InitializingBean {
|
||||
public class EurekaHealthCheckHandler
|
||||
implements HealthCheckHandler, ApplicationContextAware, InitializingBean, Ordered, Lifecycle {
|
||||
|
||||
private static final Map<Status, InstanceInfo.InstanceStatus> STATUS_MAPPING = new HashMap<Status, InstanceInfo.InstanceStatus>() {
|
||||
{
|
||||
@@ -69,9 +80,14 @@ public class EurekaHealthCheckHandler implements HealthCheckHandler, Application
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private Map<String, HealthIndicator> healthIndicators = new HashMap<>();
|
||||
private Map<String, HealthContributor> healthContributors = new HashMap<>();
|
||||
|
||||
private Map<String, ReactiveHealthIndicator> reactiveHealthIndicators = new HashMap<>();
|
||||
/**
|
||||
* {@code true} until the context is stopped.
|
||||
*/
|
||||
private boolean running = true;
|
||||
|
||||
private Map<String, ReactiveHealthContributor> reactiveHealthContributors = new HashMap<>();
|
||||
|
||||
public EurekaHealthCheckHandler(StatusAggregator statusAggregator) {
|
||||
this.statusAggregator = statusAggregator;
|
||||
@@ -86,42 +102,39 @@ public class EurekaHealthCheckHandler implements HealthCheckHandler, Application
|
||||
|
||||
@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) {
|
||||
return getHealthStatus();
|
||||
if (running) {
|
||||
return getHealthStatus();
|
||||
}
|
||||
else {
|
||||
// Return nothing if the context is not running, so the status held by the
|
||||
// InstanceInfo remains unchanged.
|
||||
// See gh-1571
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected InstanceStatus getHealthStatus() {
|
||||
@@ -130,21 +143,39 @@ public class EurekaHealthCheckHandler implements HealthCheckHandler, Application
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -154,4 +185,29 @@ public class EurekaHealthCheckHandler implements HealthCheckHandler, Application
|
||||
return STATUS_MAPPING.get(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
// registered with a high order priority so the close() method is invoked early
|
||||
// and *BEFORE* EurekaAutoServiceRegistration
|
||||
// (must be in effect when the registration is closed and the eureka replication
|
||||
// triggered -> health check handler is
|
||||
// consulted at that moment)
|
||||
return Ordered.HIGHEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
running = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -264,7 +264,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
|
||||
|
||||
/**
|
||||
* Flag to say that, when guessing a hostname, the IP address of the server should be
|
||||
* used in prference to the hostname reported by the OS.
|
||||
* used in preference to the hostname reported by the OS.
|
||||
*/
|
||||
private boolean preferIpAddress = false;
|
||||
|
||||
|
||||
+13
-2
@@ -34,6 +34,8 @@ 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;
|
||||
import org.springframework.cloud.netflix.eureka.http.WebClientDiscoveryClientOptionalArgs;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -60,14 +62,23 @@ public class DiscoveryClientOptionalArgsConfiguration {
|
||||
@ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class }, search = SearchStrategy.CURRENT)
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
|
||||
havingValue = "false")
|
||||
public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOptionalArgs(TlsProperties tlsProperties)
|
||||
public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOptionalArgs(TlsProperties tlsProperties,
|
||||
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier)
|
||||
throws GeneralSecurityException, IOException {
|
||||
logger.info("Eureka HTTP Client uses RestTemplate.");
|
||||
RestTemplateDiscoveryClientOptionalArgs result = new RestTemplateDiscoveryClientOptionalArgs();
|
||||
RestTemplateDiscoveryClientOptionalArgs result = new RestTemplateDiscoveryClientOptionalArgs(
|
||||
eurekaClientHttpRequestFactorySupplier);
|
||||
setupTLS(result, tlsProperties);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
|
||||
EurekaClientHttpRequestFactorySupplier defaultEurekaClientHttpRequestFactorySupplier() {
|
||||
return new DefaultEurekaClientHttpRequestFactorySupplier();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(name = "com.sun.jersey.api.client.filter.ClientFilter")
|
||||
@ConditionalOnMissingBean(value = AbstractDiscoveryClientOptionalArgs.class, search = SearchStrategy.CURRENT)
|
||||
|
||||
+36
-4
@@ -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;
|
||||
@@ -30,14 +31,19 @@ import org.springframework.boot.autoconfigure.web.reactive.function.client.WebCl
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
|
||||
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
|
||||
import org.springframework.cloud.configuration.TlsProperties;
|
||||
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
|
||||
import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier;
|
||||
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
|
||||
import org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient;
|
||||
import org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClientFactory;
|
||||
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;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
@@ -47,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 {
|
||||
@@ -63,9 +69,17 @@ public class EurekaConfigServerBootstrapConfiguration {
|
||||
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
|
||||
havingValue = "false")
|
||||
public RestTemplateEurekaHttpClient configDiscoveryRestTemplateEurekaHttpClient(EurekaClientConfigBean config,
|
||||
Environment env) {
|
||||
return (RestTemplateEurekaHttpClient) new RestTemplateTransportClientFactory()
|
||||
.newClient(HostnameBasedUrlRandomizer.randomEndpoint(config, env));
|
||||
Environment env, @Nullable TlsProperties properties,
|
||||
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
|
||||
return (RestTemplateEurekaHttpClient) new RestTemplateTransportClientFactory(properties,
|
||||
eurekaClientHttpRequestFactorySupplier)
|
||||
.newClient(HostnameBasedUrlRandomizer.randomEndpoint(config, env));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
EurekaClientHttpRequestFactorySupplier defaultEurekaClientHttpRequestFactorySupplier() {
|
||||
return new DefaultEurekaClientHttpRequestFactorySupplier();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -90,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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-2
@@ -23,7 +23,10 @@ import org.springframework.boot.Bootstrapper;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.cloud.config.client.ConfigClientProperties;
|
||||
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
|
||||
import org.springframework.cloud.configuration.TlsProperties;
|
||||
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
|
||||
import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier;
|
||||
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
|
||||
import org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClientFactory;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -50,8 +53,11 @@ public class EurekaConfigServerBootstrapper implements Bootstrapper {
|
||||
return null;
|
||||
}
|
||||
EurekaClientConfigBean config = context.get(EurekaClientConfigBean.class);
|
||||
EurekaHttpClient httpClient = new RestTemplateTransportClientFactory()
|
||||
.newClient(HostnameBasedUrlRandomizer.randomEndpoint(config, binder));
|
||||
EurekaHttpClient httpClient = new RestTemplateTransportClientFactory(
|
||||
context.getOrElse(TlsProperties.class, null),
|
||||
context.getOrElse(EurekaClientHttpRequestFactorySupplier.class,
|
||||
new DefaultEurekaClientHttpRequestFactorySupplier()))
|
||||
.newClient(HostnameBasedUrlRandomizer.randomEndpoint(config, binder));
|
||||
return new EurekaConfigServerInstanceProvider(httpClient, config)::getInstances;
|
||||
});
|
||||
}
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2013-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 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.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Supplier for the {@link ClientHttpRequestFactory} to be used by Eureka client that uses
|
||||
* {@link HttpClients}.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @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);
|
||||
}
|
||||
CloseableHttpClient httpClient = httpClientBuilder.build();
|
||||
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
|
||||
requestFactory.setHttpClient(httpClient);
|
||||
return requestFactory;
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2013-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 javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Supplier for the {@link ClientHttpRequestFactory} to be used by Eureka client.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public interface EurekaClientHttpRequestFactorySupplier {
|
||||
|
||||
/**
|
||||
* Returns a constructed {@link ClientHttpRequestFactory}.
|
||||
* @param sslContext SSL Context
|
||||
* @param hostnameVerifier Hostname verifier
|
||||
* @return {@link ClientHttpRequestFactory}
|
||||
*/
|
||||
ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVerifier hostnameVerifier);
|
||||
|
||||
}
|
||||
+14
-1
@@ -23,8 +23,21 @@ import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
|
||||
*/
|
||||
public class RestTemplateDiscoveryClientOptionalArgs extends AbstractDiscoveryClientOptionalArgs<Void> {
|
||||
|
||||
protected final EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier;
|
||||
|
||||
public RestTemplateDiscoveryClientOptionalArgs(
|
||||
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
|
||||
this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier;
|
||||
setTransportClientFactories(new RestTemplateTransportClientFactories(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - use
|
||||
* {@link RestTemplateDiscoveryClientOptionalArgs#RestTemplateDiscoveryClientOptionalArgs(EurekaClientHttpRequestFactorySupplier)}
|
||||
*/
|
||||
@Deprecated
|
||||
public RestTemplateDiscoveryClientOptionalArgs() {
|
||||
setTransportClientFactories(new RestTemplateTransportClientFactories());
|
||||
this(new DefaultEurekaClientHttpRequestFactorySupplier());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-2
@@ -33,6 +33,12 @@ import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
|
||||
*/
|
||||
public class RestTemplateTransportClientFactories implements TransportClientFactories<Void> {
|
||||
|
||||
private final RestTemplateDiscoveryClientOptionalArgs args;
|
||||
|
||||
public RestTemplateTransportClientFactories(RestTemplateDiscoveryClientOptionalArgs args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(Collection<Void> additionalFilters,
|
||||
EurekaJerseyClient providedJerseyClient) {
|
||||
@@ -42,14 +48,16 @@ public class RestTemplateTransportClientFactories implements TransportClientFact
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig,
|
||||
Collection<Void> additionalFilters, InstanceInfo myInstanceInfo) {
|
||||
return new RestTemplateTransportClientFactory();
|
||||
return new RestTemplateTransportClientFactory(this.args.getSSLContext(), this.args.getHostnameVerifier(),
|
||||
this.args.eurekaClientHttpRequestFactorySupplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportClientFactory newTransportClientFactory(final EurekaClientConfig clientConfig,
|
||||
final Collection<Void> additionalFilters, final InstanceInfo myInstanceInfo,
|
||||
final Optional<SSLContext> sslContext, final Optional<HostnameVerifier> hostnameVerifier) {
|
||||
return new RestTemplateTransportClientFactory();
|
||||
return new RestTemplateTransportClientFactory(this.args.getSSLContext(), this.args.getHostnameVerifier(),
|
||||
this.args.eurekaClientHttpRequestFactorySupplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+54
-1
@@ -18,6 +18,10 @@ package org.springframework.cloud.netflix.eureka.http;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import com.fasterxml.jackson.databind.BeanDescription;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
@@ -38,7 +42,10 @@ import com.netflix.discovery.shared.resolver.EurekaEndpoint;
|
||||
import com.netflix.discovery.shared.transport.EurekaHttpClient;
|
||||
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.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.support.BasicAuthenticationInterceptor;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
@@ -53,13 +60,53 @@ import org.springframework.web.client.RestTemplate;
|
||||
*/
|
||||
public class RestTemplateTransportClientFactory implements TransportClientFactory {
|
||||
|
||||
private final Optional<SSLContext> sslContext;
|
||||
|
||||
private final Optional<HostnameVerifier> hostnameVerifier;
|
||||
|
||||
private final EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier;
|
||||
|
||||
public RestTemplateTransportClientFactory(TlsProperties tlsProperties,
|
||||
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
|
||||
this.sslContext = context(tlsProperties);
|
||||
this.hostnameVerifier = Optional.empty();
|
||||
this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier;
|
||||
}
|
||||
|
||||
private Optional<SSLContext> context(TlsProperties properties) {
|
||||
if (properties == null || !properties.isEnabled()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
return Optional.of(new SSLContextFactory(properties).createSSLContext());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public RestTemplateTransportClientFactory(Optional<SSLContext> sslContext,
|
||||
Optional<HostnameVerifier> hostnameVerifier,
|
||||
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
|
||||
this.sslContext = sslContext;
|
||||
this.hostnameVerifier = hostnameVerifier;
|
||||
this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier;
|
||||
}
|
||||
|
||||
public RestTemplateTransportClientFactory() {
|
||||
this.sslContext = Optional.empty();
|
||||
this.hostnameVerifier = Optional.empty();
|
||||
this.eurekaClientHttpRequestFactorySupplier = new DefaultEurekaClientHttpRequestFactorySupplier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EurekaHttpClient newClient(EurekaEndpoint serviceUrl) {
|
||||
return new RestTemplateEurekaHttpClient(restTemplate(serviceUrl.getServiceUrl()), serviceUrl.getServiceUrl());
|
||||
}
|
||||
|
||||
private RestTemplate restTemplate(String serviceUrl) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
RestTemplate restTemplate = restTemplate();
|
||||
|
||||
try {
|
||||
URI serviceURI = new URI(serviceUrl);
|
||||
if (serviceURI.getUserInfo() != null) {
|
||||
@@ -80,6 +127,12 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
|
||||
return restTemplate;
|
||||
}
|
||||
|
||||
private RestTemplate restTemplate() {
|
||||
ClientHttpRequestFactory requestFactory = this.eurekaClientHttpRequestFactorySupplier
|
||||
.get(this.sslContext.orElse(null), this.hostnameVerifier.orElse(null));
|
||||
return new RestTemplate(requestFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the serialization configurations required by the Eureka Server. JSON
|
||||
* content exchanged with eureka requires a root node matching the entity being
|
||||
|
||||
+5
-5
@@ -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");
|
||||
|
||||
+3
-6
@@ -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);
|
||||
}
|
||||
|
||||
+122
-46
@@ -27,16 +27,18 @@ 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 +53,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 +72,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 +95,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 +105,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 +116,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 +127,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 +138,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 +167,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 +182,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 +192,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 +202,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 +215,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 +228,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 +241,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 +252,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 +264,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 +275,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 +287,71 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthCheckUrlPathWithServerPortAndContextPathKebobCase() {
|
||||
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);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().endsWith(":8989/management/actuator/info"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
assertThat(instance.getHealthCheckUrl().endsWith(":8989/management/actuator/health"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrlPath().equals("/management/actuator/info"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrlPath()).isTrue();
|
||||
assertThat(instance.getHealthCheckUrlPath().equals("/management/actuator/health"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrlPath()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().endsWith(":9999/manage/myStatusPage"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl().endsWith(":9999/manage/myHealthCheck"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getStatusPageUrl().endsWith(":9999/manage/myStatusPage"))
|
||||
.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
EurekaInstanceConfigBean instance = this.context.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl().endsWith(":9999/manage/myHealthCheck"))
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void healthCheckUrlPathWithServerPortAndContextPathKebobCase() {
|
||||
TestPropertyValues
|
||||
.of("server.port=8989", "server.servlet.context-path=/servletContextPath",
|
||||
"eureka.instance.health-check-url-path=${server.servlet.context-path:}/myHealthCheck")
|
||||
@@ -296,7 +363,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);
|
||||
@@ -306,7 +373,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);
|
||||
|
||||
@@ -320,7 +387,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")
|
||||
@@ -336,7 +403,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);
|
||||
@@ -346,7 +413,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);
|
||||
@@ -356,7 +423,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);
|
||||
@@ -366,7 +433,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);
|
||||
@@ -376,7 +443,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshScopedBeans() {
|
||||
void refreshScopedBeans() {
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
assertThat(this.context.getBeanDefinition("eurekaClient").getBeanClassName())
|
||||
.startsWith(GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
|
||||
@@ -384,9 +451,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();
|
||||
@@ -398,6 +469,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();
|
||||
@@ -410,7 +486,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);
|
||||
|
||||
@@ -425,7 +501,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);
|
||||
@@ -435,7 +511,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");
|
||||
@@ -443,7 +519,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");
|
||||
@@ -452,7 +528,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");
|
||||
@@ -494,7 +570,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();
|
||||
@@ -502,13 +578,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);
|
||||
@@ -518,7 +594,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);
|
||||
@@ -529,7 +605,7 @@ public class EurekaClientAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenBlockingDiscoveryDisabled() {
|
||||
void shouldNotHaveDiscoveryClientWhenBlockingDiscoveryDisabled() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
|
||||
DiscoveryClientOptionalArgsConfiguration.class, EurekaClientAutoConfiguration.class,
|
||||
|
||||
+11
-11
@@ -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();
|
||||
|
||||
+133
-19
@@ -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,20 @@ public class EurekaHealthCheckHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDownWithBlockingIndicators() throws Exception {
|
||||
void testHealthCheckNotReturnedWhenStopped() {
|
||||
initialize(UpHealthConfiguration.class);
|
||||
|
||||
healthCheckHandler.stop();
|
||||
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
|
||||
|
||||
assertThat(status).isNull();
|
||||
healthCheckHandler.start();
|
||||
InstanceStatus newStatus = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
|
||||
assertThat(newStatus).isEqualTo(InstanceStatus.UP);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDownWithBlockingIndicators() {
|
||||
initialize(UpHealthConfiguration.class, DownHealthConfiguration.class);
|
||||
|
||||
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
|
||||
@@ -79,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);
|
||||
@@ -87,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);
|
||||
@@ -95,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);
|
||||
@@ -103,7 +122,7 @@ public class EurekaHealthCheckHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknown() throws Exception {
|
||||
void testUnknown() {
|
||||
initialize(FatalHealthConfiguration.class);
|
||||
|
||||
InstanceStatus status = healthCheckHandler.getStatus(InstanceStatus.UNKNOWN);
|
||||
@@ -111,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();
|
||||
@@ -131,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();
|
||||
}
|
||||
};
|
||||
@@ -145,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();
|
||||
}
|
||||
};
|
||||
@@ -159,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");
|
||||
}
|
||||
};
|
||||
@@ -225,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());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+31
-29
@@ -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);
|
||||
}
|
||||
|
||||
+3
-3
@@ -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);
|
||||
|
||||
+5
-5
@@ -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");
|
||||
}
|
||||
|
||||
+3
-6
@@ -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());
|
||||
}
|
||||
|
||||
+5
-5
@@ -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))
|
||||
|
||||
+103
-8
@@ -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 {
|
||||
|
||||
+5
-6
@@ -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();
|
||||
|
||||
+7
-6
@@ -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);
|
||||
|
||||
+3
-3
@@ -25,10 +25,10 @@ import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EurekaConfigServerBootstrapperTests {
|
||||
class EurekaConfigServerBootstrapperTests {
|
||||
|
||||
@Test
|
||||
public void notEnabledDoesNotAddInstanceProviderFn() {
|
||||
void notEnabledDoesNotAddInstanceProviderFn() {
|
||||
new SpringApplicationBuilder(TestConfig.class)
|
||||
.properties("spring.cloud.service-registry.auto-registration.enabled=false")
|
||||
.addBootstrapper(registry -> registry.addCloseListener(event -> {
|
||||
@@ -40,7 +40,7 @@ public class EurekaConfigServerBootstrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledAddsInstanceProviderFn() {
|
||||
void enabledAddsInstanceProviderFn() {
|
||||
new SpringApplicationBuilder(TestConfig.class)
|
||||
.properties("spring.cloud.config.discovery.enabled=true",
|
||||
"spring.cloud.service-registry.auto-registration.enabled=false")
|
||||
|
||||
+3
-6
@@ -17,15 +17,13 @@
|
||||
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.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;
|
||||
|
||||
@@ -33,15 +31,14 @@ 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;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
void contextLoads() {
|
||||
assertThat(optionalArgs).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
+3
-6
@@ -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;
|
||||
|
||||
@@ -39,17 +37,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Jakub Narloch
|
||||
*/
|
||||
@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() {
|
||||
|
||||
InstanceInfo.InstanceStatus status = this.discoveryClient.getHealthCheckHandler()
|
||||
.getStatus(InstanceInfo.InstanceStatus.UNKNOWN);
|
||||
|
||||
+15
-15
@@ -19,7 +19,7 @@ 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.Test;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@@ -28,80 +28,80 @@ 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() {
|
||||
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");
|
||||
}
|
||||
|
||||
+4
-7
@@ -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);
|
||||
|
||||
+9
-5
@@ -16,16 +16,20 @@
|
||||
|
||||
package org.springframework.cloud.netflix.eureka.http;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Daniel Lavoie
|
||||
*/
|
||||
public class RestTemplateTransportClientFactoriesTest {
|
||||
class RestTemplateTransportClientFactoriesTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testJerseyIsUnsuported() {
|
||||
new RestTemplateTransportClientFactories().newTransportClientFactory(null, null);
|
||||
@Test
|
||||
void testJerseyIsUnsupported() {
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
|
||||
new RestTemplateTransportClientFactories(new RestTemplateDiscoveryClientOptionalArgs(null))
|
||||
.newTransportClientFactory(null, null);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+4
-7
@@ -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));
|
||||
|
||||
|
||||
+9
-5
@@ -16,18 +16,22 @@
|
||||
|
||||
package org.springframework.cloud.netflix.eureka.http;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
* @author Daniel Lavoie
|
||||
*/
|
||||
public class WebClientTransportClientFactoriesTest {
|
||||
class WebClientTransportClientFactoriesTest {
|
||||
|
||||
@Test
|
||||
void testJerseyIsUnsupported() {
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
|
||||
new WebClientTransportClientFactories(WebClient::builder).newTransportClientFactory(null, null);
|
||||
});
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testJerseyIsUnsuported() {
|
||||
new WebClientTransportClientFactories(WebClient::builder).newTransportClientFactory(null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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 -> {
|
||||
|
||||
+16
-16
@@ -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";
|
||||
|
||||
+6
-6
@@ -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);
|
||||
|
||||
+7
-7
@@ -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));
|
||||
|
||||
+3
-6
@@ -16,21 +16,18 @@
|
||||
|
||||
package org.springframework.cloud.netflix.eureka.sample;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
public class ApplicationTests {
|
||||
class ApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
|
||||
import com.netflix.appinfo.ApplicationInfoManager;
|
||||
import com.netflix.appinfo.InstanceInfo;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
@@ -41,10 +41,10 @@ import static org.mockito.Mockito.when;
|
||||
* @author Spencer Gibb
|
||||
* @author Tim Ysewyn
|
||||
*/
|
||||
public class EurekaServiceRegistryTests {
|
||||
class EurekaServiceRegistryTests {
|
||||
|
||||
@Test
|
||||
public void eurekaClientNotShutdownInDeregister() {
|
||||
void eurekaClientNotShutdownInDeregister() {
|
||||
EurekaServiceRegistry registry = new EurekaServiceRegistry();
|
||||
|
||||
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
|
||||
@@ -63,7 +63,7 @@ public class EurekaServiceRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eurekaClientGetStatus() {
|
||||
void eurekaClientGetStatus() {
|
||||
EurekaServiceRegistry registry = new EurekaServiceRegistry();
|
||||
|
||||
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
|
||||
@@ -99,7 +99,7 @@ public class EurekaServiceRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eurekaClientGetStatusNoInstance() {
|
||||
void eurekaClientGetStatusNoInstance() {
|
||||
EurekaServiceRegistry registry = new EurekaServiceRegistry();
|
||||
|
||||
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.netflix.eureka.support;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -24,10 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Ryan Baxter
|
||||
*
|
||||
*/
|
||||
public class ZoneUtilsTests {
|
||||
class ZoneUtilsTests {
|
||||
|
||||
@Test
|
||||
public void extractApproximateZoneTest() {
|
||||
void extractApproximateZoneTest() {
|
||||
assertThat("foo".equals(ZoneUtils.extractApproximateZone("foo"))).isTrue();
|
||||
assertThat("bar".equals(ZoneUtils.extractApproximateZone("foo.bar"))).isTrue();
|
||||
assertThat("world.foo.bar".equals(ZoneUtils.extractApproximateZone("hello.world.foo.bar"))).isTrue();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix</artifactId>
|
||||
<version>3.0.0-RC1</version>
|
||||
<version>3.0.6</version>
|
||||
<relativePath>..</relativePath> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
|
||||
@@ -81,30 +81,16 @@
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.restdocs</groupId>
|
||||
<artifactId>spring-restdocs-restassured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock-jre8-standalone</artifactId>
|
||||
|
||||
+23
-4
@@ -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.
|
||||
@@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Gang Li
|
||||
* @author Weix Sun
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("${eureka.dashboard.path:/}")
|
||||
@@ -58,8 +59,20 @@ public class EurekaController {
|
||||
|
||||
private ApplicationInfoManager applicationInfoManager;
|
||||
|
||||
private final EurekaProperties eurekaProperties;
|
||||
|
||||
/**
|
||||
* @deprecated in favour of
|
||||
* {@link EurekaController#EurekaController(ApplicationInfoManager, EurekaProperties)}
|
||||
*/
|
||||
@Deprecated
|
||||
public EurekaController(ApplicationInfoManager applicationInfoManager) {
|
||||
this(applicationInfoManager, null);
|
||||
}
|
||||
|
||||
public EurekaController(ApplicationInfoManager applicationInfoManager, EurekaProperties eurekaProperties) {
|
||||
this.applicationInfoManager = applicationInfoManager;
|
||||
this.eurekaProperties = eurekaProperties;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@@ -116,11 +129,17 @@ public class EurekaController {
|
||||
private void populateHeader(Map<String, Object> model) {
|
||||
model.put("currentTime", StatusResource.getCurrentTimeAsString());
|
||||
model.put("upTime", StatusInfo.getUpTime());
|
||||
model.put("environment", "N/A"); // FIXME:
|
||||
model.put("datacenter", "N/A"); // FIXME:
|
||||
if (eurekaProperties != null) {
|
||||
model.put("environment", eurekaProperties.getEnvironment());
|
||||
model.put("datacenter", eurekaProperties.getDatacenter());
|
||||
}
|
||||
else {
|
||||
model.put("environment", "N/A");
|
||||
model.put("datacenter", "N/A");
|
||||
}
|
||||
PeerAwareInstanceRegistry registry = getRegistry();
|
||||
model.put("registry", registry);
|
||||
model.put("isBelowRenewThresold", registry.isBelowRenewThresold() == 1);
|
||||
model.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);
|
||||
DataCenterInfo info = applicationInfoManager.getInfo().getDataCenterInfo();
|
||||
if (info.getName() == DataCenterInfo.Name.Amazon) {
|
||||
AmazonInfo amazonInfo = (AmazonInfo) info;
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.server;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties for the Eureka deployment.
|
||||
*
|
||||
* @author Weix Sun
|
||||
*/
|
||||
@ConfigurationProperties("eureka")
|
||||
public class EurekaProperties {
|
||||
|
||||
/**
|
||||
* Eureka environment. Defaults to "test".
|
||||
*/
|
||||
private String environment = "test";
|
||||
|
||||
/**
|
||||
* Eureka datacenter. Defaults to "default".
|
||||
*/
|
||||
private String datacenter = "default";
|
||||
|
||||
public String getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(String environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public String getDatacenter() {
|
||||
return datacenter;
|
||||
}
|
||||
|
||||
public void setDatacenter(String datacenter) {
|
||||
this.datacenter = datacenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
EurekaProperties that = (EurekaProperties) o;
|
||||
return Objects.equals(datacenter, that.datacenter) && Objects.equals(environment, that.environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(environment, datacenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("EurekaProperties{");
|
||||
sb.append("environment='").append(environment).append('\'');
|
||||
sb.append(", datacenter=").append(datacenter);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+6
-4
@@ -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.
|
||||
@@ -73,11 +73,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
* @author Gunnar Hillert
|
||||
* @author Biju Kunjummen
|
||||
* @author Fahim Farook
|
||||
* @author Weix Sun
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(EurekaServerInitializerConfiguration.class)
|
||||
@ConditionalOnBean(EurekaServerMarkerConfiguration.Marker.class)
|
||||
@EnableConfigurationProperties({ EurekaDashboardProperties.class, InstanceRegistryProperties.class })
|
||||
@EnableConfigurationProperties({ EurekaDashboardProperties.class, InstanceRegistryProperties.class,
|
||||
EurekaProperties.class })
|
||||
@PropertySource("classpath:/eureka/server.properties")
|
||||
public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@@ -113,8 +115,8 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true)
|
||||
public EurekaController eurekaController() {
|
||||
return new EurekaController(this.applicationInfoManager);
|
||||
public EurekaController eurekaController(EurekaProperties eurekaProperties) {
|
||||
return new EurekaController(this.applicationInfoManager, eurekaProperties);
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
+2
-7
@@ -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.
|
||||
@@ -38,6 +38,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Weix Sun
|
||||
*/
|
||||
public class EurekaServerBootstrap {
|
||||
|
||||
@@ -67,7 +68,6 @@ public class EurekaServerBootstrap {
|
||||
|
||||
public void contextInitialized(ServletContext context) {
|
||||
try {
|
||||
initEurekaEnvironment();
|
||||
initEurekaServerContext();
|
||||
|
||||
context.setAttribute(EurekaServerContext.class.getName(), this.serverContext);
|
||||
@@ -93,11 +93,6 @@ public class EurekaServerBootstrap {
|
||||
log.info("Eureka Service is now shutdown...");
|
||||
}
|
||||
|
||||
protected void initEurekaEnvironment() throws Exception {
|
||||
log.info("Setting the eureka configuration..");
|
||||
|
||||
}
|
||||
|
||||
protected void initEurekaServerContext() throws Exception {
|
||||
// For backward compatibility
|
||||
JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<#if isBelowRenewThresold>
|
||||
<#if isBelowRenewThreshold>
|
||||
<#if !registry.selfPreservationModeEnabled>
|
||||
<h4 id="uptime"><font size="+1" color="red"><b>RENEWALS ARE LESSER THAN THE THRESHOLD. THE SELF PRESERVATION MODE IS TURNED OFF. THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS.</b></font></h4>
|
||||
<#else>
|
||||
|
||||
+7
-10
@@ -19,8 +19,7 @@ package org.springframework.cloud.netflix.eureka.server;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -36,15 +35,13 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.application.name=eureka", "server.servlet.context-path=/context",
|
||||
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" })
|
||||
public class ApplicationContextTests {
|
||||
class ApplicationContextTests {
|
||||
|
||||
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
|
||||
|
||||
@@ -52,7 +49,7 @@ public class ApplicationContextTests {
|
||||
private int port = 0;
|
||||
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/apps", Map.class);
|
||||
@@ -60,7 +57,7 @@ public class ApplicationContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -73,21 +70,21 @@ public class ApplicationContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cssAvailable() {
|
||||
void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/css/wro.css", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsAvailable() {
|
||||
void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/context/eureka/js/wro.js", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adminLoads() {
|
||||
void adminLoads() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
|
||||
|
||||
+4
-7
@@ -18,8 +18,7 @@ package org.springframework.cloud.netflix.eureka.server;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -28,20 +27,18 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.cloud.netflix.eureka.server.ApplicationContextTests.Application;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka", "eureka.dashboard.enabled=false" })
|
||||
public class ApplicationDashboardDisabledTests {
|
||||
class ApplicationDashboardDisabledTests {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port = 0;
|
||||
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
@@ -49,7 +46,7 @@ public class ApplicationDashboardDisabledTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
|
||||
+6
-9
@@ -18,8 +18,7 @@ package org.springframework.cloud.netflix.eureka.server;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -28,20 +27,18 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.cloud.netflix.eureka.server.ApplicationContextTests.Application;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka", "eureka.dashboard.path=/dashboard" })
|
||||
public class ApplicationDashboardPathTests {
|
||||
class ApplicationDashboardPathTests {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port = 0;
|
||||
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
@@ -49,7 +46,7 @@ public class ApplicationDashboardPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/dashboard", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -66,14 +63,14 @@ public class ApplicationDashboardPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cssAvailable() {
|
||||
void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/css/wro.css", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsAvailable() {
|
||||
void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/js/wro.js", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
+7
-10
@@ -19,8 +19,7 @@ package org.springframework.cloud.netflix.eureka.server;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -35,16 +34,14 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = RANDOM_PORT,
|
||||
properties = { "spring.application.name=eureka", "server.servlet.context-path=/servlet",
|
||||
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" })
|
||||
public class ApplicationServletPathTests {
|
||||
class ApplicationServletPathTests {
|
||||
|
||||
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
|
||||
|
||||
@@ -52,7 +49,7 @@ public class ApplicationServletPathTests {
|
||||
private int port = 0;
|
||||
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/apps", Map.class);
|
||||
@@ -60,7 +57,7 @@ public class ApplicationServletPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardLoads() {
|
||||
void dashboardLoads() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -73,21 +70,21 @@ public class ApplicationServletPathTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cssAvailable() {
|
||||
void cssAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/css/wro.css", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsAvailable() {
|
||||
void jsAvailable() {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/servlet/eureka/js/wro.js", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adminLoads() {
|
||||
void adminLoads() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
|
||||
|
||||
+7
-10
@@ -22,8 +22,7 @@ import java.util.Map;
|
||||
import com.netflix.appinfo.InstanceInfo;
|
||||
import com.netflix.discovery.converters.wrappers.CodecWrapper;
|
||||
import com.netflix.eureka.resources.ServerCodecs;
|
||||
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.autoconfigure.endpoint.web.WebEndpointProperties;
|
||||
@@ -39,15 +38,13 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = RANDOM_PORT, properties = { "spring.jmx.enabled=true",
|
||||
"management.security.enabled=false", "management.endpoints.web.exposure.include=*" })
|
||||
public class ApplicationTests {
|
||||
class ApplicationTests {
|
||||
|
||||
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
|
||||
|
||||
@@ -58,7 +55,7 @@ public class ApplicationTests {
|
||||
private ServerCodecs serverCodecs;
|
||||
|
||||
@Test
|
||||
public void catalogLoads() {
|
||||
void catalogLoads() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class);
|
||||
@@ -66,7 +63,7 @@ public class ApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adminLoads() {
|
||||
void adminLoads() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
|
||||
@@ -78,7 +75,7 @@ public class ApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDoubleSlashes() {
|
||||
void noDoubleSlashes() {
|
||||
String basePath = "http://localhost:" + this.port + "/";
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(basePath, String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -88,7 +85,7 @@ public class ApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cssParsedByLess() {
|
||||
void cssParsedByLess() {
|
||||
String basePath = "http://localhost:" + this.port + "/eureka/css/wro.css";
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(basePath, String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -98,7 +95,7 @@ public class ApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customCodecWorks() throws Exception {
|
||||
void customCodecWorks() throws Exception {
|
||||
assertThat(this.serverCodecs).as("serverCodecs is wrong type")
|
||||
.isInstanceOf(EurekaServerAutoConfiguration.CloudServerCodecs.class);
|
||||
CodecWrapper codec = this.serverCodecs.getFullJsonCodec();
|
||||
|
||||
+11
-11
@@ -22,15 +22,15 @@ import java.util.Map;
|
||||
import com.netflix.appinfo.ApplicationInfoManager;
|
||||
import com.netflix.appinfo.InstanceInfo;
|
||||
import com.netflix.eureka.util.StatusInfo;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.cloud.netflix.eureka.server.EurekaControllerTests.setInstance;
|
||||
|
||||
public class EurekaControllerReplicasTests {
|
||||
class EurekaControllerReplicasTests {
|
||||
|
||||
String noAuthList1 = "https://test1.com";
|
||||
|
||||
@@ -58,21 +58,21 @@ public class EurekaControllerReplicasTests {
|
||||
|
||||
private InstanceInfo instanceInfo;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
this.original = ApplicationInfoManager.getInstance();
|
||||
setInstance(mock(ApplicationInfoManager.class));
|
||||
instanceInfo = mock(InstanceInfo.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
@AfterEach
|
||||
void teardown() throws Exception {
|
||||
setInstance(this.original);
|
||||
instanceInfo = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterReplicasNoAuth() throws Exception {
|
||||
void testFilterReplicasNoAuth() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", empty)
|
||||
.add("available-replicas", noAuthList1).add("unavailable-replicas", noAuthList2)
|
||||
@@ -90,7 +90,7 @@ public class EurekaControllerReplicasTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterReplicasAuth() throws Exception {
|
||||
void testFilterReplicasAuth() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", authList2)
|
||||
.add("available-replicas", authList1).add("unavailable-replicas", empty).withInstanceInfo(instanceInfo)
|
||||
@@ -108,7 +108,7 @@ public class EurekaControllerReplicasTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterReplicasAuthWithCombinationList() throws Exception {
|
||||
void testFilterReplicasAuthWithCombinationList() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", totalAutoList)
|
||||
.add("available-replicas", combinationAuthList1).add("unavailable-replicas", combinationAuthList2)
|
||||
|
||||
+14
-11
@@ -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,9 +33,9 @@ import com.netflix.eureka.EurekaServerContextHolder;
|
||||
import com.netflix.eureka.cluster.PeerEurekaNode;
|
||||
import com.netflix.eureka.cluster.PeerEurekaNodes;
|
||||
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
|
||||
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.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -44,14 +44,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class EurekaControllerTests {
|
||||
class EurekaControllerTests {
|
||||
|
||||
private ApplicationInfoManager infoManager;
|
||||
|
||||
private ApplicationInfoManager original;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class);
|
||||
when(peerEurekaNodes.getPeerNodesView()).thenReturn(Collections.<PeerEurekaNode>emptyList());
|
||||
|
||||
@@ -81,8 +81,8 @@ public class EurekaControllerTests {
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
@AfterEach
|
||||
void teardown() throws Exception {
|
||||
setInstance(this.original);
|
||||
}
|
||||
|
||||
@@ -93,13 +93,16 @@ public class EurekaControllerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatus() throws Exception {
|
||||
void testStatus() throws Exception {
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
|
||||
EurekaController controller = new EurekaController(infoManager);
|
||||
EurekaController controller = new EurekaController(infoManager, new EurekaProperties());
|
||||
|
||||
controller.status(new MockHttpServletRequest("GET", "/"), model);
|
||||
|
||||
assertThat((String) model.get("environment")).isEqualTo("test");
|
||||
assertThat((String) model.get("datacenter")).isEqualTo("default");
|
||||
|
||||
Map<String, Object> app = getFirst(model, "apps");
|
||||
Map<String, Object> instanceInfo = getFirst(app, "instanceInfos");
|
||||
Map<String, Object> instance = getFirst(instanceInfo, "instances");
|
||||
|
||||
+3
-6
@@ -22,29 +22,26 @@ import com.netflix.eureka.EurekaServerConfig;
|
||||
import com.netflix.eureka.cluster.PeerEurekaNodes;
|
||||
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
|
||||
import com.netflix.eureka.resources.ServerCodecs;
|
||||
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.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = EurekaCustomPeerNodesTests.Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=eureka",
|
||||
"server.contextPath=/context", "management.security.enabled=false" })
|
||||
public class EurekaCustomPeerNodesTests {
|
||||
class EurekaCustomPeerNodesTests {
|
||||
|
||||
@Autowired
|
||||
private PeerEurekaNodes peerEurekaNodes;
|
||||
|
||||
@Test
|
||||
public void testCustomPeerNodesShouldTakePrecedenceOverDefault() {
|
||||
void testCustomPeerNodesShouldTakePrecedenceOverDefault() {
|
||||
assertThat(peerEurekaNodes instanceof CustomEurekaPeerNodes)
|
||||
.as("PeerEurekaNodes should be the user created one").isTrue();
|
||||
}
|
||||
|
||||
+9
-9
@@ -16,19 +16,19 @@
|
||||
|
||||
package org.springframework.cloud.netflix.eureka.server;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EurekaServerInitializerConfigurationTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class EurekaServerInitializerConfigurationTest {
|
||||
|
||||
@Mock
|
||||
private EurekaServerBootstrap eurekaServerBootstrapMock;
|
||||
@@ -38,13 +38,13 @@ public class EurekaServerInitializerConfigurationTest {
|
||||
|
||||
private boolean callbackCalled;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
callbackCalled = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopWithCallbackCallsStop() {
|
||||
void testStopWithCallbackCallsStop() {
|
||||
eurekaServerInitializerConfiguration.stop(this::setCallbackCalledTrue);
|
||||
|
||||
assertThat(callbackCalled).isTrue();
|
||||
|
||||
+9
-12
@@ -25,9 +25,8 @@ import com.netflix.appinfo.InstanceInfo;
|
||||
import com.netflix.appinfo.LeaseInfo;
|
||||
import com.netflix.discovery.shared.Application;
|
||||
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -41,7 +40,6 @@ import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.SmartApplicationListener;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -49,11 +47,10 @@ import static org.mockito.Mockito.doReturn;
|
||||
/**
|
||||
* @author Bartlomiej Slota
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.application.name=eureka",
|
||||
"logging.level.org.springframework." + "cloud.netflix.eureka.server.InstanceRegistry=DEBUG" })
|
||||
public class InstanceRegistryTests {
|
||||
class InstanceRegistryTests {
|
||||
|
||||
private static final String APP_NAME = "MY-APP-NAME";
|
||||
|
||||
@@ -66,8 +63,8 @@ public class InstanceRegistryTests {
|
||||
@SpyBean(PeerAwareInstanceRegistry.class)
|
||||
private InstanceRegistry instanceRegistry;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.testEvents.applicationEvents.clear();
|
||||
}
|
||||
|
||||
@@ -75,7 +72,7 @@ public class InstanceRegistryTests {
|
||||
private TestEvents testEvents;
|
||||
|
||||
@Test
|
||||
public void testRegister() throws Exception {
|
||||
void testRegister() throws Exception {
|
||||
// creating instance info
|
||||
final LeaseInfo leaseInfo = getLeaseInfo();
|
||||
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, leaseInfo);
|
||||
@@ -94,7 +91,7 @@ public class InstanceRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultLeaseDurationRegisterEvent() throws Exception {
|
||||
void testDefaultLeaseDurationRegisterEvent() throws Exception {
|
||||
// creating instance info
|
||||
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null);
|
||||
// calling tested method
|
||||
@@ -106,7 +103,7 @@ public class InstanceRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInternalCancel() throws Exception {
|
||||
void testInternalCancel() throws Exception {
|
||||
// calling tested method
|
||||
instanceRegistry.internalCancel(APP_NAME, HOST_NAME, false);
|
||||
// event of proper type is registered
|
||||
@@ -122,7 +119,7 @@ public class InstanceRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenew() throws Exception {
|
||||
void testRenew() throws Exception {
|
||||
// Creating two instances of the app
|
||||
final InstanceInfo instanceInfo1 = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null);
|
||||
final InstanceInfo instanceInfo2 = getInstanceInfo(APP_NAME, HOST_NAME, "my-host-name:8009", 8009, null);
|
||||
|
||||
+12
-15
@@ -27,8 +27,7 @@ import com.netflix.eureka.EurekaServerConfig;
|
||||
import com.netflix.eureka.cluster.PeerEurekaNodes;
|
||||
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
|
||||
import com.netflix.eureka.resources.ServerCodecs;
|
||||
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.beans.factory.annotation.Value;
|
||||
@@ -44,7 +43,6 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
@@ -57,11 +55,10 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* @author Fahim Farook
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RefreshablePeerEurekaNodesTests.Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=eureka-server",
|
||||
"eureka.client.service-url.defaultZone=http://localhost:8678/eureka/" })
|
||||
public class RefreshablePeerEurekaNodesTests {
|
||||
class RefreshablePeerEurekaNodesTests {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
@@ -79,7 +76,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
private static final String USE_DNS = "eureka.client.use-dns-for-fetching-service-urls";
|
||||
|
||||
@Test
|
||||
public void notUpdatedWhenDnsIsTrue() {
|
||||
void notUpdatedWhenDnsIsTrue() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=true",
|
||||
"eureka.client.region=unavailable-region", // to force defaultZone
|
||||
"eureka.client.service-url.defaultZone=https://default-host1:8678/eureka/");
|
||||
@@ -91,7 +88,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatedWhenDnsIsFalse() {
|
||||
void updatedWhenDnsIsFalse() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false",
|
||||
"eureka.client.region=unavailable-region", // to force defaultZone
|
||||
"eureka.client.service-url.defaultZone=https://default-host2:8678/eureka/");
|
||||
@@ -103,7 +100,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatedWhenRegionChanged() {
|
||||
void updatedWhenRegionChanged() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", "eureka.client.region=region1",
|
||||
"eureka.client.availability-zones.region1=region1-zone",
|
||||
"eureka.client.availability-zones.region2=region2-zone",
|
||||
@@ -120,7 +117,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatedWhenAvailabilityZoneChanged() {
|
||||
void updatedWhenAvailabilityZoneChanged() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", "eureka.client.region=region4",
|
||||
"eureka.client.availability-zones.region3=region3-zone",
|
||||
"eureka.client.service-url.region4-zone=https://region4-zone-host:8678/eureka/",
|
||||
@@ -138,7 +135,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpdatedWhenIrrelevantPropertiesChanged() {
|
||||
void notUpdatedWhenIrrelevantPropertiesChanged() {
|
||||
// Only way to test this is verifying whether updatePeerEurekaNodes() is invoked.
|
||||
|
||||
// PeerEurekaNodes.updatePeerEurekaNodes() is not public, hence cannot verify with
|
||||
@@ -168,14 +165,14 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void peerEurekaNodesIsRefreshablePeerEurekaNodes() {
|
||||
void peerEurekaNodesIsRefreshablePeerEurekaNodes() {
|
||||
assertThat(this.peerEurekaNodes).isNotNull();
|
||||
assertThat(this.peerEurekaNodes instanceof RefreshablePeerEurekaNodes)
|
||||
.as("PeerEurekaNodes should be an instance of RefreshablePeerEurekaNodes").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrlsCountAsSoonAsRefreshed() {
|
||||
void serviceUrlsCountAsSoonAsRefreshed() {
|
||||
changeProperty(
|
||||
"eureka.client.service-url.defaultZone=https://defaul-host3:8678/eureka/,http://defaul-host4:8678/eureka/");
|
||||
forceUpdate();
|
||||
@@ -184,7 +181,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceUrlsValueAsSoonAsRefreshed() {
|
||||
void serviceUrlsValueAsSoonAsRefreshed() {
|
||||
changeProperty("eureka.client.service-url.defaultZone=https://defaul-host4:8678/eureka/");
|
||||
forceUpdate();
|
||||
assertThat(serviceUrlMatches("https://defaul-host4:8678/eureka/"))
|
||||
@@ -192,7 +189,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dashboardUpdatedAsSoonAsRefreshed() {
|
||||
void dashboardUpdatedAsSoonAsRefreshed() {
|
||||
changeProperty("eureka.client.service-url.defaultZone=https://defaul-host5:8678/eureka/");
|
||||
forceUpdate();
|
||||
final ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/",
|
||||
@@ -205,7 +202,7 @@ public class RefreshablePeerEurekaNodesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notUpdatedForRelaxedKeys() {
|
||||
void notUpdatedForRelaxedKeys() {
|
||||
changeProperty("eureka.client.use-dns-for-fetching-service-urls=false",
|
||||
"eureka.client.region=unavailable-region", // to force defaultZone
|
||||
"eureka.client.service-url.defaultZone=https://defaul-host6:8678/eureka/");
|
||||
|
||||
+3
-6
@@ -24,8 +24,7 @@ import com.sun.jersey.api.client.ClientHandlerException;
|
||||
import com.sun.jersey.api.client.ClientRequest;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.filter.ClientFilter;
|
||||
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.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -33,7 +32,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration.RefreshablePeerEurekaNodes;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -41,17 +39,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Yuxin Bai
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RefreshablePeerEurekaNodesWithCustomFiltersTests.Application.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=eureka",
|
||||
"server.contextPath=/context", "management.security.enabled=false" })
|
||||
public class RefreshablePeerEurekaNodesWithCustomFiltersTests {
|
||||
class RefreshablePeerEurekaNodesWithCustomFiltersTests {
|
||||
|
||||
@Autowired
|
||||
private PeerEurekaNodes peerEurekaNodes;
|
||||
|
||||
@Test
|
||||
public void testCustomPeerNodesShouldTakePrecedenceOverDefault() {
|
||||
void testCustomPeerNodesShouldTakePrecedenceOverDefault() {
|
||||
assertThat(peerEurekaNodes instanceof RefreshablePeerEurekaNodes)
|
||||
.as("PeerEurekaNodes should be an instance of RefreshablePeerEurekaNodes").isTrue();
|
||||
|
||||
|
||||
-187
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-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.server.doc;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.netflix.appinfo.ApplicationInfoManager;
|
||||
import com.netflix.appinfo.InstanceInfo;
|
||||
import com.netflix.eureka.DefaultEurekaServerContext;
|
||||
import com.netflix.eureka.EurekaServerConfig;
|
||||
import com.netflix.eureka.EurekaServerContext;
|
||||
import com.netflix.eureka.cluster.PeerEurekaNodes;
|
||||
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
|
||||
import com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl;
|
||||
import com.netflix.eureka.resources.ServerCodecs;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.filter.Filter;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
|
||||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
||||
import org.springframework.cloud.netflix.eureka.server.doc.AbstractDocumentationTests.Application;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.restdocs.restassured3.RestAssuredRestDocumentation;
|
||||
import org.springframework.restdocs.restassured3.RestDocumentationFilter;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.modifyUris;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
|
||||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
|
||||
import static org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.documentationConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
value = { "spring.jmx.enabled=false", "management.security.enabled=false" })
|
||||
@DirtiesContext
|
||||
public abstract class AbstractDocumentationTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port = 0;
|
||||
|
||||
@Autowired
|
||||
private PeerAwareInstanceRegistryImpl registry;
|
||||
|
||||
@Autowired
|
||||
private EurekaInstanceConfigBean instanceConfig;
|
||||
|
||||
@Autowired
|
||||
private ApplicationInfoManager applicationInfoManager;
|
||||
|
||||
@Rule
|
||||
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
|
||||
|
||||
@After
|
||||
public void init() {
|
||||
registry.clearRegistry();
|
||||
ReflectionTestUtils.setField(registry, "responseCache", null);
|
||||
registry.initializedResponseCache();
|
||||
}
|
||||
|
||||
protected InstanceInfo register(String name) {
|
||||
return register(name, UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
protected InstanceInfo register(String name, String id) {
|
||||
registry.register(instance(name, id), false);
|
||||
return instance();
|
||||
}
|
||||
|
||||
protected InstanceInfo instance(String name) {
|
||||
return instance(name, UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
protected InstanceInfo instance(String name, String id) {
|
||||
instanceConfig.setAppname(name);
|
||||
instanceConfig.setInstanceId(id);
|
||||
instanceConfig.setHostname("foo.example.com");
|
||||
applicationInfoManager.initComponent(instanceConfig);
|
||||
return applicationInfoManager.getInfo();
|
||||
}
|
||||
|
||||
protected InstanceInfo instance() {
|
||||
return applicationInfoManager.getInfo();
|
||||
}
|
||||
|
||||
private RestDocumentationFilter filter(String name) {
|
||||
return RestAssuredRestDocumentation.document(name,
|
||||
preprocessRequest(modifyUris().host("eureka.example.com").removePort(), prettyPrint()),
|
||||
preprocessResponse(prettyPrint()));
|
||||
}
|
||||
|
||||
private RequestSpecification spec(Filter... filters) {
|
||||
return spec(null, filters);
|
||||
}
|
||||
|
||||
private RequestSpecification spec(Object body, Filter... filters) {
|
||||
RequestSpecBuilder builder = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation));
|
||||
for (Filter filter : filters) {
|
||||
builder = builder.addFilter(filter);
|
||||
}
|
||||
RequestSpecification spec = builder.setPort(this.port).build();
|
||||
if (body != null) {
|
||||
spec.contentType("application/json").body(body, new EurekaObjectMapper());
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
protected RequestSpecification document() {
|
||||
return document("{method-name}");
|
||||
}
|
||||
|
||||
protected RequestSpecification document(Object body) {
|
||||
RestDocumentationFilter filter = filter("{method-name}");
|
||||
RequestSpecification assured = RestAssured.given(spec(body, filter));
|
||||
return assured.filter(filter);
|
||||
}
|
||||
|
||||
protected RequestSpecification document(String name, Object body) {
|
||||
RestDocumentationFilter filter = filter(name);
|
||||
RequestSpecification assured = RestAssured.given(spec(body, filter));
|
||||
return assured.filter(filter);
|
||||
}
|
||||
|
||||
protected RequestSpecification document(String name) {
|
||||
RestDocumentationFilter filter = filter(name);
|
||||
return RestAssured.given(spec(filter)).filter(filter);
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableAutoConfiguration
|
||||
@EnableEurekaServer
|
||||
protected static class Application {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DefaultEurekaServerContext.class);
|
||||
|
||||
@Bean
|
||||
public EurekaServerContext testEurekaServerContext(ServerCodecs serverCodecs,
|
||||
PeerAwareInstanceRegistry registry, PeerEurekaNodes peerEurekaNodes,
|
||||
ApplicationInfoManager applicationInfoManager, EurekaServerConfig eurekaServerConfig) {
|
||||
return new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs, registry, peerEurekaNodes,
|
||||
applicationInfoManager) {
|
||||
@Override
|
||||
public void shutdown() {
|
||||
logger.info("Shutting down (except ServoControl and EurekaMonitors)..");
|
||||
registry.shutdown();
|
||||
peerEurekaNodes.shutdown();
|
||||
// ServoControl.shutdown();
|
||||
// EurekaMonitors.shutdown();
|
||||
logger.info("Shut down");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-130
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-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.server.doc;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.put;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.emptyIterable;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.springframework.cloud.netflix.eureka.server.doc.RequestVerifierFilter.verify;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class AppRegistrationTests extends AbstractDocumentationTests {
|
||||
|
||||
@Test
|
||||
public void startingApp() throws Exception {
|
||||
register("foo");
|
||||
document().accept("application/json").when().get("/eureka/apps").then().assertThat()
|
||||
.body("applications.application", hasSize(1), "applications.application[0].instance[0].status",
|
||||
equalTo("STARTING"))
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addInstance() throws Exception {
|
||||
document(instance("foo"))
|
||||
.filter(verify("$.instance.app").json("$.instance.hostName").json("$.instance[?(@.status=='STARTING')]")
|
||||
.json("$.instance.instanceId").json("$.instance.dataCenterInfo.name"))
|
||||
.when().post("/eureka/apps/FOO").then().assertThat().statusCode(is(204));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setStatus() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document()
|
||||
.filter(verify(
|
||||
put(urlPathMatching("/eureka/apps/FOO/.*/status")).withQueryParam("value", matching("UP"))))
|
||||
.when().put("/eureka/apps/FOO/{id}/status?value={value}", id, "UP").then().assertThat()
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allApps() throws Exception {
|
||||
register("foo");
|
||||
document().accept("application/json").when().get("/eureka/apps").then().assertThat()
|
||||
.body("applications.application", hasSize(1)).statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delta() throws Exception {
|
||||
register("foo");
|
||||
document().accept("application/json").when().get("/eureka/apps/delta").then().assertThat()
|
||||
.body("applications.application", hasSize(1)).statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneInstance() throws Exception {
|
||||
String id = UUID.randomUUID().toString();
|
||||
register("foo", id);
|
||||
document().filter(verify(get(urlPathMatching("/eureka/apps/FOO/.*")))).accept("application/json").when()
|
||||
.get("/eureka/apps/FOO/{id}", id).then().assertThat().body("instance.app", equalTo("FOO"))
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupInstance() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document().filter(verify(get(urlPathMatching("/eureka/instances/.*")))).accept("application/json").when()
|
||||
.get("/eureka/instances/{id}", id).then().assertThat().body("instance.app", equalTo("FOO"))
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renew() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document().filter(verify(put(urlPathMatching("/eureka/apps/FOO/.*")))).accept("application/json").when()
|
||||
.put("/eureka/apps/FOO/{id}", id).then().assertThat().statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateMetadata() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document()
|
||||
.filter(verify(
|
||||
put(urlPathMatching("/eureka/apps/FOO/.*/metadata")).withQueryParam("key", matching(".*"))))
|
||||
.accept("application/json").when().put("/eureka/apps/FOO/{id}/metadata?key=value", id).then()
|
||||
.assertThat().statusCode(is(200));
|
||||
assertThat(instance().getMetadata()).containsEntry("key", "value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteInstance() throws Exception {
|
||||
String id = register("foo").getInstanceId();
|
||||
document().filter(verify(delete(urlPathMatching("/eureka/apps/FOO/.*")))).when()
|
||||
.delete("/eureka/apps/FOO/{id}", id).then().assertThat().statusCode(is(200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyApps() {
|
||||
document().when().accept("application/json").get("/eureka/apps").then().assertThat()
|
||||
.body("applications.application", emptyIterable()).statusCode(is(200));
|
||||
}
|
||||
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-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.server.doc;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import com.netflix.discovery.converters.EntityBodyConverter;
|
||||
import io.restassured.mapper.ObjectMapperDeserializationContext;
|
||||
import io.restassured.mapper.ObjectMapperSerializationContext;
|
||||
|
||||
final class EurekaObjectMapper implements io.restassured.mapper.ObjectMapper {
|
||||
|
||||
private EntityBodyConverter converter = new EntityBodyConverter();
|
||||
|
||||
@Override
|
||||
public Object serialize(ObjectMapperSerializationContext context) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try {
|
||||
converter.write(context.getObjectToSerialize(), out, MediaType.APPLICATION_JSON_TYPE);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("Cannot serialize", e);
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(ObjectMapperDeserializationContext context) {
|
||||
try {
|
||||
return converter.read(context.getDataToDeserialize().asInputStream(), (Class) context.getType(),
|
||||
MediaType.APPLICATION_JSON_TYPE);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("Cannot deserialize", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-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.server.doc;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
// TODO: maybe this should be the default (the test fails without it because the JSON is
|
||||
// invalid)
|
||||
@TestPropertySource(
|
||||
properties = { "eureka.server.minAvailableInstancesForPeerReplication=0", "spring.jmx.enabled=false" })
|
||||
public class EurekaServerTests extends AbstractDocumentationTests {
|
||||
|
||||
@Test
|
||||
public void serverStatus() throws Exception {
|
||||
register("foo", UUID.randomUUID().toString());
|
||||
document()
|
||||
.accept("application/json").when().get("/eureka/status").then().assertThat().body("generalStats",
|
||||
notNullValue(), "applicationStats", notNullValue(), "instanceInfo", notNullValue())
|
||||
.statusCode(is(200));
|
||||
}
|
||||
|
||||
}
|
||||
-359
@@ -1,359 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-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.server.doc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.github.tomakehurst.wiremock.client.MappingBuilder;
|
||||
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
|
||||
import com.github.tomakehurst.wiremock.http.ContentTypeHeader;
|
||||
import com.github.tomakehurst.wiremock.http.Cookie;
|
||||
import com.github.tomakehurst.wiremock.http.HttpHeader;
|
||||
import com.github.tomakehurst.wiremock.http.HttpHeaders;
|
||||
import com.github.tomakehurst.wiremock.http.QueryParameter;
|
||||
import com.github.tomakehurst.wiremock.http.Request;
|
||||
import com.github.tomakehurst.wiremock.http.RequestMethod;
|
||||
import com.github.tomakehurst.wiremock.matching.MatchResult;
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import io.restassured.filter.Filter;
|
||||
import io.restassured.filter.FilterContext;
|
||||
import io.restassured.http.Header;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.FilterableRequestSpecification;
|
||||
import io.restassured.specification.FilterableResponseSpecification;
|
||||
import wiremock.com.google.common.base.Optional;
|
||||
|
||||
import org.springframework.util.Base64Utils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
|
||||
public class RequestVerifierFilter implements Filter {
|
||||
|
||||
static final String CONTEXT_KEY_CONFIGURATION = "org.springframework.restdocs.configuration";
|
||||
|
||||
private Map<String, JsonPath> jsonPaths = new LinkedHashMap<>();
|
||||
|
||||
private MappingBuilder builder;
|
||||
|
||||
public static RequestVerifierFilter verify(String path) {
|
||||
return new RequestVerifierFilter(path);
|
||||
}
|
||||
|
||||
public static RequestVerifierFilter verify(MappingBuilder builder) {
|
||||
return new RequestVerifierFilter().wiremock(builder);
|
||||
}
|
||||
|
||||
private RequestVerifierFilter(String expression, Object... args) {
|
||||
expression = String.format(expression, args);
|
||||
this.jsonPaths.put(expression, JsonPath.compile(expression));
|
||||
}
|
||||
|
||||
private RequestVerifierFilter() {
|
||||
}
|
||||
|
||||
public RequestVerifierFilter json(String expression, Object... args) {
|
||||
expression = String.format(expression, args);
|
||||
this.jsonPaths.put(expression, JsonPath.compile(expression));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RequestVerifierFilter wiremock(MappingBuilder builder) {
|
||||
this.builder = builder;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec,
|
||||
FilterContext context) {
|
||||
Map<String, Object> configuration = getConfiguration(requestSpec, context);
|
||||
configuration.put("contract.jsonPaths", this.jsonPaths.keySet());
|
||||
Response response = context.next(requestSpec, responseSpec);
|
||||
if (requestSpec.getBody() != null && !this.jsonPaths.isEmpty()) {
|
||||
String actual = new String((byte[]) requestSpec.getBody());
|
||||
for (JsonPath jsonPath : this.jsonPaths.values()) {
|
||||
new JsonPathValue(jsonPath, actual).assertHasValue(Object.class, "an object");
|
||||
}
|
||||
}
|
||||
if (this.builder != null) {
|
||||
this.builder.willReturn(getResponseDefinition(response));
|
||||
StubMapping stubMapping = this.builder.build();
|
||||
MatchResult match = stubMapping.getRequest().match(new WireMockRestAssuredRequestAdapter(requestSpec));
|
||||
assertThat(match.isExactMatch()).as("wiremock did not match request").isTrue();
|
||||
configuration.put("contract.stubMapping", stubMapping);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private ResponseDefinitionBuilder getResponseDefinition(Response response) {
|
||||
ResponseDefinitionBuilder definition = ResponseDefinitionBuilder.responseDefinition()
|
||||
.withBody(response.getBody().asString()).withStatus(response.getStatusCode());
|
||||
addResponseHeaders(definition, response);
|
||||
return definition;
|
||||
}
|
||||
|
||||
private void addResponseHeaders(ResponseDefinitionBuilder definition, Response input) {
|
||||
for (Header header : input.getHeaders().asList()) {
|
||||
String name = header.getName();
|
||||
definition.withHeader(name, input.getHeader(name));
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, Object> getConfiguration(FilterableRequestSpecification requestSpec, FilterContext context) {
|
||||
Map<String, Object> configuration = context.<Map<String, Object>>getValue(CONTEXT_KEY_CONFIGURATION);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class JsonPathValue {
|
||||
|
||||
private final JsonPath jsonPath;
|
||||
|
||||
private final String expression;
|
||||
|
||||
private final CharSequence actual;
|
||||
|
||||
JsonPathValue(JsonPath jsonPath, CharSequence actual) {
|
||||
this.jsonPath = jsonPath;
|
||||
this.actual = actual;
|
||||
this.expression = jsonPath.getPath();
|
||||
}
|
||||
|
||||
public void assertHasValue(Class<?> type, String expectedDescription) {
|
||||
Object value = getValue(true);
|
||||
if (value == null || isIndefiniteAndEmpty()) {
|
||||
throw new AssertionError(getNoValueMessage());
|
||||
}
|
||||
if (type != null && !type.isInstance(value)) {
|
||||
throw new AssertionError(getExpectedValueMessage(expectedDescription));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isIndefiniteAndEmpty() {
|
||||
return !isDefinite() && isEmpty();
|
||||
}
|
||||
|
||||
private boolean isDefinite() {
|
||||
return this.jsonPath.isDefinite();
|
||||
}
|
||||
|
||||
private boolean isEmpty() {
|
||||
return ObjectUtils.isEmpty(getValue(false));
|
||||
}
|
||||
|
||||
public Object getValue(boolean required) {
|
||||
try {
|
||||
CharSequence json = this.actual;
|
||||
return this.jsonPath.read(json == null ? null : json.toString());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (!required) {
|
||||
return null;
|
||||
}
|
||||
throw new AssertionError(getNoValueMessage() + ". " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getNoValueMessage() {
|
||||
return "No value at JSON path \"" + this.expression + "\"";
|
||||
}
|
||||
|
||||
private String getExpectedValueMessage(String expectedDescription) {
|
||||
return String.format("Expected %s at JSON path \"%s\" but found: %s", expectedDescription, this.expression,
|
||||
ObjectUtils.nullSafeToString(StringUtils.quoteIfString(getValue(false))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WireMockRestAssuredRequestAdapter implements Request {
|
||||
|
||||
private FilterableRequestSpecification request;
|
||||
|
||||
WireMockRestAssuredRequestAdapter(FilterableRequestSpecification request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Request> getOriginalRequest() {
|
||||
return Optional.of(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return UriComponentsBuilder.fromUriString(request.getURI()).build().getScheme();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return UriComponentsBuilder.fromUriString(request.getURI()).build().getHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return request.getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return request.getDerivedPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAbsoluteUrl() {
|
||||
return request.getURI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestMethod getMethod() {
|
||||
return RequestMethod.fromString(request.getMethod());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientIp() {
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader(String key) {
|
||||
String value = request.getHeaders().getValue(key);
|
||||
if ("accept".equals(key.toLowerCase()) && "*/*".equals(value)) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeader header(String key) {
|
||||
String value = request.getHeaders().getValue(key);
|
||||
if ("accept".equals(key.toLowerCase()) && "*/*".equals(value)) {
|
||||
return null;
|
||||
}
|
||||
return new HttpHeader(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentTypeHeader contentTypeHeader() {
|
||||
return new ContentTypeHeader(request.getContentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
List<HttpHeader> headers = new ArrayList<>();
|
||||
for (Header header : request.getHeaders()) {
|
||||
String value = header.getValue();
|
||||
if ("accept".equals(header.getName().toLowerCase()) && "*/*".equals(value)) {
|
||||
continue;
|
||||
}
|
||||
headers.add(new HttpHeader(header.getName(), header.getValue()));
|
||||
}
|
||||
return new HttpHeaders(headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsHeader(String key) {
|
||||
String value = request.getHeaders().getValue(key);
|
||||
if ("accept".equals(key.toLowerCase()) && "*/*".equals(value)) {
|
||||
return false;
|
||||
}
|
||||
return request.getHeaders().hasHeaderWithName(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAllHeaderKeys() {
|
||||
Set<String> headers = new LinkedHashSet<>();
|
||||
for (Header header : request.getHeaders()) {
|
||||
String value = header.getValue();
|
||||
if ("accept".equals(header.getName().toLowerCase()) && "*/*".equals(value)) {
|
||||
continue;
|
||||
}
|
||||
headers.add(header.getName());
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Cookie> getCookies() {
|
||||
Map<String, Cookie> map = new LinkedHashMap<>();
|
||||
for (io.restassured.http.Cookie cookie : request.getCookies()) {
|
||||
Cookie value = new Cookie(cookie.getValue());
|
||||
map.put(cookie.getName(), value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryParameter queryParameter(String key) {
|
||||
Map<String, String> params = request.getQueryParams();
|
||||
if (params.containsKey(key)) {
|
||||
return new QueryParameter(key, Arrays.asList(params.get(key)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBody() {
|
||||
return request.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBodyAsString() {
|
||||
return new String(getBody());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBodyAsBase64() {
|
||||
return Base64Utils.encodeToString(getBody());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBrowserProxyRequest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultipart() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Part> getParts() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Part getPart(String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix</artifactId>
|
||||
<version>3.0.0-RC1</version>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
<name>Spring Cloud Starter Netflix Eureka Client</name>
|
||||
@@ -63,9 +63,5 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix</artifactId>
|
||||
<version>3.0.0-RC1</version>
|
||||
<version>3.0.6</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
|
||||
<name>Spring Cloud Starter Netflix Eureka Server</name>
|
||||
|
||||
@@ -3,44 +3,12 @@
|
||||
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||
"https://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||
<suppressions>
|
||||
<suppress files=".*OkHttpRibbonResponse\.java" checks="IllegalImportCheck"/>
|
||||
<suppress files=".*RibbonApacheHttpResponse\.java" checks="IllegalImportCheck"/>
|
||||
<suppress files=".*TurbineApplication\.java" checks="HideUtilityClassConstructorCheck"/>
|
||||
<suppress files=".*SpringAggregatorFactory\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*HystrixDashboardConfiguration\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*EurekaHealthCheckHandler\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*RestClientRibbonCommand\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*AbstractRibbonCommand\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*ContextPathZuulProxyApplicationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*RetryableRibbonLoadBalancingHttpClient\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*CustomHostRoutingFilterTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*HystrixDashboardConfigurationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*ServletPathZuulProxyApplicationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*TurbineStreamTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*InstanceRegistryTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*RibbonClientConfigurationIntegrationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*HystrixStreamEndpointTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*EurekaCustomPeerNodesTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*EurekaHealthCheckTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*HttpClientRibbonCommandIntegrationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*HttpClientRibbonRetryIntegrationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*HystrixStreamEndpointTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*OkHttpRibbonCommandFallbackTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*OkHttpRibbonCommandIntegrationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*OkHttpRibbonRetryIntegrationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*RefreshablePeerEurekaNodesTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*RestClientRibbonCommandFallbackTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*RestClientRibbonCommandIntegrationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*RibbonRoutingFilterLoadBalancerKeyIntegrationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*SimpleZuulProxyApplicationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*TurbineHttpTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*ZuulProxyApplicationTests\.java" checks="LineLengthCheck"/>
|
||||
<suppress files=".*PatternServiceRouteMapper\.java" checks="JavadocTagContinuationIndentationCheck"/>
|
||||
<suppress files=".*PatternServiceRouteMapper\.java" checks="AtclauseOrder"/>
|
||||
<suppress files=".*PatternServiceRouteMapper\.java" checks="NonEmptyAtclauseDescription"/>
|
||||
<suppress files=".*EurekaRegistration\.java" checks="FinalClass"/>
|
||||
<suppress files=".*RequestVerifierFilter\.java" checks="FinalClass"/>
|
||||
<suppress files=".*RibbonClientHttpRequestFactoryTests\.java" checks="JavadocVariable"/>
|
||||
<suppress files=".*TestAutoConfiguration\.java" checks="HideUtilityClassConstructor"/>
|
||||
<suppress files=".*TestAutoConfiguration\.java" checks="JavadocStyle"/>
|
||||
<suppress files=".*TestAutoConfiguration\.java" checks="JavadocStyle"/>
|
||||
|
||||
Reference in New Issue
Block a user