Skip to content

Commit 4454ffd

Browse files
committed
Replace remaining use of block operator
1 parent 129c05b commit 4454ffd

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
import org.junit.Test;
2222
import reactor.core.publisher.Mono;
23+
import reactor.test.StepVerifier;
2324

2425
import org.springframework.core.io.ClassPathResource;
25-
import org.springframework.core.io.buffer.DataBuffer;
2626
import org.springframework.core.io.buffer.DataBufferUtils;
2727
import org.springframework.http.HttpEntity;
2828
import org.springframework.http.HttpHeaders;
@@ -103,12 +103,15 @@ private void assertFooPart(Part part) {
103103
assertEquals("fooPart", part.name());
104104
assertTrue(part instanceof FilePart);
105105
assertEquals("foo.txt", ((FilePart) part).filename());
106-
DataBufferUtils.join(part.content()).subscribe(buffer -> {
107-
assertEquals(12, buffer.readableByteCount());
108-
byte[] byteContent = new byte[12];
109-
buffer.read(byteContent);
110-
assertEquals("Lorem Ipsum.", new String(byteContent));
111-
});
106+
107+
StepVerifier.create(DataBufferUtils.join(part.content()))
108+
.consumeNextWith(buffer -> {
109+
assertEquals(12, buffer.readableByteCount());
110+
byte[] byteContent = new byte[12];
111+
buffer.read(byteContent);
112+
assertEquals("Lorem Ipsum.", new String(byteContent));
113+
})
114+
.verifyComplete();
112115
}
113116

114117
private void assertBarPart(Part part) {

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
2121
import java.util.List;
2222
import java.util.stream.Collectors;
2323

24+
import reactor.core.publisher.MonoProcessor;
25+
2426
import org.springframework.core.DefaultParameterNameDiscoverer;
2527
import org.springframework.core.ParameterNameDiscoverer;
2628
import org.springframework.lang.Nullable;
@@ -98,8 +100,21 @@ public ParameterNameDiscoverer getParameterNameDiscoverer() {
98100
public HandlerResult invokeForHandlerResult(ServerWebExchange exchange,
99101
BindingContext bindingContext, Object... providedArgs) {
100102

101-
// This will not block with only sync resolvers allowed
102-
return this.delegate.invoke(exchange, bindingContext, providedArgs).block();
103+
MonoProcessor<HandlerResult> processor = MonoProcessor.create();
104+
this.delegate.invoke(exchange, bindingContext, providedArgs).subscribeWith(processor);
105+
106+
if (processor.isTerminated()) {
107+
Throwable error = processor.getError();
108+
if (error != null) {
109+
throw (RuntimeException) error;
110+
}
111+
return processor.peek();
112+
}
113+
else {
114+
// Should never happen...
115+
throw new IllegalStateException(
116+
"SyncInvocableHandlerMethod should have completed synchronously.");
117+
}
103118
}
104119

105120
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@
5252
import org.springframework.web.reactive.function.client.WebClient;
5353
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
5454

55-
import static org.junit.Assert.assertEquals;
55+
import static org.junit.Assert.*;
5656

5757
public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
5858

@@ -170,10 +170,19 @@ void requestPart(
170170

171171
assertEquals("fieldValue", fieldPart.value());
172172
assertEquals("fileParts:foo.txt", partDescription(fileParts));
173-
assertEquals("fileParts:foo.txt", partDescription(filePartsMono.block()));
174-
assertEquals("[fileParts:foo.txt,fileParts:logo.png]", partFluxDescription(filePartsFlux).block());
175173
assertEquals("Jason", person.getName());
176-
assertEquals("Jason", personMono.block().getName());
174+
175+
StepVerifier.create(partFluxDescription(filePartsFlux))
176+
.consumeNextWith(content -> assertEquals("[fileParts:foo.txt,fileParts:logo.png]", content))
177+
.verifyComplete();
178+
179+
StepVerifier.create(filePartsMono)
180+
.consumeNextWith(filePart -> assertEquals("fileParts:foo.txt", partDescription(filePart)))
181+
.verifyComplete();
182+
183+
StepVerifier.create(personMono)
184+
.consumeNextWith(p -> assertEquals("Jason", p.getName()))
185+
.verifyComplete();
177186
}
178187

179188
@PostMapping("/requestBodyMap")

0 commit comments

Comments
 (0)