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
a4eb6369
Commit
a4eb6369
authored
Oct 15, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
2ae81fe4
6d98851f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
108 additions
and
238 deletions
+108
-238
CouchbaseHealthIndicatorAutoConfiguration.java
.../couchbase/CouchbaseHealthIndicatorAutoConfiguration.java
+14
-26
CouchbaseHealthIndicatorProperties.java
...nfigure/couchbase/CouchbaseHealthIndicatorProperties.java
+0
-46
CouchbaseReactiveHealthIndicatorAutoConfiguration.java
...se/CouchbaseReactiveHealthIndicatorAutoConfiguration.java
+2
-9
CouchbaseHealthIndicatorAutoConfigurationTests.java
...hbase/CouchbaseHealthIndicatorAutoConfigurationTests.java
+3
-15
CouchbaseReactiveHealthIndicatorAutoConfigurationTests.java
...uchbaseReactiveHealthIndicatorAutoConfigurationTests.java
+0
-14
CouchbaseHealthIndicator.java
...work/boot/actuate/couchbase/CouchbaseHealthIndicator.java
+41
-35
CouchbaseReactiveHealthIndicator.java
...t/actuate/couchbase/CouchbaseReactiveHealthIndicator.java
+3
-11
CouchbaseHealthIndicatorTests.java
...boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java
+43
-57
CouchbaseReactiveHealthIndicatorTests.java
...uate/couchbase/CouchbaseReactiveHealthIndicatorTests.java
+2
-24
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+0
-1
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java
View file @
a4eb6369
...
...
@@ -17,7 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.couchbase;
import
java.util.Map
;
import
com.couchbase.client.java.
Bucket
;
import
com.couchbase.client.java.
Cluster
;
import
org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator
;
...
...
@@ -31,11 +31,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration
;
import
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.couchbase.core.CouchbaseOperations
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for
...
...
@@ -43,42 +40,33 @@ import org.springframework.data.couchbase.core.CouchbaseOperations;
*
* @author Eddú Meléndez
* @author Stephane Nicoll
* @since 2.1.0
* @author Andy Wilkinson Nicoll
* @since 2.0.0
*/
@Configuration
@ConditionalOnClass
(
{
Bucket
.
class
,
CouchbaseOperations
.
class
}
)
@ConditionalOnBean
(
C
ouchbaseOperations
.
class
)
@ConditionalOnClass
(
Cluster
.
class
)
@ConditionalOnBean
(
C
luster
.
class
)
@ConditionalOnEnabledHealthIndicator
(
"couchbase"
)
@AutoConfigureBefore
(
HealthIndicatorAutoConfiguration
.
class
)
@AutoConfigureAfter
({
CouchbaseAutoConfiguration
.
class
,
CouchbaseDataAutoConfiguration
.
class
,
CouchbaseReactiveHealthIndicatorAutoConfiguration
.
class
})
@EnableConfigurationProperties
(
CouchbaseHealthIndicatorProperties
.
class
)
public
class
CouchbaseHealthIndicatorAutoConfiguration
extends
CompositeHealthIndicatorConfiguration
<
CouchbaseHealthIndicator
,
CouchbaseOperations
>
{
@AutoConfigureAfter
(
CouchbaseAutoConfiguration
.
class
)
public
class
CouchbaseHealthIndicatorAutoConfiguration
extends
CompositeHealthIndicatorConfiguration
<
CouchbaseHealthIndicator
,
Cluster
>
{
private
final
Map
<
String
,
C
ouchbaseOperations
>
couchbaseOperation
s
;
private
final
Map
<
String
,
C
luster
>
cluster
s
;
private
final
CouchbaseHealthIndicatorProperties
properties
;
public
CouchbaseHealthIndicatorAutoConfiguration
(
Map
<
String
,
CouchbaseOperations
>
couchbaseOperations
,
CouchbaseHealthIndicatorProperties
properties
)
{
this
.
couchbaseOperations
=
couchbaseOperations
;
this
.
properties
=
properties
;
public
CouchbaseHealthIndicatorAutoConfiguration
(
Map
<
String
,
Cluster
>
clusters
)
{
this
.
clusters
=
clusters
;
}
@Bean
@ConditionalOnMissingBean
(
name
=
"couchbaseHealthIndicator"
)
public
HealthIndicator
couchbaseHealthIndicator
()
{
return
createHealthIndicator
(
this
.
c
ouchbaseOperation
s
);
return
createHealthIndicator
(
this
.
c
luster
s
);
}
@Override
protected
CouchbaseHealthIndicator
createHealthIndicator
(
CouchbaseOperations
couchbaseOperations
)
{
return
new
CouchbaseHealthIndicator
(
couchbaseOperations
,
this
.
properties
.
getTimeout
());
protected
CouchbaseHealthIndicator
createHealthIndicator
(
Cluster
cluster
)
{
return
new
CouchbaseHealthIndicator
(
cluster
);
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorProperties.java
deleted
100644 → 0
View file @
2ae81fe4
/*
* Copyright 2012-2018 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
*
* http://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
.
boot
.
actuate
.
autoconfigure
.
couchbase
;
import
java.time.Duration
;
import
org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Configuration properties for {@link CouchbaseHealthIndicator}.
*
* @author Stephane Nicoll
* @since 2.0.5
*/
@ConfigurationProperties
(
prefix
=
"management.health.couchbase"
)
public
class
CouchbaseHealthIndicatorProperties
{
/**
* Timeout for getting the Bucket information from the server.
*/
private
Duration
timeout
=
Duration
.
ofMillis
(
1000
);
public
Duration
getTimeout
()
{
return
this
.
timeout
;
}
public
void
setTimeout
(
Duration
timeout
)
{
this
.
timeout
=
timeout
;
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java
View file @
a4eb6369
...
...
@@ -32,7 +32,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.couchbase.core.RxJavaCouchbaseOperations
;
...
...
@@ -51,19 +50,14 @@ import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations;
@ConditionalOnEnabledHealthIndicator
(
"couchbase"
)
@AutoConfigureBefore
(
HealthIndicatorAutoConfiguration
.
class
)
@AutoConfigureAfter
(
CouchbaseReactiveDataAutoConfiguration
.
class
)
@EnableConfigurationProperties
(
CouchbaseHealthIndicatorProperties
.
class
)
public
class
CouchbaseReactiveHealthIndicatorAutoConfiguration
extends
CompositeReactiveHealthIndicatorConfiguration
<
CouchbaseReactiveHealthIndicator
,
RxJavaCouchbaseOperations
>
{
private
final
Map
<
String
,
RxJavaCouchbaseOperations
>
couchbaseOperations
;
private
final
CouchbaseHealthIndicatorProperties
properties
;
public
CouchbaseReactiveHealthIndicatorAutoConfiguration
(
Map
<
String
,
RxJavaCouchbaseOperations
>
couchbaseOperations
,
CouchbaseHealthIndicatorProperties
properties
)
{
Map
<
String
,
RxJavaCouchbaseOperations
>
couchbaseOperations
)
{
this
.
couchbaseOperations
=
couchbaseOperations
;
this
.
properties
=
properties
;
}
@Bean
...
...
@@ -75,8 +69,7 @@ public class CouchbaseReactiveHealthIndicatorAutoConfiguration extends
@Override
protected
CouchbaseReactiveHealthIndicator
createHealthIndicator
(
RxJavaCouchbaseOperations
couchbaseOperations
)
{
return
new
CouchbaseReactiveHealthIndicator
(
couchbaseOperations
,
this
.
properties
.
getTimeout
());
return
new
CouchbaseReactiveHealthIndicator
(
couchbaseOperations
);
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfigurationTests.java
View file @
a4eb6369
...
...
@@ -15,6 +15,7 @@
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
couchbase
;
import
com.couchbase.client.java.Cluster
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration
;
...
...
@@ -25,8 +26,6 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.couchbase.core.CouchbaseOperations
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -52,17 +51,6 @@ public class CouchbaseHealthIndicatorAutoConfigurationTests {
.
doesNotHaveBean
(
ApplicationHealthIndicator
.
class
));
}
@Test
public
void
runWithCustomTimeoutShouldCreateIndicator
()
{
this
.
contextRunner
.
withPropertyValues
(
"management.health.couchbase.timeout=2s"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
CouchbaseHealthIndicator
.
class
);
assertThat
(
ReflectionTestUtils
.
getField
(
context
.
getBean
(
CouchbaseHealthIndicator
.
class
),
"timeout"
))
.
isEqualTo
(
2000L
);
});
}
@Test
public
void
runWhenDisabledShouldNotCreateIndicator
()
{
this
.
contextRunner
.
withPropertyValues
(
"management.health.couchbase.enabled:false"
)
...
...
@@ -75,8 +63,8 @@ public class CouchbaseHealthIndicatorAutoConfigurationTests {
protected
static
class
CouchbaseMockConfiguration
{
@Bean
public
C
ouchbaseOperations
couchbaseOperations
()
{
return
mock
(
C
ouchbaseOperations
.
class
);
public
C
luster
cluster
()
{
return
mock
(
C
luster
.
class
);
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfigurationTests.java
View file @
a4eb6369
...
...
@@ -15,8 +15,6 @@
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
couchbase
;
import
java.time.Duration
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration
;
...
...
@@ -53,18 +51,6 @@ public class CouchbaseReactiveHealthIndicatorAutoConfigurationTests {
.
doesNotHaveBean
(
ApplicationHealthIndicator
.
class
));
}
@Test
public
void
runWithCustomTimeoutShouldCreateIndicator
()
{
this
.
contextRunner
.
withPropertyValues
(
"management.health.couchbase.timeout=2s"
)
.
run
((
context
)
->
{
assertThat
(
context
)
.
hasSingleBean
(
CouchbaseReactiveHealthIndicator
.
class
);
assertThat
(
context
.
getBean
(
CouchbaseReactiveHealthIndicator
.
class
))
.
hasFieldOrPropertyWithValue
(
"timeout"
,
Duration
.
ofSeconds
(
2
));
});
}
@Test
public
void
runWhenDisabledShouldNotCreateIndicator
()
{
this
.
contextRunner
.
withPropertyValues
(
"management.health.couchbase.enabled:false"
)
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicator.java
View file @
a4eb6369
...
...
@@ -16,19 +16,19 @@
package
org
.
springframework
.
boot
.
actuate
.
couchbase
;
import
java.
time.Duration
;
import
java.util.
concurrent.TimeUnit
;
import
java.util.
concurrent.TimeoutException
;
import
java.
util.HashMap
;
import
java.util.
Map
;
import
java.util.
stream.Collectors
;
import
com.couchbase.client.java.bucket.BucketInfo
;
import
com.couchbase.client.java.cluster.ClusterInfo
;
import
com.couchbase.client.core.message.internal.DiagnosticsReport
;
import
com.couchbase.client.core.message.internal.EndpointHealth
;
import
com.couchbase.client.core.state.LifecycleState
;
import
com.couchbase.client.java.Cluster
;
import
org.springframework.boot.actuate.health.AbstractHealthIndicator
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.data.couchbase.core.CouchbaseOperations
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
/**
* {@link HealthIndicator} for Couchbase.
...
...
@@ -39,46 +39,52 @@ import org.springframework.util.StringUtils;
*/
public
class
CouchbaseHealthIndicator
extends
AbstractHealthIndicator
{
private
final
CouchbaseOperations
operations
;
private
final
long
timeout
;
private
final
Cluster
cluster
;
/**
* Create an indicator with the specified {@link CouchbaseOperations} and
* {@code timeout}.
* @param couchbaseOperations the couchbase operations
* @param timeout the request timeout
* Create an indicator with the specified {@link Cluster}.
* @param cluster the Couchbase Cluster
* @since 2.0.6
*/
public
CouchbaseHealthIndicator
(
CouchbaseOperations
couchbaseOperations
,
Duration
timeout
)
{
public
CouchbaseHealthIndicator
(
Cluster
cluster
)
{
super
(
"Couchbase health check failed"
);
Assert
.
notNull
(
couchbaseOperations
,
"CouchbaseOperations must not be null"
);
Assert
.
notNull
(
timeout
,
"Timeout must not be null"
);
this
.
operations
=
couchbaseOperations
;
this
.
timeout
=
timeout
.
toMillis
();
Assert
.
notNull
(
cluster
,
"Cluster must not be null"
);
this
.
cluster
=
cluster
;
}
@Override
protected
void
doHealthCheck
(
Health
.
Builder
builder
)
throws
Exception
{
ClusterInfo
cluster
=
this
.
operations
.
getCouchbaseClusterInfo
();
BucketInfo
bucket
=
getBucketInfo
();
String
versions
=
StringUtils
.
collectionToCommaDelimitedString
(
cluster
.
getAllVersions
());
String
nodes
=
StringUtils
.
collectionToCommaDelimitedString
(
bucket
.
nodeList
());
builder
.
up
().
withDetail
(
"versions"
,
versions
).
withDetail
(
"nodes"
,
nodes
);
DiagnosticsReport
diagnostics
=
this
.
cluster
.
diagnostics
();
if
(
isCouchbaseUp
(
diagnostics
))
{
builder
.
up
();
}
else
{
builder
.
down
();
}
builder
.
withDetail
(
"sdk"
,
diagnostics
.
sdk
());
builder
.
withDetail
(
"endpoints"
,
diagnostics
.
endpoints
().
stream
()
.
map
(
this
::
describe
).
collect
(
Collectors
.
toList
()));
}
private
BucketInfo
getBucketInfo
()
throws
Exception
{
try
{
return
this
.
operations
.
getCouchbaseBucket
().
bucketManager
().
info
(
this
.
timeout
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
RuntimeException
ex
)
{
if
(
ex
.
getCause
()
instanceof
TimeoutException
)
{
throw
(
TimeoutException
)
ex
.
getCause
();
private
boolean
isCouchbaseUp
(
DiagnosticsReport
diagnostics
)
{
for
(
EndpointHealth
health
:
diagnostics
.
endpoints
())
{
LifecycleState
state
=
health
.
state
();
if
(
state
!=
LifecycleState
.
CONNECTED
&&
state
!=
LifecycleState
.
IDLE
)
{
return
false
;
}
throw
ex
;
}
return
true
;
}
private
Map
<
String
,
Object
>
describe
(
EndpointHealth
endpointHealth
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
endpointHealth
.
id
());
map
.
put
(
"lastActivity"
,
endpointHealth
.
lastActivity
());
map
.
put
(
"local"
,
endpointHealth
.
local
().
toString
());
map
.
put
(
"remote"
,
endpointHealth
.
remote
().
toString
());
map
.
put
(
"state"
,
endpointHealth
.
state
());
map
.
put
(
"type"
,
endpointHealth
.
type
());
return
map
;
}
}
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java
View file @
a4eb6369
...
...
@@ -15,9 +15,6 @@
*/
package
org
.
springframework
.
boot
.
actuate
.
couchbase
;
import
java.time.Duration
;
import
java.util.concurrent.TimeUnit
;
import
com.couchbase.client.java.bucket.BucketInfo
;
import
com.couchbase.client.java.cluster.ClusterInfo
;
import
reactor.core.publisher.Mono
;
...
...
@@ -42,17 +39,13 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi
private
final
RxJavaCouchbaseOperations
couchbaseOperations
;
private
final
Duration
timeout
;
/**
* Create a new {@link CouchbaseReactiveHealthIndicator} instance.
* @param couchbaseOperations the reactive couchbase operations
* @param timeout the request timeout
*/
public
CouchbaseReactiveHealthIndicator
(
RxJavaCouchbaseOperations
couchbaseOperations
,
Duration
timeout
)
{
public
CouchbaseReactiveHealthIndicator
(
RxJavaCouchbaseOperations
couchbaseOperations
)
{
this
.
couchbaseOperations
=
couchbaseOperations
;
this
.
timeout
=
timeout
;
}
@Override
...
...
@@ -61,8 +54,7 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi
String
versions
=
StringUtils
.
collectionToCommaDelimitedString
(
cluster
.
getAllVersions
());
Observable
<
BucketInfo
>
bucket
=
this
.
couchbaseOperations
.
getCouchbaseBucket
()
.
bucketManager
().
async
().
info
()
.
timeout
(
this
.
timeout
.
toMillis
(),
TimeUnit
.
MILLISECONDS
);
.
bucketManager
().
async
().
info
();
Single
<
Health
>
health
=
bucket
.
map
(
BucketInfo:
:
nodeList
)
.
map
(
StringUtils:
:
collectionToCommaDelimitedString
)
.
map
((
nodes
)
->
builder
.
up
().
withDetail
(
"versions"
,
versions
)
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java
View file @
a4eb6369
...
...
@@ -16,26 +16,22 @@
package
org
.
springframework
.
boot
.
actuate
.
couchbase
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.time.Duration
;
import
java.util.Collections
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
java.net.InetSocketAddress
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
com.couchbase.client.
java.Bucke
t
;
import
com.couchbase.client.
java.bucket.BucketInfo
;
import
com.couchbase.client.
java.bucket.BucketManager
;
import
com.couchbase.client.
java.cluster.ClusterInfo
;
import
com.couchbase.client.java.
util.features.Version
;
import
com.couchbase.client.
core.message.internal.DiagnosticsRepor
t
;
import
com.couchbase.client.
core.message.internal.EndpointHealth
;
import
com.couchbase.client.
core.service.ServiceType
;
import
com.couchbase.client.
core.state.LifecycleState
;
import
com.couchbase.client.java.
Cluster
;
import
org.junit.Test
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.Status
;
import
org.springframework.data.couchbase.core.CouchbaseOperations
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
entry
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -49,57 +45,47 @@ import static org.mockito.Mockito.verify;
public
class
CouchbaseHealthIndicatorTests
{
@Test
public
void
couchbaseIsUp
()
throws
UnknownHostException
{
BucketInfo
bucketInfo
=
mock
(
BucketInfo
.
class
);
given
(
bucketInfo
.
nodeList
()).
willReturn
(
Collections
.
singletonList
(
InetAddress
.
getByName
(
"127.0.0.1"
)));
BucketManager
bucketManager
=
mock
(
BucketManager
.
class
);
given
(
bucketManager
.
info
(
2000
,
TimeUnit
.
MILLISECONDS
)).
willReturn
(
bucketInfo
);
Bucket
bucket
=
mock
(
Bucket
.
class
);
given
(
bucket
.
bucketManager
()).
willReturn
(
bucketManager
);
ClusterInfo
clusterInfo
=
mock
(
ClusterInfo
.
class
);
given
(
clusterInfo
.
getAllVersions
())
.
willReturn
(
Collections
.
singletonList
(
new
Version
(
1
,
2
,
3
)));
CouchbaseOperations
couchbaseOperations
=
mock
(
CouchbaseOperations
.
class
);
given
(
couchbaseOperations
.
getCouchbaseBucket
()).
willReturn
(
bucket
);
given
(
couchbaseOperations
.
getCouchbaseClusterInfo
()).
willReturn
(
clusterInfo
);
CouchbaseHealthIndicator
healthIndicator
=
new
CouchbaseHealthIndicator
(
couchbaseOperations
,
Duration
.
ofSeconds
(
2
));
@SuppressWarnings
(
"unchecked"
)
public
void
couchbaseClusterIsUp
()
{
Cluster
cluster
=
mock
(
Cluster
.
class
);
CouchbaseHealthIndicator
healthIndicator
=
new
CouchbaseHealthIndicator
(
cluster
);
List
<
EndpointHealth
>
endpoints
=
Arrays
.
asList
(
new
EndpointHealth
(
ServiceType
.
BINARY
,
LifecycleState
.
CONNECTED
,
new
InetSocketAddress
(
0
),
new
InetSocketAddress
(
0
),
1234
,
"endpoint-1"
));
DiagnosticsReport
diagnostics
=
new
DiagnosticsReport
(
endpoints
,
"test-sdk"
,
"test-id"
,
null
);
given
(
cluster
.
diagnostics
()).
willReturn
(
diagnostics
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
assertThat
(
health
.
getDetails
()).
containsOnly
(
entry
(
"versions"
,
"1.2.3"
),
entry
(
"nodes"
,
"/127.0.0.1"
));
verify
(
clusterInfo
).
getAllVersions
();
verify
(
bucketInfo
).
nodeList
();
assertThat
(
health
.
getDetails
()).
containsEntry
(
"sdk"
,
"test-sdk"
);
assertThat
(
health
.
getDetails
()).
containsKey
(
"endpoints"
);
assertThat
((
List
<
Map
<
String
,
Object
>>)
health
.
getDetails
().
get
(
"endpoints"
))
.
hasSize
(
1
);
verify
(
cluster
).
diagnostics
();
}
@Test
public
void
couchbaseTimeout
()
{
BucketManager
bucketManager
=
mock
(
BucketManager
.
class
);
given
(
bucketManager
.
info
(
1500
,
TimeUnit
.
MILLISECONDS
)).
willThrow
(
new
RuntimeException
(
new
TimeoutException
(
"timeout, expected"
)));
Bucket
bucket
=
mock
(
Bucket
.
class
);
given
(
bucket
.
bucketManager
()).
willReturn
(
bucketManager
);
CouchbaseOperations
couchbaseOperations
=
mock
(
CouchbaseOperations
.
class
);
given
(
couchbaseOperations
.
getCouchbaseBucket
()).
willReturn
(
bucket
);
CouchbaseHealthIndicator
healthIndicator
=
new
CouchbaseHealthIndicator
(
couchbaseOperations
,
Duration
.
ofMillis
(
1500
));
Health
health
=
healthIndicator
.
health
();
assertThat
((
String
)
health
.
getDetails
().
get
(
"error"
))
.
contains
(
"timeout, expected"
);
}
@Test
public
void
couchbaseIsDown
()
{
CouchbaseOperations
couchbaseOperations
=
mock
(
CouchbaseOperations
.
class
);
given
(
couchbaseOperations
.
getCouchbaseClusterInfo
())
.
willThrow
(
new
IllegalStateException
(
"test, expected"
));
CouchbaseHealthIndicator
healthIndicator
=
new
CouchbaseHealthIndicator
(
couchbaseOperations
,
Duration
.
ofSeconds
(
1
));
@SuppressWarnings
(
"unchecked"
)
public
void
couchbaseClusterIsDown
()
{
Cluster
cluster
=
mock
(
Cluster
.
class
);
CouchbaseHealthIndicator
healthIndicator
=
new
CouchbaseHealthIndicator
(
cluster
);
List
<
EndpointHealth
>
endpoints
=
Arrays
.
asList
(
new
EndpointHealth
(
ServiceType
.
BINARY
,
LifecycleState
.
CONNECTED
,
new
InetSocketAddress
(
0
),
new
InetSocketAddress
(
0
),
1234
,
"endpoint-1"
),
new
EndpointHealth
(
ServiceType
.
BINARY
,
LifecycleState
.
CONNECTING
,
new
InetSocketAddress
(
0
),
new
InetSocketAddress
(
0
),
1234
,
"endpoint-2"
));
DiagnosticsReport
diagnostics
=
new
DiagnosticsReport
(
endpoints
,
"test-sdk"
,
"test-id"
,
null
);
given
(
cluster
.
diagnostics
()).
willReturn
(
diagnostics
);
Health
health
=
healthIndicator
.
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
((
String
)
health
.
getDetails
().
get
(
"error"
)).
contains
(
"test, expected"
);
verify
(
couchbaseOperations
).
getCouchbaseClusterInfo
();
assertThat
(
health
.
getDetails
()).
containsEntry
(
"sdk"
,
"test-sdk"
);
assertThat
(
health
.
getDetails
()).
containsKey
(
"endpoints"
);
assertThat
((
List
<
Map
<
String
,
Object
>>)
health
.
getDetails
().
get
(
"endpoints"
))
.
hasSize
(
2
);
verify
(
cluster
).
diagnostics
();
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java
View file @
a4eb6369
...
...
@@ -16,10 +16,7 @@
package
org
.
springframework
.
boot
.
actuate
.
couchbase
;
import
java.net.InetAddress
;
import
java.time.Duration
;
import
java.util.Arrays
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
com.couchbase.client.java.Bucket
;
import
com.couchbase.client.java.bucket.AsyncBucketManager
;
...
...
@@ -60,7 +57,7 @@ public class CouchbaseReactiveHealthIndicatorTests {
given
(
node2Address
.
toString
()).
willReturn
(
"127.0.0.2"
);
given
(
asyncBucketManager
.
info
()).
willReturn
(
Observable
.
just
(
info
));
CouchbaseReactiveHealthIndicator
couchbaseReactiveHealthIndicator
=
new
CouchbaseReactiveHealthIndicator
(
rxJavaCouchbaseOperations
,
Duration
.
ofSeconds
(
2
)
);
rxJavaCouchbaseOperations
);
Mono
<
Health
>
health
=
couchbaseReactiveHealthIndicator
.
health
();
StepVerifier
.
create
(
health
).
consumeNextWith
((
h
)
->
{
assertThat
(
h
.
getStatus
()).
isEqualTo
(
Status
.
UP
);
...
...
@@ -70,25 +67,6 @@ public class CouchbaseReactiveHealthIndicatorTests {
}).
verifyComplete
();
}
@Test
public
void
couchbaseTimeout
()
{
RxJavaCouchbaseOperations
rxJavaCouchbaseOperations
=
mock
(
RxJavaCouchbaseOperations
.
class
);
AsyncBucketManager
asyncBucketManager
=
mockAsyncBucketManager
(
rxJavaCouchbaseOperations
);
given
(
asyncBucketManager
.
info
()).
willReturn
(
Observable
.
just
(
mock
(
BucketInfo
.
class
)).
delay
(
20
,
TimeUnit
.
MILLISECONDS
));
CouchbaseReactiveHealthIndicator
couchbaseReactiveHealthIndicator
=
new
CouchbaseReactiveHealthIndicator
(
rxJavaCouchbaseOperations
,
Duration
.
ofMillis
(
10
));
Mono
<
Health
>
health
=
couchbaseReactiveHealthIndicator
.
health
();
StepVerifier
.
create
(
health
).
consumeNextWith
((
h
)
->
{
assertThat
(
h
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
h
.
getDetails
()).
containsOnlyKeys
(
"error"
);
assertThat
(
h
.
getDetails
().
get
(
"error"
)).
asString
()
.
contains
(
TimeoutException
.
class
.
getName
());
}).
verifyComplete
();
}
@Test
public
void
couchbaseIsDown
()
{
RxJavaCouchbaseOperations
rxJavaCouchbaseOperations
=
mock
(
...
...
@@ -98,7 +76,7 @@ public class CouchbaseReactiveHealthIndicatorTests {
given
(
asyncBucketManager
.
info
())
.
willReturn
(
Observable
.
error
(
new
TranscodingException
(
"Failure"
)));
CouchbaseReactiveHealthIndicator
couchbaseReactiveHealthIndicator
=
new
CouchbaseReactiveHealthIndicator
(
rxJavaCouchbaseOperations
,
Duration
.
ofSeconds
(
2
)
);
rxJavaCouchbaseOperations
);
Mono
<
Health
>
health
=
couchbaseReactiveHealthIndicator
.
health
();
StepVerifier
.
create
(
health
).
consumeNextWith
((
h
)
->
{
assertThat
(
h
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
a4eb6369
...
...
@@ -1346,7 +1346,6 @@ content into your application. Rather, pick only the properties that you need.
management.health.db.enabled=true # Whether to enable database health check.
management.health.cassandra.enabled=true # Whether to enable Cassandra health check.
management.health.couchbase.enabled=true # Whether to enable Couchbase health check.
management.health.couchbase.timeout=1000ms # Timeout for getting the Bucket information from the server.
management.health.defaults.enabled=true # Whether to enable default health indicators.
management.health.diskspace.enabled=true # Whether to enable disk space health check.
management.health.diskspace.path= # Path used to compute the available disk space.
...
...
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