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
31b617b1
Commit
31b617b1
authored
Mar 06, 2017
by
Biju Kunjummen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed formatting issues, added more tests
parent
a6fe648a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
164 additions
and
6 deletions
+164
-6
SpringClientFactory.java
...ngframework/cloud/netflix/ribbon/SpringClientFactory.java
+3
-2
ZuulConfiguration.java
...springframework/cloud/netflix/zuul/ZuulConfiguration.java
+1
-1
RibbonApplicationContextInitializerTests.java
...flix/ribbon/RibbonApplicationContextInitializerTests.java
+0
-3
EagerLoadOfZuulConfigurationTests.java
...zuul/filters/route/EagerLoadOfZuulConfigurationTests.java
+59
-0
LazyLoadOfZuulConfigurationTests.java
.../zuul/filters/route/LazyLoadOfZuulConfigurationTests.java
+101
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java
View file @
31b617b1
...
@@ -86,8 +86,7 @@ public class SpringClientFactory extends NamedContextFactory<RibbonClientSpecifi
...
@@ -86,8 +86,7 @@ public class SpringClientFactory extends NamedContextFactory<RibbonClientSpecifi
try
{
try
{
Constructor
<
C
>
constructor
=
clazz
.
getConstructor
(
IClientConfig
.
class
);
Constructor
<
C
>
constructor
=
clazz
.
getConstructor
(
IClientConfig
.
class
);
result
=
constructor
.
newInstance
(
config
);
result
=
constructor
.
newInstance
(
config
);
}
}
catch
(
Throwable
e
)
{
catch
(
Throwable
e
)
{
// Ignored
// Ignored
}
}
...
@@ -120,4 +119,6 @@ public class SpringClientFactory extends NamedContextFactory<RibbonClientSpecifi
...
@@ -120,4 +119,6 @@ public class SpringClientFactory extends NamedContextFactory<RibbonClientSpecifi
protected
AnnotationConfigApplicationContext
getContext
(
String
name
)
{
protected
AnnotationConfigApplicationContext
getContext
(
String
name
)
{
return
super
.
getContext
(
name
);
return
super
.
getContext
(
name
);
}
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulConfiguration.java
View file @
31b617b1
...
@@ -164,7 +164,7 @@ public class ZuulConfiguration {
...
@@ -164,7 +164,7 @@ public class ZuulConfiguration {
}
}
@Bean
@Bean
@ConditionalOnProperty
(
value
=
"zuul.
context.startup.enable
d"
,
matchIfMissing
=
false
)
@ConditionalOnProperty
(
value
=
"zuul.
ribbon.eager-loa
d"
,
matchIfMissing
=
false
)
public
ZuulRouteApplicationContextInitializer
zuulRoutesApplicationContextInitiazer
(
public
ZuulRouteApplicationContextInitializer
zuulRoutesApplicationContextInitiazer
(
SpringClientFactory
springClientFactory
)
{
SpringClientFactory
springClientFactory
)
{
return
new
ZuulRouteApplicationContextInitializer
(
springClientFactory
,
return
new
ZuulRouteApplicationContextInitializer
(
springClientFactory
,
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonApplicationContextInitializerTests.java
View file @
31b617b1
...
@@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration
;
import
org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.annotation.DirtiesContext
;
...
@@ -16,7 +15,6 @@ import java.util.Arrays;
...
@@ -16,7 +15,6 @@ import java.util.Arrays;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
boot
.
test
.
util
.
EnvironmentTestUtils
.
addEnvironment
;
/**
/**
* @author Biju Kunjummen
* @author Biju Kunjummen
...
@@ -43,7 +41,6 @@ public class RibbonApplicationContextInitializerTests {
...
@@ -43,7 +41,6 @@ public class RibbonApplicationContextInitializerTests {
assertThat
(
foo
).
isNotNull
();
assertThat
(
foo
).
isNotNull
();
}
}
@Configuration
static
class
FooConfig
{
static
class
FooConfig
{
@Bean
@Bean
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/EagerLoadOfZuulConfigurationTests.java
0 → 100644
View file @
31b617b1
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.cloud.netflix.ribbon.RibbonClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonClients
;
import
org.springframework.cloud.netflix.zuul.EnableZuulProxy
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
value
=
{
"zuul.routes.myroute.service-id=eager"
,
"zuul.ribbon.eager-load=true"
})
@DirtiesContext
public
class
EagerLoadOfZuulConfigurationTests
{
@Test
public
void
testEagerLoading
()
{
// Child context FooConfig should have been eagerly instantiated..
assertThat
(
Foo
.
getInstanceCount
()).
isEqualTo
(
1
);
}
@EnableAutoConfiguration
@Configuration
@EnableZuulProxy
@RibbonClients
(
@RibbonClient
(
name
=
"eager"
,
configuration
=
FooConfig
.
class
))
static
class
TestConfig
{
}
static
class
Foo
{
private
static
final
AtomicInteger
INSTANCE_COUNT
=
new
AtomicInteger
();
public
Foo
()
{
INSTANCE_COUNT
.
incrementAndGet
();
}
public
static
int
getInstanceCount
()
{
return
INSTANCE_COUNT
.
get
();
}
}
static
class
FooConfig
{
@Bean
public
Foo
foo
()
{
return
new
Foo
();
}
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/LazyLoadOfZuulConfigurationTests.java
0 → 100644
View file @
31b617b1
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.cloud.netflix.ribbon.RibbonClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonClients
;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
import
org.springframework.cloud.netflix.zuul.EnableZuulProxy
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"zuul.routes.myroute.service-id=eager"
,
"zuul.routes.myroute.path=/eager/**"
})
@DirtiesContext
public
class
LazyLoadOfZuulConfigurationTests
{
@Value
(
"${local.server.port}"
)
protected
int
port
;
@Test
public
void
testEagerLoading
()
{
// Child context FooConfig should be lazily created..
assertThat
(
Foo
.
getInstanceCount
()).
isEqualTo
(
0
);
String
uri
=
String
.
format
(
"http://localhost:%d/eager/sample"
,
this
.
port
);
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
getForEntity
(
uri
,
String
.
class
);
// the instance should be available now..
assertThat
(
Foo
.
getInstanceCount
()).
isEqualTo
(
1
);
assertThat
(
result
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
result
.
getBody
()).
isEqualTo
(
"sample"
);
}
@EnableAutoConfiguration
@Configuration
@EnableZuulProxy
@RibbonClients
(
@RibbonClient
(
name
=
"eager"
,
configuration
=
FooConfig
.
class
))
static
class
TestConfig
{
}
static
class
Foo
{
private
static
final
AtomicInteger
INSTANCE_COUNT
=
new
AtomicInteger
();
public
Foo
()
{
INSTANCE_COUNT
.
incrementAndGet
();
}
public
static
int
getInstanceCount
()
{
return
INSTANCE_COUNT
.
get
();
}
}
static
class
FooConfig
{
@Bean
public
Foo
foo
()
{
return
new
Foo
();
}
@Value
(
"${local.server.port}"
)
private
int
port
;
@Bean
public
ServerList
<
Server
>
ribbonServerList
()
{
return
new
StaticServerList
<>(
new
Server
(
"localhost"
,
this
.
port
));
}
}
@Configuration
@RestController
static
class
SampleWebConfig
{
@RequestMapping
(
"/sample"
)
public
String
sampleEndpoint
()
{
return
"sample"
;
}
}
}
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