Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
reactor-api-sample
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
vikram singh
reactor-api-sample
Commits
3fa0f01c
Commit
3fa0f01c
authored
Apr 06, 2020
by
vikram singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
did the required changes based on second review
parent
335be7ee
Changes
24
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
106 additions
and
100 deletions
+106
-100
KafkaProducerConfig.java
...in/java/com/nisum/webflux/config/KafkaProducerConfig.java
+0
-2
KafkaServer.java
src/main/java/com/nisum/webflux/config/KafkaServer.java
+1
-1
EmployeeController.java
...java/com/nisum/webflux/controller/EmployeeController.java
+13
-13
FruitController.java
...in/java/com/nisum/webflux/controller/FruitController.java
+2
-2
SampleController.java
...n/java/com/nisum/webflux/controller/SampleController.java
+1
-1
Employee.java
src/main/java/com/nisum/webflux/model/Employee.java
+0
-1
Hobby.java
src/main/java/com/nisum/webflux/model/Hobby.java
+0
-1
EmployeeService.java
.../java/com/nisum/webflux/service/impl/EmployeeService.java
+5
-5
FruitService.java
...ain/java/com/nisum/webflux/service/impl/FruitService.java
+1
-1
Logging.java
src/main/java/com/nisum/webflux/service/impl/Logging.java
+0
-17
OperationService.java
...java/com/nisum/webflux/service/impl/OperationService.java
+1
-1
AdvancedConcept_Schedular_test.java
...ebflux/basicOperators/AdvancedConcept_Schedular_test.java
+26
-20
Basic_Flux_Mono_Test.java
...om/nisum/webflux/basicOperators/Basic_Flux_Mono_Test.java
+7
-2
ColdAndHotPublisherTest.java
...nisum/webflux/basicOperators/ColdAndHotPublisherTest.java
+8
-4
FluxAndMonoBackPressureTest.java
...m/webflux/basicOperators/FluxAndMonoBackPressureTest.java
+12
-7
FluxAndMonoErrorTest.java
...om/nisum/webflux/basicOperators/FluxAndMonoErrorTest.java
+5
-1
FluxAndMonoFactoryTest.java
.../nisum/webflux/basicOperators/FluxAndMonoFactoryTest.java
+5
-1
FluxAndMonoWithTimeTest.java
...nisum/webflux/basicOperators/FluxAndMonoWithTimeTest.java
+4
-1
EmployeeControllerComponentTest.java
...m/webflux/controller/EmployeeControllerComponentTest.java
+2
-2
EmployeeControllerIntegrationTest.java
...webflux/controller/EmployeeControllerIntegrationTest.java
+6
-7
FruitControllerComponentTest.java
...isum/webflux/controller/FruitControllerComponentTest.java
+2
-2
FruitControllerIntegrationTest.java
...um/webflux/controller/FruitControllerIntegrationTest.java
+1
-3
EmployeeServiceTest.java
...a/com/nisum/webflux/service/impl/EmployeeServiceTest.java
+2
-3
TestConfig.java
src/test/java/com/nisum/webflux/service/impl/TestConfig.java
+2
-2
No files found.
src/main/java/com/nisum/webflux/config/KafkaProducerConfig.java
View file @
3fa0f01c
...
...
@@ -20,8 +20,6 @@ import java.util.Map;
@Configuration
@Component
public
class
KafkaProducerConfig
{
@Autowired
private
KafkaProperties
kafkaProperties
;
...
...
src/main/java/com/nisum/webflux/config/KafkaServer.java
View file @
3fa0f01c
...
...
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Service;
public
class
KafkaServer
{
@Autowired
KafkaTemplate
<
String
,
String
>
template
;
private
KafkaTemplate
<
String
,
String
>
template
;
@Value
(
"${com.kafka.topic}"
)
private
String
topic
;
...
...
src/main/java/com/nisum/webflux/controller/EmployeeController.java
View file @
3fa0f01c
...
...
@@ -13,13 +13,13 @@ import reactor.core.publisher.Mono;
public
class
EmployeeController
{
@Autowired
IEmployeeService
employeeService
;
private
IEmployeeService
employeeService
;
@PostMapping
(
"/employee"
)
public
Mono
<
Employee
>
save
(
@RequestBody
Employee
employee
)
{
log
.
info
(
"employee obj
##################################################
"
+
employee
);
log
.
info
(
"employee obj "
+
employee
);
return
employeeService
.
save
(
employee
);
}
...
...
@@ -38,28 +38,28 @@ public class EmployeeController {
@GetMapping
(
"/employee/byCity"
)
public
Flux
<
Employee
>
findByCity
(
@RequestParam
String
city
){
return
employeeService
.
findByCity
(
city
);
}
@GetMapping
(
"/employee/byHobby"
)
public
Flux
<
Employee
>
findByHobbyName
(
@RequestParam
String
hobbyName
){
return
employeeService
.
findByHobbyName
(
hobbyName
);
}
}
@GetMapping
(
"/employee/byNameAndHobby"
)
public
Flux
<
Employee
>
findByNameAndHobbyName
(
@RequestParam
String
name
,
@RequestParam
String
hobbyName
){
return
employeeService
.
findByNameAndHobbyName
(
name
,
hobbyName
);
String
name
,
@RequestParam
String
hobbyName
){
return
employeeService
.
findByNameAndHobbyName
(
name
,
hobbyName
);
}
@GetMapping
(
"/employee/byNameAndCityAndHobby"
)
public
Flux
<
Employee
>
findByNameAndCityAndHobby
(
@RequestParam
String
name
,
@RequestParam
String
cityName
,
@RequestParam
String
hobbyName
){
String
name
,
@RequestParam
String
cityName
,
@RequestParam
String
hobbyName
){
return
employeeService
.
findByNameAndCityAndHobby
(
name
,
cityName
,
hobbyName
);
}
}
src/main/java/com/nisum/webflux/controller/FruitController.java
View file @
3fa0f01c
...
...
@@ -25,10 +25,10 @@ public class FruitController {
private
String
topic
;
@Autowired
IFruitService
fruitService
;
private
IFruitService
fruitService
;
@Autowired
OperationService
operationService
;
private
OperationService
operationService
;
@Qualifier
(
"simpleProducer"
)
...
...
src/main/java/com/nisum/webflux/controller/SampleController.java
View file @
3fa0f01c
...
...
@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
//basic kafka
public
class
SampleController
{
@Autowired
KafkaServer
kafkaServer
;
private
KafkaServer
kafkaServer
;
@GetMapping
(
"/send"
)
public
String
producer
(
@RequestParam
...
...
src/main/java/com/nisum/webflux/model/Employee.java
View file @
3fa0f01c
...
...
@@ -10,7 +10,6 @@ import java.util.List;
@Setter
@Getter
@ToString
//@ToString(exclude= {"id","dob"})
@NoArgsConstructor
@AllArgsConstructor
@Document
...
...
src/main/java/com/nisum/webflux/model/Hobby.java
View file @
3fa0f01c
...
...
@@ -9,7 +9,6 @@ import org.springframework.data.annotation.Id;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
Hobby
{
@Id
private
String
hobbyId
;
...
...
src/main/java/com/nisum/webflux/service/impl/EmployeeService.java
View file @
3fa0f01c
...
...
@@ -20,7 +20,7 @@ import java.util.List;
@Slf4j
public
class
EmployeeService
implements
IEmployeeService
{
@Autowired
EmployeeRepo
empRepo
;
private
EmployeeRepo
empRepo
;
@Override
public
Mono
<
Employee
>
save
(
Employee
employee
)
{
...
...
@@ -49,19 +49,19 @@ public class EmployeeService implements IEmployeeService{
@Override
public
Flux
<
Employee
>
findByName
(
String
name
)
{
return
empRepo
.
findByName
(
name
);
}
@Override
public
Flux
<
Employee
>
findByCity
(
String
city
)
{
return
empRepo
.
findByCity
(
city
);
}
@Override
public
Flux
<
Employee
>
findByHobbyName
(
String
hobbyName
)
{
return
empRepo
.
findbyHobbyName
(
hobbyName
);
}
...
...
@@ -72,7 +72,7 @@ public class EmployeeService implements IEmployeeService{
@Override
public
Flux
<
Employee
>
findByNameAndCityAndHobby
(
String
name
,
String
cityName
,
String
hobbyName
)
{
return
empRepo
.
findByNameAndCityAndHobby
(
name
,
cityName
,
hobbyName
);
}
...
...
src/main/java/com/nisum/webflux/service/impl/FruitService.java
View file @
3fa0f01c
...
...
@@ -23,7 +23,7 @@ import java.util.stream.Collectors;
public
class
FruitService
implements
IFruitService
{
@Autowired
FruitRepository
fruitRepository
;
private
FruitRepository
fruitRepository
;
@Override
public
Mono
<
Fruit
>
save
(
Fruit
fruit
)
{
...
...
src/main/java/com/nisum/webflux/service/impl/Logging.java
deleted
100755 → 0
View file @
335be7ee
package
com
.
nisum
.
webflux
.
service
.
impl
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
@Aspect
public
class
Logging
{
@Pointcut
(
"execution(* com.nisum.*.*(..))"
)
private
void
selectAll
(){}
@Before
(
"selectAll()"
)
public
void
beforeAdvice
(){
System
.
out
.
println
(
"Going to Call desired Method"
);
}
}
src/main/java/com/nisum/webflux/service/impl/OperationService.java
View file @
3fa0f01c
...
...
@@ -11,7 +11,7 @@ import reactor.core.publisher.Mono;
public
class
OperationService
{
@Autowired
NameService
nameService
;
private
NameService
nameService
;
public
Mono
<
Fruit
>
operate
(
Fruit
fruit
)
{
log
.
info
(
"Into operate method of OperationService"
+
fruit
);
...
...
src/test/java/com/nisum/webflux/basicOperators/AdvancedConcept_Schedular_test.java
View file @
3fa0f01c
package
com
.
nisum
.
webflux
.
basicOperators
;
import
org.springframework.stereotype.Service
;
import
reactor.core.publisher.Flux
;
import
reactor.core.scheduler.Schedulers
;
import
java.util.logging.Logger
;
//link:http://www.vinsguru.com/reactive-programming-schedulers/
/**
...
...
@@ -13,10 +16,13 @@ import reactor.core.scheduler.Schedulers;
* • boundedElastic(): Optimized for longer executions, an alternative for blocking tasks where the number of active tasks (and threads) is capped
* • immediate(): to immediately run submitted Runnable instead of scheduling them (somewhat of a no-op or "null object" Scheduler)
*/
@Service
public
class
AdvancedConcept_Schedular_test
{
// SimplePublisher
private
final
static
Logger
log
=
Logger
.
getLogger
(
Logger
.
GLOBAL_LOGGER_NAME
);
// SimplePublisher
public
static
void
main
(
String
args
[])
{
...
...
@@ -87,7 +93,7 @@ public class AdvancedConcept_Schedular_test {
private
static
void
simplePublisher
()
{
Flux
<
Integer
>
flux
=
Flux
.
range
(
0
,
2
)
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
});
...
...
@@ -98,7 +104,7 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
}
...
...
@@ -107,7 +113,7 @@ public class AdvancedConcept_Schedular_test {
Flux
<
Integer
>
flux
=
Flux
.
range
(
0
,
2
)
.
publishOn
(
Schedulers
.
immediate
())
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
});
...
...
@@ -118,7 +124,7 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
}
...
...
@@ -126,7 +132,7 @@ public class AdvancedConcept_Schedular_test {
Flux
<
Integer
>
flux
=
Flux
.
range
(
0
,
2
)
.
publishOn
(
Schedulers
.
single
())
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
});
...
...
@@ -137,7 +143,7 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
}
...
...
@@ -153,7 +159,7 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
}
...
...
@@ -169,7 +175,7 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
}
...
...
@@ -185,24 +191,24 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
}
private
static
void
multiplePublishOnMethods
(){
Flux
<
Integer
>
flux
=
Flux
.
range
(
0
,
2
)
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping one for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping one for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
})
.
publishOn
(
Schedulers
.
boundedElastic
())
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping two for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping two for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
})
.
publishOn
(
Schedulers
.
parallel
())
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping three for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping three for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
});
Runnable
r
=
getRunnable
(
flux
);
...
...
@@ -210,7 +216,7 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
...
...
@@ -219,17 +225,17 @@ public class AdvancedConcept_Schedular_test {
private
static
void
multiplePublishOnMethodsUsingSubscribeOn
(){
Flux
<
Integer
>
flux
=
Flux
.
range
(
0
,
2
)
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping one for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping one for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
})
.
publishOn
(
Schedulers
.
boundedElastic
())
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping two for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping two for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
})
.
publishOn
(
Schedulers
.
parallel
())
.
map
(
i
->
{
System
.
out
.
println
(
"Mapping three for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Mapping three for "
+
i
+
" is done by thread "
+
Thread
.
currentThread
().
getName
());
return
i
;
});
...
...
@@ -242,7 +248,7 @@ public class AdvancedConcept_Schedular_test {
Runnable
r
=
()
->
flux
.
subscribeOn
(
Schedulers
.
single
())
.
subscribe
(
s
->
{
System
.
out
.
println
(
"Received "
+
s
+
" via "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Received "
+
s
+
" via "
+
Thread
.
currentThread
().
getName
());
});
...
...
@@ -253,7 +259,7 @@ public class AdvancedConcept_Schedular_test {
Thread
t2
=
new
Thread
(
r
,
"t2"
);
//lets start the threads. (this is when we are subscribing to the flux)
System
.
out
.
println
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Program thread :: "
+
Thread
.
currentThread
().
getName
());
t1
.
start
();
t2
.
start
();
...
...
@@ -262,7 +268,7 @@ public class AdvancedConcept_Schedular_test {
private
static
Runnable
getRunnable
(
Flux
<
Integer
>
flux
)
{
return
()
->
flux
.
subscribe
(
s
->
{
System
.
out
.
println
(
"Received "
+
s
+
" via "
+
Thread
.
currentThread
().
getName
());
log
.
info
(
"Received "
+
s
+
" via "
+
Thread
.
currentThread
().
getName
());
});
}
...
...
src/test/java/com/nisum/webflux/basicOperators/Basic_Flux_Mono_Test.java
View file @
3fa0f01c
...
...
@@ -5,8 +5,13 @@ import reactor.core.publisher.Flux;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
import
java.util.logging.Logger
;
//check java controllers also to understand it more clearly;
public
class
Basic_Flux_Mono_Test
{
private
final
static
Logger
log
=
Logger
.
getLogger
(
Logger
.
GLOBAL_LOGGER_NAME
);
/**
* flux with error
*
...
...
@@ -29,8 +34,8 @@ public class Basic_Flux_Mono_Test {
stringFlux
.
subscribe
(
System
.
out
::
println
,
(
e
)
->
System
.
err
.
println
(
"Exception is -> "
+
e
)
,
()
->
System
.
out
.
println
(
"Completed"
));
(
e
)
->
log
.
info
(
"Exception is -> "
+
e
)
,
()
->
log
.
info
(
"Completed"
));
}
@Test
...
...
src/test/java/com/nisum/webflux/basicOperators/ColdAndHotPublisherTest.java
View file @
3fa0f01c
...
...
@@ -4,12 +4,16 @@ import reactor.core.publisher.ConnectableFlux;
import
reactor.core.publisher.Flux
;
import
java.time.Duration
;
import
java.util.logging.Logger
;
/**
* Examples on Cold and hot publisher
* reference:::: http://www.vinsguru.com/reactive-programming-publisher-types-cold-vs-hot/
*/
public
class
ColdAndHotPublisherTest
{
private
final
static
Logger
log
=
Logger
.
getLogger
(
Logger
.
GLOBAL_LOGGER_NAME
);
/**
* cold publishers generates new data every time a new subscriber subscribes to them.
* Publishers by default do not produce any value unless at least 1 observer subscribes to it.
...
...
@@ -25,11 +29,11 @@ public class ColdAndHotPublisherTest {
Flux
<
String
>
stringFlux
=
Flux
.
just
(
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
)
.
delayElements
(
Duration
.
ofSeconds
(
1
));
stringFlux
.
subscribe
(
s
->
System
.
out
.
println
(
"Subscriber 1 : "
+
s
));
//emits the value from beginning
stringFlux
.
subscribe
(
s
->
log
.
info
(
"Subscriber 1 : "
+
s
));
//emits the value from beginning
Thread
.
sleep
(
2000
);
stringFlux
.
subscribe
(
s
->
System
.
out
.
println
(
"Subscriber 2 : "
+
s
));
//emits the value from beginning
stringFlux
.
subscribe
(
s
->
log
.
info
(
"Subscriber 2 : "
+
s
));
//emits the value from beginning
Thread
.
sleep
(
4000
);
...
...
@@ -51,10 +55,10 @@ public class ColdAndHotPublisherTest {
ConnectableFlux
<
String
>
connectableFlux
=
stringFlux
.
publish
();
connectableFlux
.
connect
();
connectableFlux
.
subscribe
(
s
->
System
.
out
.
println
(
"Subscriber 1 : "
+
s
));
connectableFlux
.
subscribe
(
s
->
log
.
info
(
"Subscriber 1 : "
+
s
));
Thread
.
sleep
(
3000
);
connectableFlux
.
subscribe
(
s
->
System
.
out
.
println
(
"Subscriber 2 : "
+
s
));
// does not emit the values from beginning
connectableFlux
.
subscribe
(
s
->
log
.
info
(
"Subscriber 2 : "
+
s
));
// does not emit the values from beginning
Thread
.
sleep
(
4000
);
}
...
...
src/test/java/com/nisum/webflux/basicOperators/FluxAndMonoBackPressureTest.java
View file @
3fa0f01c
...
...
@@ -5,6 +5,8 @@ import reactor.core.publisher.BaseSubscriber;
import
reactor.core.publisher.Flux
;
import
reactor.test.StepVerifier
;
import
java.util.logging.Logger
;
/**
* link : https://www.reactiveprogramming.be/project-reactor-backpressure/
* Understanding BackPressure concept
...
...
@@ -15,6 +17,9 @@ import reactor.test.StepVerifier;
* 2.cancel
*/
public
class
FluxAndMonoBackPressureTest
{
private
final
static
Logger
log
=
Logger
.
getLogger
(
Logger
.
GLOBAL_LOGGER_NAME
);
/**
* verifies the backPressure
*/
...
...
@@ -45,9 +50,9 @@ public class FluxAndMonoBackPressureTest {
Flux
<
Integer
>
finiteFlux
=
Flux
.
range
(
1
,
10
)
.
log
();
finiteFlux
.
subscribe
((
element
)
->
System
.
out
.
println
(
"Element is : "
+
element
)
,
(
e
)
->
System
.
err
.
println
(
"Exception is : "
+
e
)
,
()
->
System
.
out
.
println
(
"Done"
)
finiteFlux
.
subscribe
((
element
)
->
log
.
info
(
"Element is : "
+
element
)
,
(
e
)
->
log
.
info
(
"Exception is : "
+
e
)
,
()
->
log
.
info
(
"Done"
)
,
(
subscription
->
subscription
.
request
(
2
)));
}
...
...
@@ -61,9 +66,9 @@ public class FluxAndMonoBackPressureTest {
Flux
<
Integer
>
finiteFlux
=
Flux
.
range
(
1
,
10
)
.
log
();
finiteFlux
.
subscribe
((
element
)
->
System
.
out
.
println
(
"Element is : "
+
element
)
,
(
e
)
->
System
.
err
.
println
(
"Exception is : "
+
e
)
,
()
->
System
.
out
.
println
(
"Done"
)
finiteFlux
.
subscribe
((
element
)
->
log
.
info
(
"Element is : "
+
element
)
,
(
e
)
->
log
.
info
(
"Exception is : "
+
e
)
,
()
->
log
.
info
(
"Done"
)
,
(
subscription
->
subscription
.
cancel
()));
}
...
...
@@ -82,7 +87,7 @@ public class FluxAndMonoBackPressureTest {
@Override
protected
void
hookOnNext
(
Integer
value
)
{
request
(
1
);
System
.
out
.
println
(
"Value received is : "
+
value
);
log
.
info
(
"Value received is : "
+
value
);
if
(
value
==
4
){
cancel
();
}
...
...
src/test/java/com/nisum/webflux/basicOperators/FluxAndMonoErrorTest.java
View file @
3fa0f01c
...
...
@@ -5,6 +5,7 @@ import reactor.core.publisher.Flux;
import
reactor.test.StepVerifier
;
import
java.time.Duration
;
import
java.util.logging.Logger
;
/**
*
...
...
@@ -13,6 +14,9 @@ import java.time.Duration;
* understanding error operators
*/
public
class
FluxAndMonoErrorTest
{
private
final
static
Logger
log
=
Logger
.
getLogger
(
Logger
.
GLOBAL_LOGGER_NAME
);
/**
*
* onErrorResume method
...
...
@@ -26,7 +30,7 @@ public class FluxAndMonoErrorTest {
.
concatWith
(
Flux
.
error
(
new
RuntimeException
(
"Exception Occurred"
)))
.
concatWith
(
Flux
.
just
(
"D"
))
.
onErrorResume
((
e
)
->
{
// this block gets executed
System
.
out
.
println
(
"Exception is : "
+
e
);
log
.
info
(
"Exception is : "
+
e
);
return
Flux
.
just
(
"default"
,
"default1"
);
});
...
...
src/test/java/com/nisum/webflux/basicOperators/FluxAndMonoFactoryTest.java
View file @
3fa0f01c
...
...
@@ -8,6 +8,7 @@ import reactor.test.StepVerifier;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.function.Supplier
;
import
java.util.logging.Logger
;
/**
* check java controllers/services also to understand it more clearly;
...
...
@@ -15,6 +16,9 @@ import java.util.function.Supplier;
*/
public
class
FluxAndMonoFactoryTest
{
private
final
static
Logger
log
=
Logger
.
getLogger
(
Logger
.
GLOBAL_LOGGER_NAME
);
List
<
String
>
names
=
Arrays
.
asList
(
"adam"
,
"anna"
,
"jack"
,
"jenny"
);
/**
...
...
@@ -83,7 +87,7 @@ public class FluxAndMonoFactoryTest {
Mono
<
String
>
stringMono
=
Mono
.
fromSupplier
(
stringSupplier
);
System
.
out
.
println
(
stringSupplier
.
get
());
log
.
info
(
stringSupplier
.
get
());
StepVerifier
.
create
(
stringMono
.
log
())
.
expectNext
(
"adam"
)
...
...
src/test/java/com/nisum/webflux/basicOperators/FluxAndMonoWithTimeTest.java
View file @
3fa0f01c
...
...
@@ -5,11 +5,14 @@ import reactor.core.publisher.Flux;
import
reactor.test.StepVerifier
;
import
java.time.Duration
;
import
java.util.logging.Logger
;
/**
* Playing with flux with timestamp and delays;
*/
public
class
FluxAndMonoWithTimeTest
{
private
final
static
Logger
log
=
Logger
.
getLogger
(
Logger
.
GLOBAL_LOGGER_NAME
);
/**
* uses
* to create infinite sequence of the flux;
...
...
@@ -22,7 +25,7 @@ public class FluxAndMonoWithTimeTest {
.
log
();
// starts from 0 --> ......
infiniteFlux
.
subscribe
((
element
)
->
System
.
out
.
println
(
"Value is : "
+
element
));
.
subscribe
((
element
)
->
log
.
info
(
"Value is : "
+
element
));
Thread
.
sleep
(
3000
);
...
...
src/test/java/com/nisum/webflux/controller/EmployeeControllerComponentTest.java
View file @
3fa0f01c
...
...
@@ -40,10 +40,10 @@ public class EmployeeControllerComponentTest {
@Autowired
WebTestClient
webTestClient
;
private
WebTestClient
webTestClient
;
@Autowired
EmployeeRepo
empRepo
;
private
EmployeeRepo
empRepo
;
@Before
public
void
setup
()
{
...
...
src/test/java/com/nisum/webflux/controller/EmployeeControllerIntegrationTest.java
View file @
3fa0f01c
...
...
@@ -34,10 +34,10 @@ public class EmployeeControllerIntegrationTest {
@Autowired
WebTestClient
webTestClient
;
private
WebTestClient
webTestClient
;
@InjectMocks
EmployeeController
employeeController
;
private
EmployeeController
employeeController
;
@Mock
private
IEmployeeService
employeeService
;
...
...
@@ -52,7 +52,6 @@ public class EmployeeControllerIntegrationTest {
webTestClient
.
post
().
uri
(
"/employee"
).
contentType
(
MediaType
.
APPLICATION_JSON
).
body
(
Mono
.
just
(
getMockEmployee
().
blockFirst
()),
Employee
.
class
)
.
exchange
()
.
expectStatus
().
isOk
().
expectBody
().
jsonPath
(
"$.id"
).
isEqualTo
(
"1"
);
// .jsonPath("$.description").isEqualTo("xx").jsonPath("$.price").isEqualTo(34.4);
}
@Test
public
void
getAll_UsingWebClientComponentTestCase
()
{
...
...
@@ -74,14 +73,14 @@ public class EmployeeControllerIntegrationTest {
StepVerifier
.
create
(
employeeFlux
.
log
()).
expectSubscription
()
.
expectNextCount
(
1
).
verifyComplete
();
}
@Test
public
void
getAll_UsingMockito
(){
public
void
getAll_UsingMockito
_JunitTestCase
(){
Flux
<
Employee
>
employeeFlux
=
getMockEmployee
();
when
(
employeeService
.
getAllEmployee
()).
thenReturn
(
employeeFlux
);
assertEquals
(
employeeController
.
getAll
(),
employeeFlux
);
}
private
Flux
<
Employee
>
getMockEmployee
()
{
List
<
Hobby
>
hobbyObj
=
new
ArrayList
<>();
...
...
src/test/java/com/nisum/webflux/controller/FruitControllerComponentTest.java
View file @
3fa0f01c
...
...
@@ -24,10 +24,10 @@ import static org.mockito.Mockito.when;
@ContextConfiguration
(
classes
=
TestConfig
.
class
)
public
class
FruitControllerComponentTest
{
@Autowired
WebTestClient
webTestClient
;
private
WebTestClient
webTestClient
;
@Autowired
FruitRepository
fruitRepo
;
private
FruitRepository
fruitRepo
;
@Test
public
void
save
()
{
...
...
src/test/java/com/nisum/webflux/controller/FruitControllerIntegrationTest.java
View file @
3fa0f01c
...
...
@@ -24,9 +24,7 @@ import static org.mockito.Mockito.when;
public
class
FruitControllerIntegrationTest
{
@Autowired
WebTestClient
webTestClient
;
private
WebTestClient
webTestClient
;
@Test
public
void
save
()
{
...
...
src/test/java/com/nisum/webflux/service/impl/EmployeeServiceTest.java
View file @
3fa0f01c
...
...
@@ -27,10 +27,9 @@ import static org.mockito.Mockito.when;
@RunWith
(
SpringRunner
.
class
)
public
class
EmployeeServiceTest
{
@Mock
EmployeeRepo
empRepo
;
private
EmployeeRepo
empRepo
;
@InjectMocks
EmployeeService
employeeService
;
private
EmployeeService
employeeService
;
@Test
public
void
getAllEmployeeTestUsingStepVerifier
()
{
...
...
src/test/java/com/nisum/webflux/service/impl/TestConfig.java
View file @
3fa0f01c
...
...
@@ -9,8 +9,8 @@ import org.springframework.boot.test.mock.mockito.MockBean;
public
class
TestConfig
{
@MockBean
EmployeeRepo
empRepo
;
private
EmployeeRepo
empRepo
;
@MockBean
FruitRepository
fruitRepo
;
private
FruitRepository
fruitRepo
;
}
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