Java Code Examples for reactor.core.publisher.Mono#empty()

The following examples show how to use reactor.core.publisher.Mono#empty() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void buildVoidPublisher() {
	Mono<Void> mono = Mono.empty();
	Mono<ServerResponse> result = ServerResponse.ok().build(mono);

	MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").build();
	MockServerWebExchange exchange = MockServerWebExchange.from(request);

	result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();

	MockServerHttpResponse response = exchange.getResponse();
	StepVerifier.create(response.getBody()).expectComplete().verify();
}
 
Example 2
@Test
public void sameOriginRequest() {
	WebFilterChain filterChain = filterExchange -> {
		try {
			HttpHeaders headers = filterExchange.getResponse().getHeaders();
			assertNull(headers.getFirst(ACCESS_CONTROL_ALLOW_ORIGIN));
			assertNull(headers.getFirst(ACCESS_CONTROL_EXPOSE_HEADERS));
		}
		catch (AssertionError ex) {
			return Mono.error(ex);
		}
		return Mono.empty();

	};
	MockServerWebExchange exchange = MockServerWebExchange.from(
			MockServerHttpRequest
					.get("https://domain1.com/test.html")
					.header(ORIGIN, "https://domain1.com"));
	this.filter.filter(exchange, filterChain).block();
}
 
Example 3
Source Project: reactor-core   File: StepVerifierTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void verifyTimeoutSmokeTest() {
	Mono<String> neverMono = Mono.never();
	Mono<String> completingMono = Mono.empty();

	StepVerifier.create(neverMono, StepVerifierOptions.create().scenarioName("neverMono should pass"))
			.verifyTimeout(Duration.ofSeconds(1));

	assertThatExceptionOfType(AssertionError.class)
			.isThrownBy(() -> StepVerifier.create(completingMono).verifyTimeout(Duration.ofSeconds(1)))
			.withMessage("expectation \"expectTimeout\" failed (expected: timeout(1s); actual: onComplete())");
}
 
Example 4
@Override
public Mono<Void> onClose(CloseWebSocketFrame frame, Channel channel) {
    System.out.println("onClose" + channel);
    if (channel.isOpen() && channel.isActive()) {
        channel.close();
    }
    return Mono.empty();
}
 
Example 5
/**
 * GET /fake/jsonFormData : test json serialization of form data
 *
 * @param param field1 (required)
 * @param param2 field2 (required)
 * @return successful operation (status code 200)
 * @see FakeApi#testJsonFormData
 */
default Mono<ResponseEntity<Void>> testJsonFormData(String param,
    String param2,
    ServerWebExchange exchange) {
    Mono<Void> result = Mono.empty();
    exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
    return result.then(Mono.empty());

}
 
Example 6
Source Project: Shadbot   File: GuildMusic.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Mono<Void> removeAudioLoadResultListener(AudioLoadResultListener listener) {
    LOGGER.debug("{Guild ID: {}} Removing audio load result listener: {}", this.guildId, listener.hashCode());
    this.listeners.remove(listener);
    // If there is no music playing and nothing is loading, leave the voice channel
    if (this.trackScheduler.isStopped() && this.listeners.values().stream().allMatch(Future::isDone)) {
        return this.gateway.getVoiceConnectionRegistry()
                .getVoiceConnection(Snowflake.of(this.guildId))
                .flatMap(VoiceConnection::disconnect);
    }
    return Mono.empty();
}
 
Example 7
@Override
public Mono<Void> writeHttpHeaders(ServerWebExchange exchange) {
	HttpHeaders headers = exchange.getResponse().getHeaders();
	boolean containsOneHeaderToAdd = Collections.disjoint(headers.keySet(), this.headersToAdd.keySet());
	if(containsOneHeaderToAdd) {
		this.headersToAdd.forEach((name, values) -> {
			headers.put(name, values);
		});
	}
	return Mono.empty();
}
 
Example 8
@Test
public void should_return_empty_endpoints_when_all_empty() {
	// given
	Instance instance = Instance.create(InstanceId.of("id"));
	ChainingStrategy strategy = new ChainingStrategy((a) -> Mono.empty());
	// when/then
	StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(Endpoints.empty()).verifyComplete();
}
 
Example 9
public Mono<Void> onMessage(Message message) {
    if (null == message) {
        return Mono.empty();
    }
    if (!messageProcessor.hasDownstreams() && !messageProcessor.isCancelled()) {
        return Mono.empty();
    }

    return this.getTopic(message)
        .map(topic -> TopicMessage.of(topic, message))
        .doOnNext(sink::next)
        .then();
}
 
Example 10
@Override
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
	URI uri = request.getURI();
	assertEquals("https", uri.getScheme());
	assertNotNull(uri.getHost());
	assertNotEquals(-1, uri.getPort());
	assertNotNull(request.getRemoteAddress());
	assertEquals("/foo", uri.getPath());
	assertEquals("param=bar", uri.getQuery());
	return Mono.empty();
}
 
Example 11
/**
 * Find the resource under the given location.
 * <p>The default implementation checks if there is a readable
 * {@code Resource} for the given path relative to the location.
 * @param resourcePath the path to the resource
 * @param location the location to check
 * @return the resource, or empty {@link Mono} if none found
 */
protected Mono<Resource> getResource(String resourcePath, Resource location) {
	try {
		if (location instanceof ClassPathResource) {
			resourcePath = UriUtils.decode(resourcePath, StandardCharsets.UTF_8);
		}
		Resource resource = location.createRelative(resourcePath);
		if (resource.isReadable()) {
			if (checkResource(resource, location)) {
				return Mono.just(resource);
			}
			else if (logger.isWarnEnabled()) {
				Resource[] allowedLocations = getAllowedLocations();
				logger.warn("Resource path \"" + resourcePath + "\" was successfully resolved " +
						"but resource \"" + resource.getURL() + "\" is neither under the " +
						"current location \"" + location.getURL() + "\" nor under any of the " +
						"allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
			}
		}
		return Mono.empty();
	}
	catch (IOException ex) {
		if (logger.isDebugEnabled()) {
			String error = "Skip location [" + location + "] due to error";
			if (logger.isTraceEnabled()) {
				logger.trace(error, ex);
			}
			else {
				logger.debug(error + ": " + ex.getMessage());
			}
		}
		return Mono.error(ex);
	}
}
 
Example 12
@Override
public Mono<Void> invalidate() {
	this.state.set(State.EXPIRED);
	getAttributes().clear();
	InMemoryWebSessionStore.this.sessions.remove(this.id.get());
	return Mono.empty();
}
 
Example 13
@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
    // nothing to do - handler already registered in #supports(Object)
    return Mono.empty();
}
 
Example 14
Source Project: james-project   File: HybridBlobStore.java    License: Apache License 2.0 4 votes vote down vote up
private <T> Mono<T> logAndReturnEmpty(Throwable throwable) {
    LOGGER.error("error happens from current blob store, fall back to lowCost blob store", throwable);
    return Mono.empty();
}
 
Example 15
@Override
public Mono<UpdateServiceInstanceResponse> updateServiceInstance(UpdateServiceInstanceRequest request) {
	return Mono.empty();
}
 
Example 16
Source Project: rsocket-java   File: TestRSocket.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Void> metadataPush(Payload payload) {
  return Mono.empty();
}
 
Example 17
@Override
public Mono<UpdateServiceInstanceResponse> updateServiceInstance(UpdateServiceInstanceRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example 18
Source Project: r2dbc-mysql   File: BlobCodecTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Void> discard() {
    return Mono.empty();
}
 
Example 19
Source Project: reactor-netty   File: NettyOutbound.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Obtains a {@link Mono} of pending outbound(s) write completion.
 *
 * @return a {@link Mono} of pending outbound(s) write completion
 */
default Mono<Void> then() {
	return Mono.empty();
}
 
Example 20
/**
 * Performs the operation on the error flow
 *
 * @param request the service broker request
 * @param t the error
 * @return an empty Mono
 */
default Mono<Void> error(CreateServiceInstanceRequest request, Throwable t) {
	return Mono.empty();
}