Browse Source

Change order of argument for createPayload

Expecting data first and metadata second aligns better with the single
arg variant that accepts data. This is also consistent with the
RSocket API in the create methods of ByteBufPayload and DefaultPayload.
pull/23393/head
Rossen Stoyanchev 5 years ago
parent
commit
5e15bbfbf1
  1. 2
      spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequester.java
  2. 2
      spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java
  3. 4
      spring-messaging/src/main/java/org/springframework/messaging/rsocket/PayloadUtils.java
  4. 2
      spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultMetadataExtractorTests.java
  5. 8
      spring-messaging/src/test/java/org/springframework/messaging/rsocket/PayloadUtilsTests.java

2
spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequester.java

@ -235,7 +235,7 @@ final class DefaultRSocketRequester implements RSocketRequester { @@ -235,7 +235,7 @@ final class DefaultRSocketRequester implements RSocketRequester {
DataBufferUtils.release(data);
throw ex;
}
return PayloadUtils.createPayload(metadata, data);
return PayloadUtils.createPayload(data, metadata);
}
private Mono<Payload> emptyPayload() {

2
spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java

@ -202,7 +202,7 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder { @@ -202,7 +202,7 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
}
metadata = metadata != null ? metadata : emptyBuffer(strategies);
data = data != null ? data : emptyBuffer(strategies);
return PayloadUtils.createPayload(metadata, data);
return PayloadUtils.createPayload(data, metadata);
}
private DataBuffer emptyBuffer(RSocketStrategies strategies) {

4
spring-messaging/src/main/java/org/springframework/messaging/rsocket/PayloadUtils.java

@ -72,11 +72,11 @@ public abstract class PayloadUtils { @@ -72,11 +72,11 @@ public abstract class PayloadUtils {
* or using {@link Unpooled#wrappedBuffer(ByteBuffer...)} if necessary.
* Otherwise, if both are {@link DefaultDataBuffer}, then
* {@link DefaultPayload} is created.
* @param metadata the metadata part for the payload
* @param data the data part for the payload
* @param metadata the metadata part for the payload
* @return the created payload
*/
public static Payload createPayload(DataBuffer metadata, DataBuffer data) {
public static Payload createPayload(DataBuffer data, DataBuffer metadata) {
return data instanceof NettyDataBuffer || metadata instanceof NettyDataBuffer ?
ByteBufPayload.create(asByteBuf(data), asByteBuf(metadata)) :
DefaultPayload.create(asByteBuffer(data), asByteBuffer(metadata));

2
spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultMetadataExtractorTests.java

@ -163,7 +163,7 @@ public class DefaultMetadataExtractorTests { @@ -163,7 +163,7 @@ public class DefaultMetadataExtractorTests {
private Payload createPayload(DataBuffer metadata) {
return PayloadUtils.createPayload(metadata, this.strategies.dataBufferFactory().allocateBuffer());
return PayloadUtils.createPayload(this.strategies.dataBufferFactory().allocateBuffer(), metadata);
}
}

8
spring-messaging/src/test/java/org/springframework/messaging/rsocket/PayloadUtilsTests.java

@ -81,7 +81,7 @@ public class PayloadUtilsTests { @@ -81,7 +81,7 @@ public class PayloadUtilsTests {
NettyDataBuffer data = createNettyDataBuffer("sample data");
NettyDataBuffer metadata = createNettyDataBuffer("sample metadata");
Payload payload = PayloadUtils.createPayload(metadata, data);
Payload payload = PayloadUtils.createPayload(data, metadata);
try {
assertThat(payload).isInstanceOf(ByteBufPayload.class);
assertThat(payload.data()).isSameAs(data.getNativeBuffer());
@ -96,7 +96,7 @@ public class PayloadUtilsTests { @@ -96,7 +96,7 @@ public class PayloadUtilsTests {
public void createWithDefaultBuffers() {
DataBuffer data = createDefaultDataBuffer("sample data");
DataBuffer metadata = createDefaultDataBuffer("sample metadata");
Payload payload = PayloadUtils.createPayload(metadata, data);
Payload payload = PayloadUtils.createPayload(data, metadata);
assertThat(payload).isInstanceOf(DefaultPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(dataBufferToString(data));
@ -107,7 +107,7 @@ public class PayloadUtilsTests { @@ -107,7 +107,7 @@ public class PayloadUtilsTests {
public void createWithNettyAndDefaultBuffers() {
NettyDataBuffer data = createNettyDataBuffer("sample data");
DefaultDataBuffer metadata = createDefaultDataBuffer("sample metadata");
Payload payload = PayloadUtils.createPayload(metadata, data);
Payload payload = PayloadUtils.createPayload(data, metadata);
try {
assertThat(payload).isInstanceOf(ByteBufPayload.class);
assertThat(payload.data()).isSameAs(data.getNativeBuffer());
@ -122,7 +122,7 @@ public class PayloadUtilsTests { @@ -122,7 +122,7 @@ public class PayloadUtilsTests {
public void createWithDefaultAndNettyBuffers() {
DefaultDataBuffer data = createDefaultDataBuffer("sample data");
NettyDataBuffer metadata = createNettyDataBuffer("sample metadata");
Payload payload = PayloadUtils.createPayload(metadata, data);
Payload payload = PayloadUtils.createPayload(data, metadata);
try {
assertThat(payload).isInstanceOf(ByteBufPayload.class);
assertThat(payload.getDataUtf8()).isEqualTo(dataBufferToString(data));

Loading…
Cancel
Save