Browse Source

Replace remaining use of block operator

pull/1771/merge
Rossen Stoyanchev 7 years ago
parent
commit
4454ffd2b1
  1. 17
      spring-web/src/test/java/org/springframework/http/server/reactive/MultipartIntegrationTests.java
  2. 21
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java
  3. 19
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java

17
spring-web/src/test/java/org/springframework/http/server/reactive/MultipartIntegrationTests.java

@ -20,9 +20,9 @@ import java.net.URI; @@ -20,9 +20,9 @@ import java.net.URI;
import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@ -103,12 +103,15 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes @@ -103,12 +103,15 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
assertEquals("fooPart", part.name());
assertTrue(part instanceof FilePart);
assertEquals("foo.txt", ((FilePart) part).filename());
DataBufferUtils.join(part.content()).subscribe(buffer -> {
assertEquals(12, buffer.readableByteCount());
byte[] byteContent = new byte[12];
buffer.read(byteContent);
assertEquals("Lorem Ipsum.", new String(byteContent));
});
StepVerifier.create(DataBufferUtils.join(part.content()))
.consumeNextWith(buffer -> {
assertEquals(12, buffer.readableByteCount());
byte[] byteContent = new byte[12];
buffer.read(byteContent);
assertEquals("Lorem Ipsum.", new String(byteContent));
})
.verifyComplete();
}
private void assertBarPart(Part part) {

21
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,6 +21,8 @@ import java.util.ArrayList; @@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import reactor.core.publisher.MonoProcessor;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.lang.Nullable;
@ -98,8 +100,21 @@ public class SyncInvocableHandlerMethod extends HandlerMethod { @@ -98,8 +100,21 @@ public class SyncInvocableHandlerMethod extends HandlerMethod {
public HandlerResult invokeForHandlerResult(ServerWebExchange exchange,
BindingContext bindingContext, Object... providedArgs) {
// This will not block with only sync resolvers allowed
return this.delegate.invoke(exchange, bindingContext, providedArgs).block();
MonoProcessor<HandlerResult> processor = MonoProcessor.create();
this.delegate.invoke(exchange, bindingContext, providedArgs).subscribeWith(processor);
if (processor.isTerminated()) {
Throwable error = processor.getError();
if (error != null) {
throw (RuntimeException) error;
}
return processor.peek();
}
else {
// Should never happen...
throw new IllegalStateException(
"SyncInvocableHandlerMethod should have completed synchronously.");
}
}
}

19
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -52,7 +52,7 @@ import org.springframework.web.reactive.function.client.ClientResponse; @@ -52,7 +52,7 @@ import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
@ -170,10 +170,19 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes @@ -170,10 +170,19 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
assertEquals("fieldValue", fieldPart.value());
assertEquals("fileParts:foo.txt", partDescription(fileParts));
assertEquals("fileParts:foo.txt", partDescription(filePartsMono.block()));
assertEquals("[fileParts:foo.txt,fileParts:logo.png]", partFluxDescription(filePartsFlux).block());
assertEquals("Jason", person.getName());
assertEquals("Jason", personMono.block().getName());
StepVerifier.create(partFluxDescription(filePartsFlux))
.consumeNextWith(content -> assertEquals("[fileParts:foo.txt,fileParts:logo.png]", content))
.verifyComplete();
StepVerifier.create(filePartsMono)
.consumeNextWith(filePart -> assertEquals("fileParts:foo.txt", partDescription(filePart)))
.verifyComplete();
StepVerifier.create(personMono)
.consumeNextWith(p -> assertEquals("Jason", p.getName()))
.verifyComplete();
}
@PostMapping("/requestBodyMap")

Loading…
Cancel
Save