Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
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
openSource
spring-cloud-netflix
Commits
195c3fd7
Commit
195c3fd7
authored
Jun 09, 2017
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract utility class into shared library for contract tests
parent
c626bcca
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
203 additions
and
101 deletions
+203
-101
pom.xml
pom.xml
+1
-0
pom.xml
spring-cloud-netflix-hystrix-contract/pom.xml
+35
-0
HystrixContractUtils.java
.../cloud/netflix/hystrix/contract/HystrixContractUtils.java
+71
-0
simpleBody.json
...hystrix-contract/src/main/resources/stubs/simpleBody.json
+71
-0
pom.xml
spring-cloud-netflix-hystrix-stream/pom.xml
+11
-3
StreamSourceTestBase.java
...rk/cloud/netflix/hystrix/stream/StreamSourceTestBase.java
+3
-13
shouldProduceValidMetricsData.groovy
.../resources/contracts/shouldProduceValidMetricsData.groovy
+3
-82
pom.xml
spring-cloud-netflix-turbine-stream/pom.xml
+6
-0
TurbineStreamTests.java
...work/cloud/netflix/turbine/stream/TurbineStreamTests.java
+2
-3
No files found.
pom.xml
View file @
195c3fd7
...
...
@@ -124,6 +124,7 @@
</dependencyManagement>
<modules>
<module>
spring-cloud-netflix-dependencies
</module>
<module>
spring-cloud-netflix-hystrix-contract
</module>
<module>
spring-cloud-netflix-core
</module>
<module>
spring-cloud-netflix-hystrix-dashboard
</module>
<module>
spring-cloud-netflix-hystrix-amqp
</module>
...
...
spring-cloud-netflix-hystrix-contract/pom.xml
0 → 100644
View file @
195c3fd7
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-netflix
</artifactId>
<version>
1.3.1.BUILD-SNAPSHOT
</version>
<relativePath>
..
</relativePath>
<!-- lookup parent from repository -->
</parent>
<artifactId>
spring-cloud-netflix-hystrix-contract
</artifactId>
<packaging>
jar
</packaging>
<name>
spring-cloud-netflix-hystrix-contract
</name>
<description>
Spring Cloud Netflix Hystrix Contract
</description>
<properties>
<main.basedir>
${basedir}/..
</main.basedir>
<spring-cloud-contract.version>
1.0.5.RELEASE
</spring-cloud-contract.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-contract-verifier
</artifactId>
<version>
${spring-cloud-contract.version}
</version>
</dependency>
</dependencies>
</project>
spring-cloud-netflix-hystrix-contract/src/main/java/org/springframework/cloud/netflix/hystrix/contract/HystrixContractUtils.java
0 → 100644
View file @
195c3fd7
/*
* Copyright 2016-2017 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
.
cloud
.
netflix
.
hystrix
.
contract
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.util.StreamUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* @author Dave Syer
*
*/
public
class
HystrixContractUtils
{
public
static
String
simpleBody
()
{
try
{
return
StreamUtils
.
copyToString
(
new
DefaultResourceLoader
()
.
getResource
(
"classpath:/stubs/simpleBody.json"
).
getInputStream
(),
StandardCharsets
.
UTF_8
);
}
catch
(
IOException
e
)
{
throw
new
IllegalStateException
(
"Cannot read stub"
,
e
);
}
}
public
static
void
checkOrigin
(
Map
<
String
,
Object
>
origin
)
{
assertThat
(
origin
.
get
(
"host"
)).
isNotNull
();
assertThat
(
origin
.
get
(
"port"
)).
isNotNull
();
assertThat
(
origin
.
get
(
"serviceId"
)).
isEqualTo
(
"application"
);
// TODO: should be server.port?
assertThat
(
origin
.
get
(
"id"
)).
isEqualTo
(
"application:-1"
);
}
public
static
void
checkData
(
Map
<
String
,
Object
>
data
)
{
assertThat
(
data
.
get
(
"type"
)).
isEqualTo
(
"HystrixCommand"
);
// TODO: should be application.hello
assertThat
(
data
.
get
(
"name"
)).
asString
().
startsWith
(
"application."
);
assertThat
(
data
.
get
(
"group"
)).
isNotNull
();
// TODO: should be TestApplication
// assertThat(data.get("group")).isEqualTo(TestApplication.class.getSimpleName());
assertThat
(
data
.
get
(
"errorCount"
)).
isEqualTo
(
0
);
assertThat
(
data
.
get
(
"errorPercentage"
)).
isEqualTo
(
0
);
assertThat
(
data
.
get
(
"requestCount"
)).
isInstanceOf
(
java
.
lang
.
Integer
.
class
);
assertThat
(
data
.
get
(
"currentConcurrentExecutionCount"
))
.
isInstanceOf
(
java
.
lang
.
Integer
.
class
);
assertThat
(
data
.
get
(
"rollingCountFailure"
)).
isEqualTo
(
0
);
assertThat
(
data
.
get
(
"rollingCountSuccess"
)).
isInstanceOf
(
java
.
lang
.
Integer
.
class
);
assertThat
(
data
.
get
(
"rollingCountShortCircuited"
)).
isEqualTo
(
0
);
assertThat
(
data
.
get
(
"rollingCountFallbackSuccess"
)).
isEqualTo
(
0
);
assertThat
(
data
.
get
(
"isCircuitBreakerOpen"
)).
isEqualTo
(
false
);
}
}
spring-cloud-netflix-hystrix-contract/src/main/resources/stubs/simpleBody.json
0 → 100644
View file @
195c3fd7
{
"origin"
:{
"host"
:
"192.168.1.192"
,
"port"
:
0
,
"serviceId"
:
"application"
,
"id"
:
"application:0"
},
"data"
:{
"type"
:
"HystrixCommand"
,
"name"
:
"application.hello"
,
"group"
:
"Application"
,
"currentTime"
:
1494840901153
,
"isCircuitBreakerOpen"
:
false
,
"errorPercentage"
:
0
,
"errorCount"
:
0
,
"requestCount"
:
1
,
"rollingCountCollapsedRequests"
:
0
,
"rollingCountExceptionsThrown"
:
0
,
"rollingCountFailure"
:
0
,
"rollingCountFallbackFailure"
:
0
,
"rollingCountFallbackRejection"
:
0
,
"rollingCountFallbackSuccess"
:
0
,
"rollingCountResponsesFromCache"
:
0
,
"rollingCountSemaphoreRejected"
:
0
,
"rollingCountShortCircuited"
:
0
,
"rollingCountSuccess"
:
0
,
"rollingCountThreadPoolRejected"
:
0
,
"rollingCountTimeout"
:
0
,
"currentConcurrentExecutionCount"
:
0
,
"latencyExecute_mean"
:
0
,
"latencyExecute"
:{
"0"
:
0
,
"25"
:
0
,
"50"
:
0
,
"75"
:
0
,
"90"
:
0
,
"95"
:
0
,
"99"
:
0
,
"99.5"
:
0
,
"100"
:
0
},
"latencyTotal_mean"
:
0
,
"latencyTotal"
:{
"0"
:
0
,
"25"
:
0
,
"50"
:
0
,
"75"
:
0
,
"90"
:
0
,
"95"
:
0
,
"99"
:
0
,
"99.5"
:
0
,
"100"
:
0
},
"propertyValue_circuitBreakerRequestVolumeThreshold"
:
20
,
"propertyValue_circuitBreakerSleepWindowInMilliseconds"
:
5000
,
"propertyValue_circuitBreakerErrorThresholdPercentage"
:
50
,
"propertyValue_circuitBreakerForceOpen"
:
false
,
"propertyValue_circuitBreakerForceClosed"
:
false
,
"propertyValue_circuitBreakerEnabled"
:
true
,
"propertyValue_executionIsolationStrategy"
:
"THREAD"
,
"propertyValue_executionIsolationThreadTimeoutInMilliseconds"
:
1000
,
"propertyValue_executionIsolationThreadInterruptOnTimeout"
:
true
,
"propertyValue_executionIsolationThreadPoolKeyOverride"
:
null
,
"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests"
:
10
,
"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests"
:
10
,
"propertyValue_metricsRollingStatisticalWindowInMilliseconds"
:
10000
,
"propertyValue_requestCacheEnabled"
:
true
,
"propertyValue_requestLogEnabled"
:
true
,
"reportingHosts"
:
1
}
}
spring-cloud-netflix-hystrix-stream/pom.xml
View file @
195c3fd7
...
...
@@ -78,8 +78,8 @@
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-
contract-verifier
</artifactId>
<version>
${
spring-cloud-contra
ct.version}
</version>
<artifactId>
spring-cloud-
netflix-hystrix-contract
</artifactId>
<version>
${
proje
ct.version}
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
...
...
@@ -98,11 +98,19 @@
</baseClassMapping>
</baseClassMappings>
</configuration>
<dependencies>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-netflix-hystrix-contract
</artifactId>
<version>
${project.version}
</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>
org.eclipse.m2e
</groupId>
<artifactId>
lifecycle-mapping
</artifactId>
...
...
spring-cloud-netflix-hystrix-stream/src/test/java/org/springframework/cloud/netflix/hystrix/stream/StreamSourceTestBase.java
View file @
195c3fd7
...
...
@@ -28,13 +28,12 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker
;
import
org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier
;
import
org.springframework.cloud.netflix.hystrix.contract.HystrixContractUtils
;
import
org.springframework.cloud.netflix.hystrix.stream.StreamSourceTestBase.TestApplication
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Base class for sensor autogenerated tests (used by Spring Cloud Contract).
*
...
...
@@ -57,23 +56,14 @@ public abstract class StreamSourceTestBase {
public
void
assertOrigin
(
Object
input
)
{
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
origin
=
(
Map
<
String
,
Object
>)
input
;
assertThat
(
origin
.
get
(
"host"
)).
isNotNull
();
assertThat
(
origin
.
get
(
"port"
)).
isNotNull
();
assertThat
(
origin
.
get
(
"serviceId"
)).
isEqualTo
(
"application"
);
// TODO: should be server.port?
assertThat
(
origin
.
get
(
"id"
)).
isEqualTo
(
"application:-1"
);
HystrixContractUtils
.
checkOrigin
(
origin
);
}
public
void
assertData
(
Object
input
)
{
System
.
err
.
println
(
input
);
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
data
=
(
Map
<
String
,
Object
>)
input
;
assertThat
(
data
.
get
(
"type"
)).
isEqualTo
(
"HystrixCommand"
);
// TODO: should be application.hello
assertThat
(
data
.
get
(
"name"
)).
asString
().
startsWith
(
"application."
);
assertThat
(
data
.
get
(
"group"
)).
isNotNull
();
// TODO: should be TestApplication
// assertThat(data.get("group")).isEqualTo(TestApplication.class.getSimpleName());
HystrixContractUtils
.
checkData
(
data
);
}
@EnableAutoConfiguration
...
...
spring-cloud-netflix-hystrix-stream/src/test/resources/contracts/shouldProduceValidMetricsData.groovy
View file @
195c3fd7
package
contracts
import
org.springframework.cloud.netflix.hystrix.contract.HystrixContractUtils
org
.
springframework
.
cloud
.
contract
.
spec
.
Contract
.
make
{
// Human readable description
description
'Should produce valid metrics data'
...
...
@@ -17,91 +19,10 @@ org.springframework.cloud.contract.spec.Contract.make {
headers
{
header
(
'contentType'
:
'application/json'
)
}
body
(
"""
{
"origin":{
"host":"192.168.1.192",
"port":0,
"serviceId":"application",
"id":"application:0"
},
"data":{
"type":"HystrixCommand",
"name":"application.hello",
"group":"Application",
"currentTime":1494840901153,
"isCircuitBreakerOpen":false,
"errorPercentage":0,
"errorCount":0,
"requestCount":1,
"rollingCountCollapsedRequests":0,
"rollingCountExceptionsThrown":0,
"rollingCountFailure":0,
"rollingCountFallbackFailure":0,
"rollingCountFallbackRejection":0,
"rollingCountFallbackSuccess":0,
"rollingCountResponsesFromCache":0,
"rollingCountSemaphoreRejected":0,
"rollingCountShortCircuited":0,
"rollingCountSuccess":0,
"rollingCountThreadPoolRejected":0,
"rollingCountTimeout":0,
"currentConcurrentExecutionCount":0,
"latencyExecute_mean":0,
"latencyExecute":{
"0":0,
"25":0,
"50":0,
"75":0,
"90":0,
"95":0,
"99":0,
"99.5":0,
"100":0
},
"latencyTotal_mean":0,
"latencyTotal":{
"0":0,
"25":0,
"50":0,
"75":0,
"90":0,
"95":0,
"99":0,
"99.5":0,
"100":0
},
"propertyValue_circuitBreakerRequestVolumeThreshold":20,
"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,
"propertyValue_circuitBreakerErrorThresholdPercentage":50,
"propertyValue_circuitBreakerForceOpen":false,
"propertyValue_circuitBreakerForceClosed":false,
"propertyValue_circuitBreakerEnabled":true,
"propertyValue_executionIsolationStrategy":"THREAD",
"propertyValue_executionIsolationThreadTimeoutInMilliseconds":1000,
"propertyValue_executionIsolationThreadInterruptOnTimeout":true,
"propertyValue_executionIsolationThreadPoolKeyOverride":null,
"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,
"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,
"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,
"propertyValue_requestCacheEnabled":true,
"propertyValue_requestLogEnabled":true,
"reportingHosts":1
}
}
"""
)
body
(
HystrixContractUtils
.
simpleBody
())
testMatchers
{
jsonPath
(
'$.origin'
,
byCommand
(
'assertOrigin($it)'
))
jsonPath
(
'$.data'
,
byCommand
(
'assertData($it)'
))
jsonPath
(
'$.data.errorCount'
,
byEquality
())
jsonPath
(
'$.data.errorPercentage'
,
byEquality
())
jsonPath
(
'$.data.requestCount'
,
byType
())
jsonPath
(
'$.data.currentConcurrentExecutionCount'
,
byType
())
jsonPath
(
'$.data.rollingCountFailure'
,
byEquality
())
jsonPath
(
'$.data.rollingCountSuccess'
,
byType
())
jsonPath
(
'$.data.rollingCountShortCircuited'
,
byEquality
())
jsonPath
(
'$.data.rollingCountFallbackSuccess'
,
byEquality
())
jsonPath
(
'$.data.isCircuitBreakerOpen'
,
byEquality
())
}
}
}
spring-cloud-netflix-turbine-stream/pom.xml
View file @
195c3fd7
...
...
@@ -111,5 +111,11 @@
<version>
${spring-cloud-contract.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-netflix-hystrix-contract
</artifactId>
<version>
${project.version}
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
spring-cloud-netflix-turbine-stream/src/test/java/org/springframework/cloud/netflix/turbine/stream/TurbineStreamTests.java
View file @
195c3fd7
...
...
@@ -63,7 +63,6 @@ import static org.assertj.core.api.Assertions.assertThat;
// TODO: we don't need this if we harmonize the turbine and hystrix destinations
// https://github.com/spring-cloud/spring-cloud-netflix/issues/1948
"spring.cloud.stream.bindings.turbineStreamInput.destination=hystrixStreamOutput"
,
"logging.level.org.springframework.cloud.netflix.turbine=DEBUG"
,
"spring.jmx.enabled=true"
,
"stubrunner.workOffline=true"
,
"stubrunner.ids=org.springframework.cloud:spring-cloud-netflix-hystrix-stream"
})
@AutoConfigureStubRunner
...
...
@@ -140,9 +139,9 @@ public class TurbineStreamTests {
latch
.
countDown
();
builder
.
append
(
new
String
(
bytes
,
0
,
read
));
}
log
.
info
(
"Building: "
+
builder
);
log
.
debug
(
"Building: "
+
builder
);
}
log
.
info
(
"Done: "
+
builder
);
log
.
debug
(
"Done: "
+
builder
);
return
ResponseEntity
.
status
(
response
.
getStatusCode
())
.
headers
(
response
.
getHeaders
()).
body
(
builder
.
toString
());
}
...
...
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