Search in sources :

Example 6 with Payload

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");
}
Also used : Payload(io.rsocket.Payload) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 7 with Payload

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");
}
Also used : Payload(io.rsocket.Payload) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 8 with Payload

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");
}
Also used : Payload(io.rsocket.Payload) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 9 with Payload

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");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Payload(io.rsocket.Payload) Test(org.junit.jupiter.api.Test)

Example 10 with Payload

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");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Payload(io.rsocket.Payload) Test(org.junit.jupiter.api.Test)

Aggregations

Payload (io.rsocket.Payload)26 Test (org.junit.jupiter.api.Test)23 DefaultPayload (io.rsocket.util.DefaultPayload)16 ByteBufPayload (io.rsocket.util.ByteBufPayload)14 DataBuffer (org.springframework.core.io.buffer.DataBuffer)12 NettyDataBuffer (org.springframework.core.io.buffer.NettyDataBuffer)9 RSocket (io.rsocket.RSocket)7 RSocketProxy (io.rsocket.util.RSocketProxy)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)6 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)5 MimeType (org.springframework.util.MimeType)5 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)4 Publisher (org.reactivestreams.Publisher)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 RSocketConnector (io.rsocket.core.RSocketConnector)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2