Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
2cfcd269
Commit
2cfcd269
authored
Apr 18, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Allow to configure the Elasticsearch rest client timeouts"
Closes gh-15965
parent
5bacb325
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
15 deletions
+17
-15
RestClientAutoConfigurationTests.java
.../elasticsearch/rest/RestClientAutoConfigurationTests.java
+16
-15
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+1
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java
View file @
2cfcd269
...
...
@@ -78,29 +78,39 @@ public class RestClientAutoConfigurationTests {
}
@Test
public
void
defaultTimeoutsShouldBeConfigured
()
{
public
void
configureWithNoTimeoutsApplyDefaults
()
{
this
.
contextRunner
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
);
RestClient
restClient
=
context
.
getBean
(
RestClient
.
class
);
assertTimeouts
(
restClient
,
Duration
.
ofMillis
(
RestClientBuilder
.
DEFAULT_CONNECT_TIMEOUT_MILLIS
),
Duration
.
ofMillis
(
RestClientBuilder
.
DEFAULT_SOCKET_TIMEOUT_MILLIS
)
);
Duration
.
ofMillis
(
RestClientBuilder
.
DEFAULT_CONNECT_TIMEOUT_MILLIS
),
Duration
.
ofMillis
(
RestClientBuilder
.
DEFAULT_SOCKET_TIMEOUT_MILLIS
)
);
});
}
@Test
public
void
timeoutsCanBeConfigured
()
{
public
void
configureWithCustomTimeouts
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.elasticsearch.rest.connection-timeout=15s"
,
"spring.elasticsearch.rest.read-timeout=1m"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
RestClient
.
class
);
RestClient
restClient
=
context
.
getBean
(
RestClient
.
class
);
assertTimeouts
(
restClient
,
Duration
.
ofSeconds
(
15
),
Duration
.
ofMinutes
(
1
)
);
assertTimeouts
(
restClient
,
Duration
.
ofSeconds
(
15
),
Duration
.
ofMinutes
(
1
)
);
});
}
private
static
void
assertTimeouts
(
RestClient
restClient
,
Duration
connectTimeout
,
Duration
readTimeout
)
{
Object
client
=
ReflectionTestUtils
.
getField
(
restClient
,
"client"
);
Object
config
=
ReflectionTestUtils
.
getField
(
client
,
"defaultConfig"
);
assertThat
(
config
).
hasFieldOrPropertyWithValue
(
"socketTimeout"
,
Math
.
toIntExact
(
readTimeout
.
toMillis
()));
assertThat
(
config
).
hasFieldOrPropertyWithValue
(
"connectTimeout"
,
Math
.
toIntExact
(
connectTimeout
.
toMillis
()));
}
@Test
public
void
restClientCanQueryElasticsearchNode
()
{
this
.
contextRunner
...
...
@@ -121,15 +131,6 @@ public class RestClientAutoConfigurationTests {
});
}
private
static
void
assertTimeouts
(
RestClient
restClient
,
Duration
connectTimeout
,
Duration
readTimeout
)
{
Object
client
=
ReflectionTestUtils
.
getField
(
restClient
,
"client"
);
Object
config
=
ReflectionTestUtils
.
getField
(
client
,
"defaultConfig"
);
assertThat
(
config
).
hasFieldOrPropertyWithValue
(
"socketTimeout"
,
Math
.
toIntExact
(
readTimeout
.
toMillis
()));
assertThat
(
config
).
hasFieldOrPropertyWithValue
(
"connectTimeout"
,
Math
.
toIntExact
(
connectTimeout
.
toMillis
()));
}
@Configuration
(
proxyBeanMethods
=
false
)
static
class
CustomRestClientConfiguration
{
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
2cfcd269
...
...
@@ -4805,6 +4805,7 @@ You can further tune how `RestClient` is configured, as shown in the following e
[source,properties,indent=0]
----
spring.elasticsearch.rest.uris=https://search.example.com:9200
spring.elasticsearch.rest.read-timeout=10s
spring.elasticsearch.rest.username=user
spring.elasticsearch.rest.password=secret
----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment