Skip to content

Commit ef178d2

Browse files
committed
Merge branch '5.3.x'
2 parents cb8163b + 7e7d6b9 commit ef178d2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ public static Mono<Void> write(Publisher<DataBuffer> source, Path destination, O
366366
sink.onDispose(() -> closeChannel(channel));
367367
write(source, channel).subscribe(DataBufferUtils::release,
368368
sink::error,
369-
sink::success);
369+
sink::success,
370+
Context.of(sink.contextView()));
370371
}
371372
catch (IOException ex) {
372373
sink.error(ex);

spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,27 @@ void propagateContextAsynchronousFileChannel(DataBufferFactory bufferFactory) th
990990
}
991991
}
992992

993+
@ParameterizedDataBufferAllocatingTest
994+
void propagateContextPath(DataBufferFactory bufferFactory) throws IOException {
995+
Path path = Paths.get(this.resource.getURI());
996+
Path out = Files.createTempFile("data-buffer-utils-tests", ".tmp");
997+
998+
Flux<Void> result = DataBufferUtils.read(path, bufferFactory, 1024, StandardOpenOption.READ)
999+
.transformDeferredContextual((f, ctx) -> {
1000+
assertThat(ctx.getOrDefault("key", "EMPTY")).isEqualTo("TEST");
1001+
return f;
1002+
})
1003+
.transform(f -> DataBufferUtils.write(f, out))
1004+
.transformDeferredContextual((f, ctx) -> {
1005+
assertThat(ctx.getOrDefault("key", "EMPTY")).isEqualTo("TEST");
1006+
return f;
1007+
})
1008+
.contextWrite(Context.of("key", "TEST"));
1009+
1010+
StepVerifier.create(result)
1011+
.verifyComplete();
1012+
}
1013+
9931014
private static class ZeroDemandSubscriber extends BaseSubscriber<DataBuffer> {
9941015

9951016
@Override

0 commit comments

Comments
 (0)