JAMES-2979 MailDispatcher: Use immediate schedule to avoid allocating threads upon nested block calls
This test mimics the previous behaviour of LocalDelivery
```
@Test
void testNestedBlocksWithElasticScheduler() {
// mono1 corresponds to the append to the mailbox (blocking)
Mono<Void> mono1 = Mono.fromRunnable(() -> {
System.out.println("mono1 running on " + Thread.currentThread().getName());
});
// mono2 corresponds to the retries perforned in MailDispatcher
Mono<Void> mono2 = Mono.fromRunnable(() -> {
System.out.println("mono2 running on " + Thread.currentThread().getName());
mono1.subscribeOn(Schedulers.elastic()).block();
});
// This is a spooler thread running LocalDelivery
System.out.println("Current thread " + Thread.currentThread().getName());
mono2.subscribeOn(Schedulers.elastic()).block();
}
```
Output:
```
Current thread main
mono2 running on elastic-2
mono1 running on elastic-3
```
One thread doing the work and two waiting...
With the new paradigm (waiting for a fully reactive version)
```
@Test
void testNestedBlockWithImmediateScheduler() {
// mono1 corresponds to the append to the mailbox (blocking)
Mono<Void> mono1 = Mono.fromRunnable(() -> {
System.out.println("mono1 running on " + Thread.currentThread().getName());
});
// mono2 corresponds to the retries perforned in MailDispatcher
Mono<Void> mono2 = Mono.fromRunnable(() -> {
System.out.println("mono2 running on " + Thread.currentThread().getName());
mono1.subscribeOn(Schedulers.immediate()).block();
});
// This is a spooler thread running LocalDelivery
System.out.println("Current thread " + Thread.currentThread().getName());
mono2.subscribeOn(Schedulers.immediate()).block();
}
```
We get...
```
Current thread main
mono2 running on main
mono1 running on main
```
Way better! We do mobilize only one thread that would anyway be blocked.
1 file changed