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
c6a00c1a
Unverified
Commit
c6a00c1a
authored
Oct 24, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move to proper reactor testing
parent
a67a0779
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
35 deletions
+39
-35
HystrixCommandsTests.java
...framework/cloud/netflix/hystrix/HystrixCommandsTests.java
+39
-35
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCommandsTests.java
View file @
c6a00c1a
...
...
@@ -17,63 +17,63 @@
package
org
.
springframework
.
cloud
.
netflix
.
hystrix
;
import
java.time.Duration
;
import
java.util.List
;
import
com.netflix.hystrix.exception.HystrixRuntimeException
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
com.netflix.hystrix.exception.HystrixRuntimeException
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
reactor.core.scheduler.Schedulers
;
import
reactor.test.StepVerifier
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
HystrixCommandsTests
{
@Rule
public
ExpectedException
exception
=
ExpectedException
.
none
();
@Test
public
void
monoWorks
()
{
String
result
=
HystrixCommands
.
from
(
Mono
.
just
(
"works"
)).
commandName
(
"testworks"
).
toMono
().
block
();
assertThat
(
result
).
isEqualTo
(
"works"
);
StepVerifier
.
create
(
HystrixCommands
.
from
(
Flux
.
just
(
"works"
))
.
commandName
(
"testworks"
)
.
toMono
())
.
expectNext
(
"works"
)
.
verifyComplete
();
}
@Test
public
void
eagerMonoWorks
()
{
String
result
=
HystrixCommands
.
from
(
Mono
.
just
(
"works"
))
.
eager
()
.
commandName
(
"testworks"
)
.
toMono
().
block
();
assertThat
(
result
).
isEqualTo
(
"works"
);
StepVerifier
.
create
(
HystrixCommands
.
from
(
Mono
.
just
(
"works"
))
.
eager
()
.
commandName
(
"testworks"
)
.
toMono
())
.
expectNext
(
"works"
)
.
verifyComplete
();
}
@Test
public
void
monoTimesOut
()
{
exception
.
expect
(
HystrixRuntimeException
.
class
);
HystrixCommands
.
from
(
Mono
.
fromCallable
(()
->
{
StepVerifier
.
create
(
HystrixCommands
.
from
(
Mono
.
fromCallable
(()
->
{
Thread
.
sleep
(
1500
);
return
"timeout"
;
})).
commandName
(
"failcmd"
).
toMono
().
block
();
})).
commandName
(
"failcmd"
).
toMono
())
.
expectError
(
HystrixRuntimeException
.
class
);
}
@Test
public
void
monoFallbackWorks
()
{
St
ring
result
=
HystrixCommands
.
from
(
Mono
.<
String
>
error
(
new
Exception
()))
St
epVerifier
.
create
(
HystrixCommands
.
from
(
Mono
.<
String
>
error
(
new
Exception
()))
.
commandName
(
"failcmd"
)
.
fallback
(
Mono
.
just
(
"fallback"
))
.
toMono
().
block
();
assertThat
(
result
).
isEqualTo
(
"fallback"
);
.
toMono
())
.
expectNext
(
"fallback"
)
.
verifyComplete
();
}
@Test
public
void
fluxWorks
()
{
List
<
String
>
list
=
HystrixCommands
.
from
(
Flux
.
just
(
"1"
,
"2"
))
StepVerifier
.
create
(
HystrixCommands
.
from
(
Flux
.
just
(
"1"
,
"2"
))
.
commandName
(
"multiflux"
)
.
toFlux
().
collectList
().
block
();
assertThat
(
list
).
hasSize
(
2
).
contains
(
"1"
,
"2"
);
.
toFlux
())
.
expectNext
(
"1"
)
.
expectNext
(
"2"
)
.
verifyComplete
();
}
@Test
...
...
@@ -90,32 +90,36 @@ public class HystrixCommandsTests {
@Test
public
void
eagerFluxWorks
()
{
List
<
String
>
list
=
HystrixCommands
.
from
(
Flux
.
just
(
"1"
,
"2"
))
StepVerifier
.
create
(
HystrixCommands
.
from
(
Flux
.
just
(
"1"
,
"2"
))
.
commandName
(
"multiflux"
)
.
eager
()
.
toFlux
().
collectList
().
block
();
assertThat
(
list
).
hasSize
(
2
).
contains
(
"1"
,
"2"
);
.
toFlux
())
.
expectNext
(
"1"
)
.
expectNext
(
"2"
)
.
verifyComplete
();
}
@Test
public
void
fluxTimesOut
()
{
exception
.
expect
(
HystrixRuntimeException
.
class
);
HystrixCommands
.
from
(
Flux
.
from
(
s
->
{
StepVerifier
.
create
(
HystrixCommands
.
from
(
Flux
.
from
(
s
->
{
try
{
Thread
.
sleep
(
1500
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
})).
commandName
(
"failcmd"
).
toFlux
().
blockFirst
();
})).
commandName
(
"failcmd"
).
toFlux
())
.
expectError
(
HystrixRuntimeException
.
class
);
}
@Test
public
void
fluxFallbackWorks
()
{
List
<
String
>
list
=
HystrixCommands
.
from
(
Flux
.<
String
>
error
(
new
Exception
()))
StepVerifier
.
create
(
HystrixCommands
.
from
(
Flux
.<
String
>
error
(
new
Exception
()))
.
commandName
(
"multiflux"
)
.
fallback
(
Flux
.
just
(
"a"
,
"b"
))
.
toFlux
().
collectList
().
block
();
assertThat
(
list
).
hasSize
(
2
).
contains
(
"a"
,
"b"
);
.
toFlux
())
.
expectNext
(
"a"
)
.
expectNext
(
"b"
)
.
verifyComplete
();
}
}
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