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
8aeca9c2
Commit
8aeca9c2
authored
Sep 08, 2017
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master' into 2.0.x
parents
81c6ece8
38b8786e
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
128 additions
and
3 deletions
+128
-3
RibbonClientConfiguration.java
...ework/cloud/netflix/ribbon/RibbonClientConfiguration.java
+6
-0
AbstractLoadBalancingClient.java
...d/netflix/ribbon/support/AbstractLoadBalancingClient.java
+3
-2
AbstractRibbonCommand.java
...lix/zuul/filters/route/support/AbstractRibbonCommand.java
+3
-1
RibbonLoadBalancingHttpClientTests.java
...lix/ribbon/apache/RibbonLoadBalancingHttpClientTests.java
+7
-0
OkHttpLoadBalancingClientTests.java
...netflix/ribbon/okhttp/OkHttpLoadBalancingClientTests.java
+7
-0
HttpClientRibbonCommandFactoryTest.java
...ters/route/apache/HttpClientRibbonCommandFactoryTest.java
+51
-0
OkHttpRibbonCommandFactoryTest.java
.../filters/route/okhttp/OkHttpRibbonCommandFactoryTest.java
+51
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfiguration.java
View file @
8aeca9c2
...
@@ -35,6 +35,7 @@ import org.springframework.context.annotation.Import;
...
@@ -35,6 +35,7 @@ import org.springframework.context.annotation.Import;
import
com.netflix.client.DefaultLoadBalancerRetryHandler
;
import
com.netflix.client.DefaultLoadBalancerRetryHandler
;
import
com.netflix.client.RetryHandler
;
import
com.netflix.client.RetryHandler
;
import
com.netflix.client.config.CommonClientConfigKey
;
import
com.netflix.client.config.DefaultClientConfigImpl
;
import
com.netflix.client.config.DefaultClientConfigImpl
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.loadbalancer.ConfigurationBasedServerList
;
import
com.netflix.loadbalancer.ConfigurationBasedServerList
;
...
@@ -68,6 +69,9 @@ import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToHttps
...
@@ -68,6 +69,9 @@ import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToHttps
@Import
({
HttpClientConfiguration
.
class
,
OkHttpRibbonConfiguration
.
class
,
RestClientRibbonConfiguration
.
class
,
HttpClientRibbonConfiguration
.
class
})
@Import
({
HttpClientConfiguration
.
class
,
OkHttpRibbonConfiguration
.
class
,
RestClientRibbonConfiguration
.
class
,
HttpClientRibbonConfiguration
.
class
})
public
class
RibbonClientConfiguration
{
public
class
RibbonClientConfiguration
{
public
static
final
int
DEFAULT_CONNECT_TIMEOUT
=
1000
;
public
static
final
int
DEFAULT_READ_TIMEOUT
=
1000
;
@Value
(
"${ribbon.client.name}"
)
@Value
(
"${ribbon.client.name}"
)
private
String
name
=
"client"
;
private
String
name
=
"client"
;
...
@@ -82,6 +86,8 @@ public class RibbonClientConfiguration {
...
@@ -82,6 +86,8 @@ public class RibbonClientConfiguration {
public
IClientConfig
ribbonClientConfig
()
{
public
IClientConfig
ribbonClientConfig
()
{
DefaultClientConfigImpl
config
=
new
DefaultClientConfigImpl
();
DefaultClientConfigImpl
config
=
new
DefaultClientConfigImpl
();
config
.
loadProperties
(
this
.
name
);
config
.
loadProperties
(
this
.
name
);
config
.
set
(
CommonClientConfigKey
.
ConnectTimeout
,
DEFAULT_CONNECT_TIMEOUT
);
config
.
set
(
CommonClientConfigKey
.
ReadTimeout
,
DEFAULT_READ_TIMEOUT
);
return
config
;
return
config
;
}
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/support/AbstractLoadBalancingClient.java
View file @
8aeca9c2
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
support
;
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
support
;
import
org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
com.netflix.client.AbstractLoadBalancerAwareClient
;
import
com.netflix.client.AbstractLoadBalancerAwareClient
;
...
@@ -92,10 +93,10 @@ public abstract class AbstractLoadBalancingClient<S extends ContextAwareRequest,
...
@@ -92,10 +93,10 @@ public abstract class AbstractLoadBalancingClient<S extends ContextAwareRequest,
super
.
initWithNiwsConfig
(
clientConfig
);
super
.
initWithNiwsConfig
(
clientConfig
);
this
.
connectTimeout
=
clientConfig
.
getPropertyAsInteger
(
this
.
connectTimeout
=
clientConfig
.
getPropertyAsInteger
(
CommonClientConfigKey
.
ConnectTimeout
,
CommonClientConfigKey
.
ConnectTimeout
,
DefaultClientConfigImpl
.
DEFAULT_CONNECT_TIMEOUT
);
RibbonClientConfiguration
.
DEFAULT_CONNECT_TIMEOUT
);
this
.
readTimeout
=
clientConfig
.
getPropertyAsInteger
(
this
.
readTimeout
=
clientConfig
.
getPropertyAsInteger
(
CommonClientConfigKey
.
ReadTimeout
,
CommonClientConfigKey
.
ReadTimeout
,
DefaultClientConfigImpl
.
DEFAULT_READ_TIMEOUT
);
RibbonClientConfiguration
.
DEFAULT_READ_TIMEOUT
);
this
.
secure
=
clientConfig
.
getPropertyAsBoolean
(
CommonClientConfigKey
.
IsSecure
,
this
.
secure
=
clientConfig
.
getPropertyAsBoolean
(
CommonClientConfigKey
.
IsSecure
,
false
);
false
);
this
.
followRedirects
=
clientConfig
.
getPropertyAsBoolean
(
this
.
followRedirects
=
clientConfig
.
getPropertyAsBoolean
(
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/support/AbstractRibbonCommand.java
View file @
8aeca9c2
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
.
support
;
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
.
support
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonHttpResponse
;
import
org.springframework.cloud.netflix.ribbon.RibbonHttpResponse
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand
;
...
@@ -83,7 +84,8 @@ public abstract class AbstractRibbonCommand<LBC extends AbstractLoadBalancerAwar
...
@@ -83,7 +84,8 @@ public abstract class AbstractRibbonCommand<LBC extends AbstractLoadBalancerAwar
.
andCommandKey
(
HystrixCommandKey
.
Factory
.
asKey
(
commandKey
));
.
andCommandKey
(
HystrixCommandKey
.
Factory
.
asKey
(
commandKey
));
final
HystrixCommandProperties
.
Setter
setter
=
HystrixCommandProperties
.
Setter
()
final
HystrixCommandProperties
.
Setter
setter
=
HystrixCommandProperties
.
Setter
()
.
withExecutionIsolationStrategy
(
zuulProperties
.
getRibbonIsolationStrategy
());
.
withExecutionIsolationStrategy
(
zuulProperties
.
getRibbonIsolationStrategy
()).
withExecutionTimeoutInMilliseconds
(
RibbonClientConfiguration
.
DEFAULT_CONNECT_TIMEOUT
+
RibbonClientConfiguration
.
DEFAULT_READ_TIMEOUT
);
if
(
zuulProperties
.
getRibbonIsolationStrategy
()
==
ExecutionIsolationStrategy
.
SEMAPHORE
){
if
(
zuulProperties
.
getRibbonIsolationStrategy
()
==
ExecutionIsolationStrategy
.
SEMAPHORE
){
final
String
name
=
ZuulConstants
.
ZUUL_EUREKA
+
commandKey
+
".semaphore.maxSemaphores"
;
final
String
name
=
ZuulConstants
.
ZUUL_EUREKA
+
commandKey
+
".semaphore.maxSemaphores"
;
// we want to default to semaphore-isolation since this wraps
// we want to default to semaphore-isolation since this wraps
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonLoadBalancingHttpClientTests.java
View file @
8aeca9c2
...
@@ -116,6 +116,13 @@ public class RibbonLoadBalancingHttpClientTests {
...
@@ -116,6 +116,13 @@ public class RibbonLoadBalancingHttpClientTests {
}
}
@Test
@Test
public
void
testDefaultTimeouts
()
throws
Exception
{
RequestConfig
result
=
getBuiltRequestConfig
(
UseDefaults
.
class
,
null
);
assertThat
(
result
.
getConnectTimeout
(),
is
(
1000
));
assertThat
(
result
.
getSocketTimeout
(),
is
(
1000
));
}
@Test
public
void
testConnections
()
throws
Exception
{
public
void
testConnections
()
throws
Exception
{
SpringClientFactory
factory
=
new
SpringClientFactory
();
SpringClientFactory
factory
=
new
SpringClientFactory
();
factory
.
setApplicationContext
(
new
AnnotationConfigApplicationContext
(
factory
.
setApplicationContext
(
new
AnnotationConfigApplicationContext
(
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpLoadBalancingClientTests.java
View file @
8aeca9c2
...
@@ -94,6 +94,13 @@ public class OkHttpLoadBalancingClientTests {
...
@@ -94,6 +94,13 @@ public class OkHttpLoadBalancingClientTests {
}
}
@Test
@Test
public
void
testDefaultTimeouts
()
throws
Exception
{
OkHttpClient
result
=
getHttpClient
(
UseDefaults
.
class
,
null
);
assertThat
(
result
.
readTimeoutMillis
(),
is
(
1000
));
assertThat
(
result
.
connectTimeoutMillis
(),
is
(
1000
));
}
@Test
public
void
testTimeoutsOverride
()
throws
Exception
{
public
void
testTimeoutsOverride
()
throws
Exception
{
DefaultClientConfigImpl
override
=
new
DefaultClientConfigImpl
();
DefaultClientConfigImpl
override
=
new
DefaultClientConfigImpl
();
override
.
set
(
CommonClientConfigKey
.
ConnectTimeout
,
60
);
override
.
set
(
CommonClientConfigKey
.
ConnectTimeout
,
60
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/apache/HttpClientRibbonCommandFactoryTest.java
0 → 100644
View file @
8aeca9c2
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
.
apache
;
import
java.util.HashSet
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider
;
import
com.netflix.client.config.DefaultClientConfigImpl
;
import
com.netflix.client.config.IClientConfig
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* @author Ryan Baxter
*/
public
class
HttpClientRibbonCommandFactoryTest
{
SpringClientFactory
springClientFactory
;
ZuulProperties
zuulProperties
;
HttpClientRibbonCommandFactory
ribbonCommandFactory
;
@Before
public
void
setup
(){
this
.
springClientFactory
=
mock
(
SpringClientFactory
.
class
);
this
.
zuulProperties
=
new
ZuulProperties
();
RibbonLoadBalancingHttpClient
loadBalancingHttpClient
=
mock
(
RibbonLoadBalancingHttpClient
.
class
);
IClientConfig
clientConfig
=
new
DefaultClientConfigImpl
();
doReturn
(
loadBalancingHttpClient
).
when
(
this
.
springClientFactory
).
getClient
(
anyString
(),
eq
(
RibbonLoadBalancingHttpClient
.
class
));
doReturn
(
clientConfig
).
when
(
this
.
springClientFactory
).
getClientConfig
(
anyString
());
this
.
ribbonCommandFactory
=
new
HttpClientRibbonCommandFactory
(
springClientFactory
,
zuulProperties
,
new
HashSet
<
ZuulFallbackProvider
>());
}
@Test
public
void
testHystrixTimeoutValue
()
throws
Exception
{
RibbonCommandContext
context
=
mock
(
RibbonCommandContext
.
class
);
doReturn
(
"service"
).
when
(
context
).
getServiceId
();
HttpClientRibbonCommand
ribbonCommand
=
this
.
ribbonCommandFactory
.
create
(
context
);
assertEquals
(
2000
,
ribbonCommand
.
getProperties
().
executionTimeoutInMilliseconds
().
get
().
intValue
());
}
}
\ No newline at end of file
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/okhttp/OkHttpRibbonCommandFactoryTest.java
0 → 100644
View file @
8aeca9c2
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
.
okhttp
;
import
java.util.HashSet
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClient
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext
;
import
org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider
;
import
com.netflix.client.config.DefaultClientConfigImpl
;
import
com.netflix.client.config.IClientConfig
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* @author Ryan Baxter
*/
public
class
OkHttpRibbonCommandFactoryTest
{
SpringClientFactory
springClientFactory
;
ZuulProperties
zuulProperties
;
OkHttpRibbonCommandFactory
commandFactory
;
@Before
public
void
setup
()
{
this
.
springClientFactory
=
mock
(
SpringClientFactory
.
class
);
this
.
zuulProperties
=
new
ZuulProperties
();
OkHttpLoadBalancingClient
loadBalancingHttpClient
=
mock
(
OkHttpLoadBalancingClient
.
class
);
IClientConfig
clientConfig
=
new
DefaultClientConfigImpl
();
doReturn
(
loadBalancingHttpClient
).
when
(
this
.
springClientFactory
).
getClient
(
anyString
(),
eq
(
OkHttpLoadBalancingClient
.
class
));
doReturn
(
clientConfig
).
when
(
this
.
springClientFactory
).
getClientConfig
(
anyString
());
commandFactory
=
new
OkHttpRibbonCommandFactory
(
springClientFactory
,
zuulProperties
,
new
HashSet
<
ZuulFallbackProvider
>());
}
@Test
public
void
testHystrixTimeoutValue
()
throws
Exception
{
RibbonCommandContext
context
=
mock
(
RibbonCommandContext
.
class
);
doReturn
(
"service"
).
when
(
context
).
getServiceId
();
OkHttpRibbonCommand
ribbonCommand
=
this
.
commandFactory
.
create
(
context
);
assertEquals
(
2000
,
ribbonCommand
.
getProperties
().
executionTimeoutInMilliseconds
().
get
().
intValue
());
}
}
\ No newline at end of file
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