public MockClientHttpRequest(HttpMethod httpMethod, URI url) { this.httpMethod = httpMethod; this.url = url; this.writeHandler = body -> { this.body = body.cache(); return this.body.then(); }; }
public MockServerHttpResponse() { super(new DefaultDataBufferFactory()); this.writeHandler = body -> { this.body = body.cache(); return this.body.then(); }; }
/** * Apply {@link #beforeCommit(Supplier) beforeCommit} actions, apply the * request headers/cookies, and write the request body. * @param writeAction the action to write the request body (may be {@code null}) * @return a completion publisher */ protected Mono<Void> doCommit(@Nullable Supplier<? extends Publisher<Void>> writeAction) { if (!this.state.compareAndSet(State.NEW, State.COMMITTING)) { return Mono.empty(); } this.commitActions.add(() -> Mono.fromRunnable(() -> { applyHeaders(); applyCookies(); this.state.set(State.COMMITTED); })); if (writeAction != null) { this.commitActions.add(writeAction); } List<? extends Publisher<Void>> actions = this.commitActions.stream() .map(Supplier::get).collect(Collectors.toList()); return Flux.concat(actions).then(); }
private static Mono<Void> consumeAndCancel(ReactiveHttpInputMessage message) { return message.getBody() .map(buffer -> { DataBufferUtils.release(buffer); throw new ReadCancellationException(); }) .onErrorResume(ReadCancellationException.class, ex -> Mono.empty()) .then(); }
/** * Apply {@link #beforeCommit(Supplier) beforeCommit} actions, apply the * response status and headers/cookies, and write the response body. * @param writeAction the action to write the response body (may be {@code null}) * @return a completion publisher */ protected Mono<Void> doCommit(@Nullable Supplier<? extends Mono<Void>> writeAction) { if (!this.state.compareAndSet(State.NEW, State.COMMITTING)) { return Mono.empty(); } this.commitActions.add(() -> Mono.fromRunnable(() -> { applyStatusCode(); applyHeaders(); applyCookies(); this.state.set(State.COMMITTED); })); if (writeAction != null) { this.commitActions.add(writeAction); } List<? extends Mono<Void>> actions = this.commitActions.stream() .map(Supplier::get).collect(Collectors.toList()); return Flux.concat(actions).then(); }
protected Mono<Void> updateStatusForAllInstances() { log.debug("Updating status for all instances"); Instant expiryInstant = Instant.now().minus(statusLifetime); return Flux.fromIterable(lastQueried.entrySet()) .filter(e -> e.getValue().isBefore(expiryInstant)) .map(Map.Entry::getKey) .flatMap(this::updateStatus) .then(); }
public MockServerHttpResponse(DataBufferFactory dataBufferFactory) { super(dataBufferFactory); this.writeHandler = body -> { this.body = body.cache(); return this.body.then(); }; }
@Override protected Mono<Void> writeWithInternal(Publisher<? extends DataBuffer> body) { return Flux.from(body).map(b -> { this.body.add(b); return b; }).then(); }
public MockClientHttpRequest(HttpMethod httpMethod, URI url) { this.httpMethod = httpMethod; this.url = url; this.writeHandler = body -> { this.body = body.cache(); return this.body.then(); }; }
@PostMapping("/flux") public Mono<Void> createWithFlux(@RequestBody Flux<Person> flux) { return flux.doOnNext(persons::add).then(); }
private Mono<Void> writeAndFlush(Flux<DataBuffer> body, OutputStream responseBody) { return DataBufferUtils.write(body, responseBody).map(DataBufferUtils::release).then(Mono.create(sink -> { try { responseBody.flush(); sink.success(); } catch (IOException ex) { sink.error(ex); } })); } }
@Override public Mono<Void> notify(InstanceEvent event) { return Flux.fromIterable(delegates).flatMap(d -> d.notify(event).onErrorResume(error -> { log.warn("Unexpected exception while triggering notifications. Notification might not be sent.", error); return Mono.empty(); })).then(); } }
@PostMapping("/publisher") public Publisher<Void> createWithPublisher(@RequestBody Publisher<Person> publisher) { return Flux.from(publisher).doOnNext(persons::add).then(); }
@Override public Mono<Void> shutdown(boolean save) { Map<String, Publisher<Void>> publishers = executeOnNodes(commands -> commands.shutdown(save), ALL_NODES); return Flux.merge(publishers.values()).then(); }
protected Mono<Void> sendReminders() { Instant now = Instant.now(); return Flux.fromIterable(this.reminders.values()) .filter(reminder -> reminder.getLastNotification().plus(reminderPeriod).isBefore(now)) .flatMap(reminder -> delegate.notify(reminder.getEvent()) .doOnSuccess(signal -> reminder.setLastNotification(now))) .then(); }
@Override protected Mono<Void> writeAndFlushWithInternal( Publisher<? extends Publisher<? extends DataBuffer>> bodyWithFlush) { return Flux.from(bodyWithFlush).flatMap(body -> Flux.from(body).map(b -> { this.body.add(b); return b; }) ).then(); } }
@Test public void sessionClosing() throws Exception { this.client.execute(getUrl("/close"), session -> { logger.debug("Starting.."); return session.receive() .doOnNext(s -> logger.debug("inbound " + s)) .then() .doFinally(signalType -> { logger.debug("Completed with: " + signalType); }); }) .block(TIMEOUT); }
@Test public void fluxThenMonoAndShift() { StepVerifier.create(Flux.just("Good Morning", "Hello") .then(Mono.just("Good Afternoon")) .then(Mono.just("Bye"))) .expectNext("Bye") .verifyComplete(); }
@Test public void normal3() { StepVerifier.create(Flux.just(1) .then()) .verifyComplete(); }
@Test public void cancel() { TestPublisher<String> cancelTester = TestPublisher.create(); MonoProcessor<Void> processor = cancelTester.flux() .then() .toProcessor(); processor.subscribe(); processor.cancel(); cancelTester.assertCancelled(); }