Java Code Examples for io.rsocket.util.DefaultPayload#create()
The following examples show how to use
io.rsocket.util.DefaultPayload#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RSocketRequesterTest.java From rsocket-java with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("streamRacingCases") public void ensuresCorrectOrderOfStreamIdIssuingInCaseOfRacing( BiFunction<ClientSocketRule, Payload, Publisher<?>> interaction1, BiFunction<ClientSocketRule, Payload, Publisher<?>> interaction2, FrameType interactionType1, FrameType interactionType2) { Assumptions.assumeThat(interactionType1).isNotEqualTo(METADATA_PUSH); Assumptions.assumeThat(interactionType2).isNotEqualTo(METADATA_PUSH); for (int i = 1; i < 10000; i += 4) { Payload payload = DefaultPayload.create("test", "test"); Publisher<?> publisher1 = interaction1.apply(rule, payload); Publisher<?> publisher2 = interaction2.apply(rule, payload); RaceTestUtils.race( () -> publisher1.subscribe(AssertSubscriber.create()), () -> publisher2.subscribe(AssertSubscriber.create())); Assertions.assertThat(rule.connection.getSent()) .extracting(FrameHeaderCodec::streamId) .containsExactly(i, i + 2); rule.connection.getSent().forEach(bb -> bb.release()); rule.connection.getSent().clear(); } }
Example 2
Source File: SetupFrameCodecTest.java From rsocket-java with Apache License 2.0 | 6 votes |
@Test void testEncodingResume() { byte[] tokenBytes = new byte[65000]; Arrays.fill(tokenBytes, (byte) 1); ByteBuf metadata = Unpooled.wrappedBuffer(new byte[] {1, 2, 3, 4}); ByteBuf data = Unpooled.wrappedBuffer(new byte[] {5, 4, 3}); Payload payload = DefaultPayload.create(data, metadata); ByteBuf token = Unpooled.wrappedBuffer(tokenBytes); ByteBuf frame = SetupFrameCodec.encode( ByteBufAllocator.DEFAULT, true, 5, 500, token, "metadata_type", "data_type", payload); assertEquals(FrameType.SETUP, FrameHeaderCodec.frameType(frame)); assertTrue(SetupFrameCodec.honorLease(frame)); assertTrue(SetupFrameCodec.resumeEnabled(frame)); assertEquals(token, SetupFrameCodec.resumeToken(frame)); assertEquals("metadata_type", SetupFrameCodec.metadataMimeType(frame)); assertEquals("data_type", SetupFrameCodec.dataMimeType(frame)); assertEquals(metadata, SetupFrameCodec.metadata(frame)); assertEquals(data, SetupFrameCodec.data(frame)); assertEquals(SetupFrameCodec.CURRENT_VERSION, SetupFrameCodec.version(frame)); frame.release(); }
Example 3
Source File: SetupFrameCodecTest.java From rsocket-java with Apache License 2.0 | 6 votes |
@Test void testEncodingNoResume() { ByteBuf metadata = Unpooled.wrappedBuffer(new byte[] {1, 2, 3, 4}); ByteBuf data = Unpooled.wrappedBuffer(new byte[] {5, 4, 3}); Payload payload = DefaultPayload.create(data, metadata); ByteBuf frame = SetupFrameCodec.encode( ByteBufAllocator.DEFAULT, false, 5, 500, "metadata_type", "data_type", payload); assertEquals(FrameType.SETUP, FrameHeaderCodec.frameType(frame)); assertFalse(SetupFrameCodec.resumeEnabled(frame)); assertEquals(0, SetupFrameCodec.resumeToken(frame).readableBytes()); assertEquals("metadata_type", SetupFrameCodec.metadataMimeType(frame)); assertEquals("data_type", SetupFrameCodec.dataMimeType(frame)); assertEquals(metadata, SetupFrameCodec.metadata(frame)); assertEquals(data, SetupFrameCodec.data(frame)); assertEquals(SetupFrameCodec.CURRENT_VERSION, SetupFrameCodec.version(frame)); frame.release(); }
Example 4
Source File: ConnectionSetupPayloadTest.java From rsocket-java with Apache License 2.0 | 6 votes |
@Test void testSetupPayloadWithEmptyMetadata() { ByteBuf data = Unpooled.wrappedBuffer(new byte[] {5, 4, 3}); ByteBuf metadata = Unpooled.EMPTY_BUFFER; Payload payload = DefaultPayload.create(data, metadata); boolean leaseEnabled = false; ByteBuf frame = encodeSetupFrame(leaseEnabled, payload); ConnectionSetupPayload setupPayload = new DefaultConnectionSetupPayload(frame); assertFalse(setupPayload.willClientHonorLease()); assertTrue(setupPayload.hasMetadata()); assertNotNull(setupPayload.metadata()); assertEquals(0, setupPayload.metadata().readableBytes()); assertEquals(payload.data(), setupPayload.data()); frame.release(); }
Example 5
Source File: ConnectionSetupPayloadTest.java From rsocket-java with Apache License 2.0 | 6 votes |
@Test void testSetupPayloadWithDataMetadata() { ByteBuf data = Unpooled.wrappedBuffer(new byte[] {5, 4, 3}); ByteBuf metadata = Unpooled.wrappedBuffer(new byte[] {2, 1, 0}); Payload payload = DefaultPayload.create(data, metadata); boolean leaseEnabled = true; ByteBuf frame = encodeSetupFrame(leaseEnabled, payload); ConnectionSetupPayload setupPayload = new DefaultConnectionSetupPayload(frame); assertTrue(setupPayload.willClientHonorLease()); assertEquals(KEEP_ALIVE_INTERVAL, setupPayload.keepAliveInterval()); assertEquals(KEEP_ALIVE_MAX_LIFETIME, setupPayload.keepAliveMaxLifetime()); assertEquals(METADATA_TYPE, SetupFrameCodec.metadataMimeType(frame)); assertEquals(DATA_TYPE, SetupFrameCodec.dataMimeType(frame)); assertTrue(setupPayload.hasMetadata()); assertNotNull(setupPayload.metadata()); assertEquals(payload.metadata(), setupPayload.metadata()); assertEquals(payload.data(), setupPayload.data()); frame.release(); }
Example 6
Source File: BrokerActuatorHandlerRegistration.java From spring-cloud-rsocket with Apache License 2.0 | 5 votes |
private ConnectionSetupPayload getConnectionSetupPayload() { DataBufferFactory dataBufferFactory = messageHandler.getRSocketStrategies() .dataBufferFactory(); NettyDataBufferFactory ndbf = (NettyDataBufferFactory) dataBufferFactory; ByteBufAllocator byteBufAllocator = ndbf.getByteBufAllocator(); Payload setupPayload = DefaultPayload.create(Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER); ByteBuf setup = SetupFrameFlyweight.encode(byteBufAllocator, false, 1, 1, MESSAGE_RSOCKET_COMPOSITE_METADATA.getString(), // TODO: configurable? APPLICATION_CBOR.getString(), setupPayload); return ConnectionSetupPayload.create(setup); }
Example 7
Source File: PayloadValidationUtilsTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void shouldBeValidFrameWithNoFragmentation0() { byte[] metadata = new byte[FrameLengthCodec.FRAME_LENGTH_MASK / 2]; byte[] data = new byte [FrameLengthCodec.FRAME_LENGTH_MASK / 2 - FrameLengthCodec.FRAME_LENGTH_SIZE - FrameHeaderCodec.size() - FrameHeaderCodec.size()]; ThreadLocalRandom.current().nextBytes(data); ThreadLocalRandom.current().nextBytes(metadata); final Payload payload = DefaultPayload.create(data, metadata); Assertions.assertThat(PayloadValidationUtils.isValid(0, payload)).isTrue(); }
Example 8
Source File: BaseClientServerTest.java From rsocket-java with Apache License 2.0 | 5 votes |
private Payload testPayload(int metadataPresent) { String metadata; switch (metadataPresent % 5) { case 0: metadata = null; break; case 1: metadata = ""; break; default: metadata = "metadata"; break; } return DefaultPayload.create("hello", metadata); }
Example 9
Source File: MicrometerRSocketTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@DisplayName("requestResponse gathers metrics") @Test void requestResponse() { Payload payload = DefaultPayload.create("test-metadata", "test-data"); when(delegate.requestResponse(payload)).thenReturn(Mono.empty()); new MicrometerRSocket(delegate, meterRegistry, Tag.of("test-key", "test-value")) .requestResponse(payload) .as(StepVerifier::create) .verifyComplete(); assertThat(findTimer("request.response", SignalType.ON_COMPLETE).count()).isEqualTo(1); }
Example 10
Source File: PayloadValidationUtilsTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void shouldBeValidFrameWithNoFragmentation4() { byte[] metadata = new byte[1]; byte[] data = new byte[1]; ThreadLocalRandom.current().nextBytes(metadata); ThreadLocalRandom.current().nextBytes(data); final Payload payload = DefaultPayload.create(data, metadata); Assertions.assertThat(PayloadValidationUtils.isValid(64, payload)).isTrue(); }
Example 11
Source File: ForwardingIntegrationTests.java From spring-cloud-rsocket with Apache License 2.0 | 5 votes |
@Override protected Forwarding decode(ByteBuf byteBuf) { MetadataExtractor metadataExtractor = strategies.metadataExtractor(); Payload payload = DefaultPayload.create(Unpooled.EMPTY_BUFFER, byteBuf); Map<String, Object> metadata = metadataExtractor.extract(payload, Metadata.COMPOSITE_MIME_TYPE); assertThat(metadata).containsKey(Forwarding.METADATA_KEY); return (Forwarding) metadata.get(Forwarding.METADATA_KEY); }
Example 12
Source File: PayloadValidationUtilsTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void shouldBeValidFrameWithNoFragmentation2() { byte[] metadata = new byte[1]; byte[] data = new byte[1]; ThreadLocalRandom.current().nextBytes(metadata); ThreadLocalRandom.current().nextBytes(data); final Payload payload = DefaultPayload.create(data, metadata); Assertions.assertThat(PayloadValidationUtils.isValid(0, payload)).isTrue(); }
Example 13
Source File: PayloadFlyweightTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void nextCompleteDataMetadata() { Payload payload = DefaultPayload.create("d", "md"); ByteBuf nextComplete = PayloadFrameCodec.encodeNextCompleteReleasingPayload(ByteBufAllocator.DEFAULT, 1, payload); String data = PayloadFrameCodec.data(nextComplete).toString(StandardCharsets.UTF_8); String metadata = PayloadFrameCodec.metadata(nextComplete).toString(StandardCharsets.UTF_8); Assertions.assertEquals("d", data); Assertions.assertEquals("md", metadata); nextComplete.release(); }
Example 14
Source File: PayloadValidationUtilsTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void shouldBeInValidFrameWithNoFragmentation1() { byte[] metadata = new byte[FrameLengthCodec.FRAME_LENGTH_MASK]; byte[] data = new byte[FrameLengthCodec.FRAME_LENGTH_MASK]; ThreadLocalRandom.current().nextBytes(metadata); ThreadLocalRandom.current().nextBytes(data); final Payload payload = DefaultPayload.create(data, metadata); Assertions.assertThat(PayloadValidationUtils.isValid(0, payload)).isFalse(); }
Example 15
Source File: PayloadFlyweightTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void nextCompleteMetaData() { Payload payload = DefaultPayload.create( Unpooled.EMPTY_BUFFER, Unpooled.wrappedBuffer("md".getBytes(StandardCharsets.UTF_8))); ByteBuf nextComplete = PayloadFrameCodec.encodeNextCompleteReleasingPayload(ByteBufAllocator.DEFAULT, 1, payload); ByteBuf data = PayloadFrameCodec.data(nextComplete); String metadata = PayloadFrameCodec.metadata(nextComplete).toString(StandardCharsets.UTF_8); Assertions.assertTrue(data.readableBytes() == 0); Assertions.assertEquals("md", metadata); nextComplete.release(); }
Example 16
Source File: PayloadFlyweightTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void nextDataMetadata() { Payload payload = DefaultPayload.create("d", "md"); ByteBuf next = PayloadFrameCodec.encodeNextReleasingPayload(ByteBufAllocator.DEFAULT, 1, payload); String data = PayloadFrameCodec.data(next).toString(StandardCharsets.UTF_8); String metadata = PayloadFrameCodec.metadata(next).toString(StandardCharsets.UTF_8); Assertions.assertEquals("d", data); Assertions.assertEquals("md", metadata); next.release(); }
Example 17
Source File: PayloadFlyweightTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void nextData() { Payload payload = DefaultPayload.create("d"); ByteBuf next = PayloadFrameCodec.encodeNextReleasingPayload(ByteBufAllocator.DEFAULT, 1, payload); String data = PayloadFrameCodec.data(next).toString(StandardCharsets.UTF_8); ByteBuf metadata = PayloadFrameCodec.metadata(next); Assertions.assertEquals("d", data); Assertions.assertNull(metadata); next.release(); }
Example 18
Source File: PayloadFlyweightTest.java From rsocket-java with Apache License 2.0 | 5 votes |
@Test void nextDataEmptyMetadata() { Payload payload = DefaultPayload.create("d".getBytes(), new byte[0]); ByteBuf next = PayloadFrameCodec.encodeNextReleasingPayload(ByteBufAllocator.DEFAULT, 1, payload); String data = PayloadFrameCodec.data(next).toString(StandardCharsets.UTF_8); ByteBuf metadata = PayloadFrameCodec.metadata(next); Assertions.assertEquals("d", data); Assertions.assertEquals(metadata.readableBytes(), 0); next.release(); }
Example 19
Source File: ResumeFileTransfer.java From rsocket-java with Apache License 2.0 | 4 votes |
public Payload encode(Request request) { String encoded = request.getChunkSize() + ":" + request.getFileName(); return DefaultPayload.create(encoded); }
Example 20
Source File: RSocketConnector.java From rsocket-java with Apache License 2.0 | 3 votes |
/** * Provide a {@code Payload} with data and/or metadata for the initial {@code SETUP} frame. Data * and metadata should be formatted according to the MIME types specified via {@link * #dataMimeType(String)} and {@link #metadataMimeType(String)}. * * @param payload the payload containing data and/or metadata for the {@code SETUP} frame. Note, * if the instance of the given payload is not a {@link DefaultPayload}, its content will be * copied * @return the same instance for method chaining * @see <a href="https://github.com/rsocket/rsocket/blob/master/Protocol.md#frame-setup">SETUP * Frame</a> */ public RSocketConnector setupPayload(Payload payload) { if (payload instanceof DefaultPayload) { this.setupPayload = payload; } else { this.setupPayload = DefaultPayload.create(Objects.requireNonNull(payload)); payload.release(); } return this; }