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
cd42566d
Commit
cd42566d
authored
Mar 25, 2016
by
Marcin Grzejszczak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for HystrixStream
parent
5d2065b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
1 deletion
+72
-1
HystrixStreamTask.java
...ework/cloud/netflix/hystrix/stream/HystrixStreamTask.java
+2
-1
HystrixStreamTaskTests.java
.../cloud/netflix/hystrix/stream/HystrixStreamTaskTests.java
+70
-0
No files found.
spring-cloud-netflix-hystrix-stream/src/main/java/org/springframework/cloud/netflix/hystrix/stream/HystrixStreamTask.java
View file @
cd42566d
...
...
@@ -67,7 +67,8 @@ public class HystrixStreamTask implements ApplicationContextAware {
@Autowired
private
HystrixStreamProperties
properties
;
private
final
LinkedBlockingQueue
<
String
>
jsonMetrics
=
new
LinkedBlockingQueue
<>(
// Visible for testing
final
LinkedBlockingQueue
<
String
>
jsonMetrics
=
new
LinkedBlockingQueue
<>(
1000
);
private
final
JsonFactory
jsonFactory
=
new
JsonFactory
();
...
...
spring-cloud-netflix-hystrix-stream/src/test/java/org/springframework/cloud/netflix/hystrix/stream/HystrixStreamTaskTests.java
0 → 100644
View file @
cd42566d
package
org
.
springframework
.
cloud
.
netflix
.
hystrix
.
stream
;
import
com.netflix.hystrix.HystrixCommandGroupKey
;
import
com.netflix.hystrix.HystrixCommandKey
;
import
com.netflix.hystrix.HystrixCommandMetrics
;
import
com.netflix.hystrix.HystrixCommandProperties
;
import
com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.BDDMockito
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.Spy
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.messaging.Message
;
import
org.springframework.messaging.MessageChannel
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
then
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
verifyZeroInteractions
;
/**
* @author Marcin Grzejszczak
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
HystrixStreamTaskTests
{
@Mock
MessageChannel
outboundChannel
;
@Mock
DiscoveryClient
discoveryClient
;
@Mock
ApplicationContext
context
;
@Spy
HystrixStreamProperties
properties
;
@Mock
ServiceInstance
serviceInstance
;
@InjectMocks
HystrixStreamTask
hystrixStreamTask
;
@Test
public
void
should_not_send_metrics_when_they_are_empty
()
throws
Exception
{
this
.
hystrixStreamTask
.
sendMetrics
();
verifyZeroInteractions
(
this
.
outboundChannel
);
}
@Test
public
void
should_send_metrics_when_they_are_not_empty
()
throws
Exception
{
this
.
hystrixStreamTask
.
jsonMetrics
.
put
(
"someJson"
);
this
.
hystrixStreamTask
.
sendMetrics
();
then
(
this
.
outboundChannel
).
should
().
send
(
any
(
Message
.
class
));
}
@Test
public
void
should_gather_json_metrics
()
throws
Exception
{
HystrixCommandKey
hystrixCommandKey
=
HystrixCommandKey
.
Factory
.
asKey
(
"commandKey"
);
HystrixCommandMetrics
.
getInstance
(
hystrixCommandKey
,
HystrixCommandGroupKey
.
Factory
.
asKey
(
"commandGroupKey"
),
new
HystrixPropertiesCommandDefault
(
hystrixCommandKey
,
HystrixCommandProperties
.
defaultSetter
()));
given
(
this
.
discoveryClient
.
getLocalServiceInstance
()).
willReturn
(
this
.
serviceInstance
);
this
.
hystrixStreamTask
.
gatherMetrics
();
assertThat
(
this
.
hystrixStreamTask
.
jsonMetrics
.
isEmpty
(),
is
(
false
));
}
}
\ 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