use of io.rsocket.Payload in project spring-framework by spring-projects.
the class DefaultRSocketRequesterTests method testSendWithAsyncMetadata.
@Test
public void testSendWithAsyncMetadata() {
MimeType compositeMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
Mono<String> asyncMeta1 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 1");
Mono<String> asyncMeta2 = Mono.delay(Duration.ofMillis(1)).map(aLong -> "Async Metadata 2");
TestRSocket rsocket = new TestRSocket();
RSocketRequester.wrap(rsocket, TEXT_PLAIN, compositeMimeType, this.strategies).route("toA").metadata(asyncMeta1, new MimeType("text", "x.test.metadata1")).metadata(asyncMeta2, new MimeType("text", "x.test.metadata2")).data("data").send().block(Duration.ofSeconds(5));
Payload payload = rsocket.getSavedPayload();
DefaultMetadataExtractor extractor = new DefaultMetadataExtractor(this.strategies.decoders());
extractor.metadataToExtract(new MimeType("text", "x.test.metadata1"), String.class, "asyncMeta1");
extractor.metadataToExtract(new MimeType("text", "x.test.metadata2"), String.class, "asyncMeta2");
Map<String, Object> metadataValues = extractor.extract(payload, compositeMimeType);
assertThat(metadataValues.get("asyncMeta1")).isEqualTo("Async Metadata 1");
assertThat(metadataValues.get("asyncMeta2")).isEqualTo("Async Metadata 2");
assertThat(payload.getDataUtf8()).isEqualTo("data");
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class PayloadUtilsTests method createWithNettyAndDefaultBuffers.
@Test
public void createWithNettyAndDefaultBuffers() {
NettyDataBuffer data = createNettyDataBuffer("sample data");
DefaultDataBuffer metadata = createDefaultDataBuffer("sample metadata");
Payload payload = PayloadUtils.createPayload(data, metadata);
try {
assertThat(payload).isInstanceOf(ByteBufPayload.class);
assertThat(payload.data()).isSameAs(data.getNativeBuffer());
assertThat(payload.getMetadataUtf8()).isEqualTo(metadata.toString(UTF_8));
} finally {
payload.release();
}
}
use of io.rsocket.Payload in project spring-framework by spring-projects.
the class PayloadUtilsTests method retainAndReleaseWithDefaultFactory.
@Test
public void retainAndReleaseWithDefaultFactory() {
Payload payload = ByteBufPayload.create("sample data");
DataBuffer buffer = PayloadUtils.retainDataAndReleasePayload(payload, DefaultDataBufferFactory.sharedInstance);
assertThat(buffer).isInstanceOf(DefaultDataBuffer.class);
assertThat(payload.refCnt()).isEqualTo(0);
}
use of io.rsocket.Payload in project spring-security by spring-projects.
the class PayloadInterceptorRSocketTests method requestResponseWhenSecurityContextThenDelegateContext.
@Test
public void requestResponseWhenSecurityContextThenDelegateContext() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
given(this.delegate.requestResponse(any())).willReturn(this.payloadResult.mono());
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
@Override
public Mono<Payload> requestResponse(Payload payload) {
return assertAuthentication(authentication).flatMap((a) -> super.requestResponse(payload));
}
};
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication, Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
StepVerifier.create(interceptor.requestResponse(this.payload)).then(() -> this.payloadResult.assertSubscribers()).then(() -> this.payloadResult.emit(this.payload)).expectNext(this.payload).verifyComplete();
verify(this.interceptor).intercept(this.exchange.capture(), any());
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
verify(this.delegate).requestResponse(this.payload);
}
use of io.rsocket.Payload in project spring-security by spring-projects.
the class PayloadInterceptorRSocketTests method requestStreamWhenSecurityContextThenDelegateContext.
@Test
public void requestStreamWhenSecurityContextThenDelegateContext() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
given(this.delegate.requestStream(any())).willReturn(this.payloadResult.flux());
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
@Override
public Flux<Payload> requestStream(Payload payload) {
return assertAuthentication(authentication).flatMapMany((a) -> super.requestStream(payload));
}
};
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(assertAuthentication, Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
StepVerifier.create(interceptor.requestStream(this.payload)).then(() -> this.payloadResult.assertSubscribers()).then(() -> this.payloadResult.emit(this.payload)).expectNext(this.payload).verifyComplete();
verify(this.interceptor).intercept(this.exchange.capture(), any());
assertThat(this.exchange.getValue().getPayload()).isEqualTo(this.payload);
verify(this.delegate).requestStream(this.payload);
}
Aggregations