use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method routeWithCustomFormatting.
@Test
public void routeWithCustomFormatting() {
this.extractor.metadataToExtract(TEXT_PLAIN, String.class, (text, result) -> {
String[] items = text.split(":");
Assert.isTrue(items.length == 2, "Expected two items");
result.put(ROUTE_KEY, items[0]);
result.put("entry1", items[1]);
});
MetadataEncoder encoder = new MetadataEncoder(TEXT_PLAIN, this.strategies).metadata("toA:text data", null);
DataBuffer metadata = encoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = this.extractor.extract(payload, TEXT_PLAIN);
payload.release();
assertThat(result).hasSize(2).containsEntry(ROUTE_KEY, "toA").containsEntry("entry1", "text data");
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method routeAsText.
@Test
public void routeAsText() {
this.extractor.metadataToExtract(TEXT_PLAIN, String.class, ROUTE_KEY);
MetadataEncoder metadataEncoder = new MetadataEncoder(TEXT_PLAIN, this.strategies).route("toA");
DataBuffer metadata = metadataEncoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = this.extractor.extract(payload, TEXT_PLAIN);
payload.release();
assertThat(result).hasSize(1).containsEntry(ROUTE_KEY, "toA");
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultMetadataExtractorTests method compositeMetadataWithMimeTypeRegistrations.
@Test
public void compositeMetadataWithMimeTypeRegistrations() {
this.extractor.metadataToExtract(TEXT_PLAIN, String.class, "text-entry");
this.extractor.metadataToExtract(TEXT_HTML, String.class, "html-entry");
this.extractor.metadataToExtract(TEXT_XML, String.class, "xml-entry");
MetadataEncoder metadataEncoder = new MetadataEncoder(COMPOSITE_METADATA, this.strategies).route("toA").metadata("text data", TEXT_PLAIN).metadata("html data", TEXT_HTML).metadata("xml data", TEXT_XML);
DataBuffer metadata = metadataEncoder.encode().block();
Payload payload = createPayload(metadata);
Map<String, Object> result = this.extractor.extract(payload, COMPOSITE_METADATA);
payload.release();
assertThat(result).hasSize(4).containsEntry(ROUTE_KEY, "toA").containsEntry("text-entry", "text data").containsEntry("html-entry", "html data").containsEntry("xml-entry", "xml data");
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultRSocketRequesterTests method retrieveMonoVoid.
@Test
public void retrieveMonoVoid() {
AtomicBoolean consumed = new AtomicBoolean();
Mono<Payload> mono = Mono.delay(MILLIS_10).thenReturn(toPayload("bodyA")).doOnSuccess(p -> consumed.set(true));
this.rsocket.setPayloadMonoToReturn(mono);
this.requester.route("").data("").retrieveMono(Void.class).block(Duration.ofSeconds(5));
assertThat(consumed.get()).isTrue();
assertThat(this.rsocket.getSavedMethodName()).isEqualTo("requestResponse");
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultRSocketRequesterTests method retrieveFluxVoid.
@Test
public void retrieveFluxVoid() {
AtomicBoolean consumed = new AtomicBoolean();
Flux<Payload> flux = Flux.just("bodyA", "bodyB").delayElements(MILLIS_10).map(this::toPayload).doOnComplete(() -> consumed.set(true));
this.rsocket.setPayloadFluxToReturn(flux);
this.requester.route("").data("").retrieveFlux(Void.class).blockLast(Duration.ofSeconds(5));
assertThat(consumed.get()).isTrue();
assertThat(this.rsocket.getSavedMethodName()).isEqualTo("requestStream");
}
Aggregations