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
7672ee36
Commit
7672ee36
authored
Sep 21, 2017
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix hystrix command keys in tests to be unique
parent
7ca4f33d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
57 deletions
+108
-57
AdhocTestSuite.java
...ava/org/springframework/cloud/netflix/AdhocTestSuite.java
+4
-4
RibbonCommandCauseFallbackPropagationTest.java
...te/support/RibbonCommandCauseFallbackPropagationTest.java
+57
-33
RibbonCommandHystrixThreadPoolKeyTests.java
...route/support/RibbonCommandHystrixThreadPoolKeyTests.java
+47
-20
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java
View file @
7672ee36
...
...
@@ -21,8 +21,8 @@ import org.junit.runner.RunWith;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
org.springframework.cloud.netflix.zuul.
FormZuulServletProxyApplicationTests
;
import
org.springframework.cloud.netflix.zuul.filters.route.
LazyLoadOfZuulConfiguration
Tests
;
import
org.springframework.cloud.netflix.zuul.
filters.route.support.RibbonCommandCauseFallbackPropagationTest
;
import
org.springframework.cloud.netflix.zuul.filters.route.
support.RibbonCommandHystrixThreadPoolKey
Tests
;
/**
* A test suite for probing weird ordering problems in the tests.
...
...
@@ -30,8 +30,8 @@ import org.springframework.cloud.netflix.zuul.filters.route.LazyLoadOfZuulConfig
* @author Dave Syer
*/
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
FormZuulServletProxyApplication
Tests
.
class
,
LazyLoadOfZuulConfigurationTests
.
class
})
@SuiteClasses
({
RibbonCommandHystrixThreadPoolKey
Tests
.
class
,
RibbonCommandCauseFallbackPropagationTest
.
class
})
@Ignore
public
class
AdhocTestSuite
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/support/RibbonCommandCauseFallbackPropagationTest.java
View file @
7672ee36
...
...
@@ -17,6 +17,11 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
.
support
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.UUID
;
import
com.netflix.client.AbstractLoadBalancerAwareClient
;
import
com.netflix.client.ClientException
;
import
com.netflix.client.ClientRequest
;
...
...
@@ -26,18 +31,16 @@ import com.netflix.client.config.IClientConfig;
import
com.netflix.client.http.HttpResponse
;
import
com.netflix.hystrix.HystrixCommandProperties
;
import
com.netflix.hystrix.exception.HystrixTimeoutException
;
import
org.junit.Test
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider
;
import
org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider
;
import
org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.client.ClientHttpResponse
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
...
...
@@ -47,9 +50,11 @@ public class RibbonCommandCauseFallbackPropagationTest {
@Test
public
void
providerIsCalledInCaseOfException
()
throws
Exception
{
TestZuulFallbackProviderWithoutCause
provider
=
new
TestZuulFallbackProviderWithoutCause
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
TestZuulFallbackProviderWithoutCause
provider
=
new
TestZuulFallbackProviderWithoutCause
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
RuntimeException
exception
=
new
RuntimeException
(
"Failed!"
);
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
);
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
);
ClientHttpResponse
response
=
testCommand
.
execute
();
...
...
@@ -59,9 +64,11 @@ public class RibbonCommandCauseFallbackPropagationTest {
@Test
public
void
causeIsProvidedForNewInterface
()
throws
Exception
{
TestFallbackProvider
provider
=
TestFallbackProvider
.
withResponse
(
HttpStatus
.
NOT_FOUND
);
TestFallbackProvider
provider
=
TestFallbackProvider
.
withResponse
(
HttpStatus
.
NOT_FOUND
);
RuntimeException
exception
=
new
RuntimeException
(
"Failed!"
);
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
);
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
);
ClientHttpResponse
response
=
testCommand
.
execute
();
...
...
@@ -73,10 +80,13 @@ public class RibbonCommandCauseFallbackPropagationTest {
}
@Test
public
void
executionExceptionIsUsedInsteadWhenFailedExceptionIsNull
()
throws
Exception
{
TestFallbackProvider
provider
=
TestFallbackProvider
.
withResponse
(
HttpStatus
.
BAD_GATEWAY
);
public
void
executionExceptionIsUsedInsteadWhenFailedExceptionIsNull
()
throws
Exception
{
TestFallbackProvider
provider
=
TestFallbackProvider
.
withResponse
(
HttpStatus
.
BAD_GATEWAY
);
final
RuntimeException
exception
=
new
RuntimeException
(
"Failed!"
);
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
)
{
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
)
{
@Override
public
Throwable
getFailedExecutionException
()
{
return
null
;
...
...
@@ -96,9 +106,11 @@ public class RibbonCommandCauseFallbackPropagationTest {
@Test
public
void
timeoutExceptionIsPropagated
()
throws
Exception
{
TestFallbackProvider
provider
=
TestFallbackProvider
.
withResponse
(
HttpStatus
.
CONFLICT
);
TestFallbackProvider
provider
=
TestFallbackProvider
.
withResponse
(
HttpStatus
.
CONFLICT
);
RuntimeException
exception
=
new
RuntimeException
(
"Failed!"
);
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
,
1
)
{
TestRibbonCommand
testCommand
=
new
TestRibbonCommand
(
new
TestClient
(
exception
),
provider
,
1
)
{
@Override
protected
ClientRequest
createRequest
()
throws
Exception
{
Thread
.
sleep
(
5
);
...
...
@@ -111,33 +123,39 @@ public class RibbonCommandCauseFallbackPropagationTest {
assertThat
(
response
).
isNotNull
();
assertThat
(
response
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
CONFLICT
);
assertThat
(
provider
.
getCause
()).
isNotNull
();
assertThat
(
provider
.
getCause
().
getClass
()).
isEqualTo
(
HystrixTimeoutException
.
class
);
assertThat
(
provider
.
getCause
().
getClass
())
.
isEqualTo
(
HystrixTimeoutException
.
class
);
}
public
static
class
TestRibbonCommand
extends
AbstractRibbonCommand
<
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>,
ClientRequest
,
HttpResponse
>
{
public
static
class
TestRibbonCommand
extends
AbstractRibbonCommand
<
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>,
ClientRequest
,
HttpResponse
>
{
public
TestRibbonCommand
(
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>
client
,
ZuulFallbackProvider
fallbackProvider
)
{
public
TestRibbonCommand
(
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>
client
,
ZuulFallbackProvider
fallbackProvider
)
{
this
(
client
,
new
ZuulProperties
(),
fallbackProvider
);
}
public
TestRibbonCommand
(
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>
client
,
ZuulProperties
zuulProperties
,
ZuulFallbackProvider
fallbackProvider
)
{
super
(
"testCommand"
,
client
,
null
,
zuulProperties
,
fallbackProvider
);
public
TestRibbonCommand
(
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>
client
,
ZuulProperties
zuulProperties
,
ZuulFallbackProvider
fallbackProvider
)
{
super
(
"testCommand"
+
UUID
.
randomUUID
(),
client
,
null
,
zuulProperties
,
fallbackProvider
);
}
public
TestRibbonCommand
(
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>
client
,
ZuulFallbackProvider
fallbackProvider
,
int
timeout
)
{
public
TestRibbonCommand
(
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>
client
,
ZuulFallbackProvider
fallbackProvider
,
int
timeout
)
{
// different name is used because of properties caching
super
(
getSetter
(
"testCommand2"
,
new
ZuulProperties
()).
andCommandPropertiesDefaults
(
defauts
(
timeout
)),
client
,
null
,
fallbackProvider
,
null
);
super
(
getSetter
(
"testCommand"
+
UUID
.
randomUUID
(),
new
ZuulProperties
())
.
andCommandPropertiesDefaults
(
defauts
(
timeout
)),
client
,
null
,
fallbackProvider
,
null
);
}
private
static
HystrixCommandProperties
.
Setter
defauts
(
final
int
timeout
)
{
return
HystrixCommandProperties
.
Setter
().
withExecutionTimeoutEnabled
(
true
)
.
withExecutionIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
)
.
withExecutionIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
)
.
withExecutionTimeoutInMilliseconds
(
timeout
);
}
...
...
@@ -147,6 +165,7 @@ public class RibbonCommandCauseFallbackPropagationTest {
}
}
@SuppressWarnings
(
"rawtypes"
)
public
static
class
TestClient
extends
AbstractLoadBalancerAwareClient
{
private
final
RuntimeException
exception
;
...
...
@@ -157,17 +176,20 @@ public class RibbonCommandCauseFallbackPropagationTest {
}
@Override
public
IResponse
executeWithLoadBalancer
(
final
ClientRequest
request
,
final
IClientConfig
requestConfig
)
throws
ClientException
{
public
IResponse
executeWithLoadBalancer
(
final
ClientRequest
request
,
final
IClientConfig
requestConfig
)
throws
ClientException
{
throw
exception
;
}
@Override
public
RequestSpecificRetryHandler
getRequestSpecificRetryHandler
(
final
ClientRequest
clientRequest
,
final
IClientConfig
iClientConfig
)
{
public
RequestSpecificRetryHandler
getRequestSpecificRetryHandler
(
final
ClientRequest
clientRequest
,
final
IClientConfig
iClientConfig
)
{
return
null
;
}
@Override
public
IResponse
execute
(
final
ClientRequest
clientRequest
,
final
IClientConfig
iClientConfig
)
throws
Exception
{
public
IResponse
execute
(
final
ClientRequest
clientRequest
,
final
IClientConfig
iClientConfig
)
throws
Exception
{
return
null
;
}
}
...
...
@@ -194,7 +216,8 @@ public class RibbonCommandCauseFallbackPropagationTest {
@Override
public
ClientHttpResponse
fallbackResponse
()
{
throw
new
UnsupportedOperationException
(
"fallback without cause is not supported"
);
throw
new
UnsupportedOperationException
(
"fallback without cause is not supported"
);
}
public
Throwable
getCause
()
{
...
...
@@ -206,7 +229,8 @@ public class RibbonCommandCauseFallbackPropagationTest {
}
}
public
static
class
TestZuulFallbackProviderWithoutCause
implements
ZuulFallbackProvider
{
public
static
class
TestZuulFallbackProviderWithoutCause
implements
ZuulFallbackProvider
{
private
final
ClientHttpResponse
response
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/support/RibbonCommandHystrixThreadPoolKeyTests.java
View file @
7672ee36
...
...
@@ -20,8 +20,12 @@ import com.netflix.client.AbstractLoadBalancerAwareClient;
import
com.netflix.client.ClientRequest
;
import
com.netflix.client.http.HttpResponse
;
import
com.netflix.hystrix.HystrixCommandProperties
;
import
com.netflix.hystrix.strategy.HystrixPlugins
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -38,25 +42,38 @@ public class RibbonCommandHystrixThreadPoolKeyTests {
zuulProperties
=
new
ZuulProperties
();
}
@After
public
void
tearDown
()
throws
Exception
{
HystrixPlugins
.
reset
();
}
@Test
public
void
testDefaultHystrixThreadPoolKey
()
throws
Exception
{
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
);
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
// CommandGroupKey should be used as ThreadPoolKey as default.
assertThat
(
ribbonCommand1
.
getThreadPoolKey
().
name
()).
isEqualTo
(
ribbonCommand1
.
getCommandGroup
().
name
());
assertThat
(
ribbonCommand2
.
getThreadPoolKey
().
name
()).
isEqualTo
(
ribbonCommand2
.
getCommandGroup
().
name
());
assertThat
(
ribbonCommand1
.
getThreadPoolKey
().
name
())
.
isEqualTo
(
ribbonCommand1
.
getCommandGroup
().
name
());
assertThat
(
ribbonCommand2
.
getThreadPoolKey
().
name
())
.
isEqualTo
(
ribbonCommand2
.
getCommandGroup
().
name
());
}
@Test
public
void
testUseSeparateThreadPools
()
throws
Exception
{
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
);
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
);
zuulProperties
.
getThreadPool
().
setUseSeparateThreadPools
(
true
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
assertThat
(
ribbonCommand1
.
getThreadPoolKey
().
name
()).
isEqualTo
(
"testCommand1"
);
assertThat
(
ribbonCommand2
.
getThreadPoolKey
().
name
()).
isEqualTo
(
"testCommand2"
);
...
...
@@ -66,35 +83,45 @@ public class RibbonCommandHystrixThreadPoolKeyTests {
public
void
testThreadPoolKeyPrefix
()
throws
Exception
{
final
String
prefix
=
"zuulgw-"
;
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
);
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
THREAD
);
zuulProperties
.
getThreadPool
().
setUseSeparateThreadPools
(
true
);
zuulProperties
.
getThreadPool
().
setThreadPoolKeyPrefix
(
prefix
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
assertThat
(
ribbonCommand1
.
getThreadPoolKey
().
name
()).
isEqualTo
(
prefix
+
"testCommand1"
);
assertThat
(
ribbonCommand2
.
getThreadPoolKey
().
name
()).
isEqualTo
(
prefix
+
"testCommand2"
);
assertThat
(
ribbonCommand1
.
getThreadPoolKey
().
name
())
.
isEqualTo
(
prefix
+
"testCommand1"
);
assertThat
(
ribbonCommand2
.
getThreadPoolKey
().
name
())
.
isEqualTo
(
prefix
+
"testCommand2"
);
}
@Test
public
void
testNoSideEffectOnSemaphoreIsolation
()
throws
Exception
{
final
String
prefix
=
"zuulgw-"
;
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
SEMAPHORE
);
zuulProperties
.
setRibbonIsolationStrategy
(
HystrixCommandProperties
.
ExecutionIsolationStrategy
.
SEMAPHORE
);
zuulProperties
.
getThreadPool
().
setUseSeparateThreadPools
(
true
);
zuulProperties
.
getThreadPool
().
setThreadPoolKeyPrefix
(
prefix
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand1
=
new
TestRibbonCommand
(
"testCommand1"
,
zuulProperties
);
TestRibbonCommand
ribbonCommand2
=
new
TestRibbonCommand
(
"testCommand2"
,
zuulProperties
);
// There should be no side effect on semaphore isolation
assertThat
(
ribbonCommand1
.
getThreadPoolKey
().
name
()).
isEqualTo
(
ribbonCommand1
.
getCommandGroup
().
name
());
assertThat
(
ribbonCommand2
.
getThreadPoolKey
().
name
()).
isEqualTo
(
ribbonCommand2
.
getCommandGroup
().
name
());
assertThat
(
ribbonCommand1
.
getThreadPoolKey
().
name
())
.
isEqualTo
(
ribbonCommand1
.
getCommandGroup
().
name
());
assertThat
(
ribbonCommand2
.
getThreadPoolKey
().
name
())
.
isEqualTo
(
ribbonCommand2
.
getCommandGroup
().
name
());
}
public
static
class
TestRibbonCommand
extends
AbstractRibbonCommand
<
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>,
ClientRequest
,
HttpResponse
>
{
public
static
class
TestRibbonCommand
extends
AbstractRibbonCommand
<
AbstractLoadBalancerAwareClient
<
ClientRequest
,
HttpResponse
>,
ClientRequest
,
HttpResponse
>
{
public
TestRibbonCommand
(
String
commandKey
,
ZuulProperties
zuulProperties
)
{
super
(
commandKey
,
null
,
null
,
zuulProperties
);
}
...
...
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