}
TestListener testListener = new TestListener(port, chatRooms);
- CompletableFuture<Void> testListenerFuture = testListener
+ testListener
.run()
- .toFuture();
+ .subscribe(message -> log.info(
+ "Received message: {}",
+ message));
log.info("Sleeping for 3 seconds...");
Thread.sleep(3000);
log.info("Joined TestWriter {}", testWriters[i].user);
}
-
- log.info("Sleeping for 3 seconds...");
- Thread.sleep(3000);
- log.info("Joining TestListener...");
- testListener.running = false;
- testListenerFuture.join();
- log.info("Joined TestListener");
+ // Yield the work, so that the last messages can be received
+ Thread.sleep(500);
}
Mono<ChatRoomInfoTo> createChatRoom(String name)
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
import java.util.*;
static final ParameterizedTypeReference<ServerSentEvent<String>> SSE_TYPE = new ParameterizedTypeReference<>() {};
- public Mono<Void> run()
+ public Flux<MessageTo> run()
{
return Flux
.fromArray(chatRooms)
return Mono.error(e);
}
})
- .doOnNext(message ->
- {
- list.add(message);
- log.info(
- "Received a message from chat-room {}: {}",
- chatRoom.getName(),
- message);
- });
- })
- .limitRate(10)
- .takeUntil(message -> !running)
- .doOnComplete(() -> log.info("TestListener is done"))
- .parallel(chatRooms.length)
- .runOn(Schedulers.parallel())
- .then();
+ .doOnNext(message -> list.add(message));
+ });
}
Flux<ServerSentEvent<String>> receiveMessages(ChatRoomInfoTo chatRoom)
final Map<UUID, List<MessageTo>> receivedMessages = new HashMap<>();
- volatile boolean running = true;
-
TestListener(Integer port, ChatRoomInfoTo[] chatRooms)
{