Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
WebFluxApp
Project
Project
Details
Activity
Releases
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
Syed Javed Ali
WebFluxApp
Commits
622395b4
Commit
622395b4
authored
Feb 09, 2021
by
Syed Javed Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test cases for Mono
parent
39e00913
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
5 deletions
+55
-5
FluxAndMonoController.java
.../java/com/nisum/app/controller/FluxAndMonoController.java
+21
-5
FluxAndMonoControllerTest.java
...a/com/nisum/app/controller/FluxAndMonoControllerTest.java
+34
-0
No files found.
src/main/java/com/nisum/app/controller/FluxAndMonoController.java
View file @
622395b4
...
@@ -4,6 +4,7 @@ import org.springframework.http.MediaType;
...
@@ -4,6 +4,7 @@ import org.springframework.http.MediaType;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
java.time.Duration
;
import
java.time.Duration
;
...
@@ -12,31 +13,46 @@ public class FluxAndMonoController {
...
@@ -12,31 +13,46 @@ public class FluxAndMonoController {
//This will return all data at a time not event by event
//This will return all data at a time not event by event
// (internally following events but not visible on postman)
// (internally following events but not visible on postman)
/*
@GetMapping("/flux")
@GetMapping
(
"/flux"
)
public
Flux
<
Integer
>
getFlux
(){
public
Flux
<
Integer
>
getFlux
(){
return
Flux
.
just
(
1
,
2
,
3
,
4
)
return
Flux
.
just
(
1
,
2
,
3
,
4
)
.
log
();
.
log
();
}
*/
}
//In this case every event is emitted after one sec
//In this case every event is emitted after one sec
// but in postman it gives all data after 4 sec becoz it assume it is JSON response
// but in postman it gives all data after 4 sec becoz it assume it is JSON response
@GetMapping
(
"/flux"
)
/*
@GetMapping("/flux")
public Flux<Integer> getFlux(){
public Flux<Integer> getFlux(){
return Flux.just(1,2,3,4)
return Flux.just(1,2,3,4)
.delayElements(Duration.ofSeconds(1))
.delayElements(Duration.ofSeconds(1))
.log();
.log();
}
}
*/
//we can get events after 1 sec
//we can get events after 1 sec
@GetMapping
(
value
=
"/fluxstream"
/*
@GetMapping(value = "/fluxstream"
,produces = MediaType.APPLICATION_NDJSON_VALUE)
,produces = MediaType.APPLICATION_NDJSON_VALUE)
public Flux<Integer> getFluxStream(){
public Flux<Integer> getFluxStream(){
return Flux.just(1,2,3,4)
return Flux.just(1,2,3,4)
.delayElements(Duration.ofSeconds(1))
.delayElements(Duration.ofSeconds(1))
.log();
.log();
}*/
@GetMapping
(
value
=
"/fluxstream"
,
produces
=
MediaType
.
APPLICATION_STREAM_JSON_VALUE
)
public
Flux
<
Long
>
getFluxStream
(){
return
Flux
.
interval
(
Duration
.
ofSeconds
(
1
))
.
log
();
}
@GetMapping
(
"/mono"
)
public
Mono
<
Integer
>
getMono
(){
return
Mono
.
just
(
1
)
.
log
();
}
}
}
}
src/test/java/com/nisum/app/controller/FluxAndMonoControllerTest.java
View file @
622395b4
...
@@ -88,4 +88,38 @@ public class FluxAndMonoControllerTest {
...
@@ -88,4 +88,38 @@ public class FluxAndMonoControllerTest {
(
expectedIntegerList
,
response
.
getResponseBody
());
(
expectedIntegerList
,
response
.
getResponseBody
());
});
});
}
}
//for checking infinite elements emitted from flux
@Test
public
void
fluxStream
(){
Flux
<
Long
>
longFlux
=
webTestClient
.
get
().
uri
(
"/fluxstream"
)
.
accept
(
MediaType
.
APPLICATION_STREAM_JSON
)
.
exchange
()
.
expectStatus
().
isOk
()
.
returnResult
(
Long
.
class
)
.
getResponseBody
();
StepVerifier
.
create
(
longFlux
)
.
expectNext
(
0
l
)
.
expectNext
(
1
l
)
.
expectNext
(
2
l
)
.
thenCancel
()
.
verify
();
}
//to check for mono
@Test
public
void
mono
(){
Integer
expectedValue
=
new
Integer
(
1
);
webTestClient
.
get
().
uri
(
"/mono"
)
.
accept
(
MediaType
.
APPLICATION_JSON_UTF8
)
.
exchange
()
.
expectStatus
().
isOk
()
.
expectBody
(
Integer
.
class
)
.
consumeWith
(
response
->{
assertEquals
(
expectedValue
,
response
.
getResponseBody
());
});
}
}
}
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