Skip to content

Commit

Permalink
Fixed unit test JacksonSmileMessageCodecTest
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v committed Sep 1, 2023
1 parent 43c0ea7 commit 249bd76
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import io.scalecube.cluster.Member;
import io.scalecube.cluster.transport.api.Message;
import io.scalecube.cluster.transport.api.MessageCodec;
import io.scalecube.net.Address;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
Expand All @@ -17,12 +19,13 @@ class JacksonSmileMessageCodecTest {

private static final MessageCodec messageCodec = MessageCodec.INSTANCE;
private static final Random random = new Random();
private static final Member member = new Member("0", null, Address.NULL_ADDRESS, "NAMESPACE");

@Test
void serializeAndDeserializeByteBuffer() throws Exception {
byte[] bytes = "hello".getBytes();

Message to = Message.builder().data(new Entity(ByteBuffer.wrap(bytes))).build();
Message to = Message.builder().sender(member).data(new Entity(ByteBuffer.wrap(bytes))).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand All @@ -42,7 +45,7 @@ void serializeAndDeserializeDirectByteBuffer() throws Exception {
byteBuffer.put(bytes);
byteBuffer.flip();

Message to = Message.builder().data(new Entity(byteBuffer)).build();
Message to = Message.builder().sender(member).data(new Entity(byteBuffer)).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand All @@ -57,7 +60,7 @@ void serializeAndDeserializeDirectByteBuffer() throws Exception {
void serializeAndDeserializeEmptyByteBuffer() throws Exception {
byte[] bytes = new byte[0];

Message to = Message.builder().data(new Entity(ByteBuffer.wrap(bytes))).build();
Message to = Message.builder().sender(member).data(new Entity(ByteBuffer.wrap(bytes))).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand All @@ -82,7 +85,7 @@ void serializeAndDeserializeByteBufferWithOffset() throws Exception {
assertEquals(offset, byteBuffer.position());
assertEquals(bytes.length - offset, byteBuffer.remaining());

Message to = Message.builder().data(new Entity(byteBuffer)).build();
Message to = Message.builder().sender(member).data(new Entity(byteBuffer)).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand All @@ -106,7 +109,7 @@ void serializeAndDeserializeByteBufferWithOffsetSlice() throws Exception {
assertEquals(0, byteBuffer.position());
assertEquals(bytes.length - offset, byteBuffer.remaining());

Message to = Message.builder().data(new Entity(byteBuffer)).build();
Message to = Message.builder().sender(member).data(new Entity(byteBuffer)).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand Down Expand Up @@ -134,7 +137,7 @@ void serializeAndDeserializeDirectByteBufferWithOffset() throws Exception {
assertEquals(offset, byteBuffer.position());
assertEquals(bytes.length - offset, byteBuffer.remaining());

Message to = Message.builder().data(new Entity(byteBuffer)).build();
Message to = Message.builder().sender(member).data(new Entity(byteBuffer)).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand Down Expand Up @@ -162,7 +165,7 @@ void serializeAndDeserializeDirectByteBufferWithOffsetSlice() throws Exception {
assertEquals(0, slice.position());
assertEquals(bytes.length - offset, slice.remaining());

Message to = Message.builder().data(new Entity(slice)).build();
Message to = Message.builder().sender(member).data(new Entity(slice)).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand All @@ -178,7 +181,7 @@ void serializeAndDeserializeDirectByteBufferWithOffsetSlice() throws Exception {
void serializeAndDeserializeByteBufferWithoutEntity() throws Exception {
byte[] bytes = "hello".getBytes();

Message to = Message.builder().data(ByteBuffer.wrap(bytes)).build();
Message to = Message.builder().sender(member).data(ByteBuffer.wrap(bytes)).build();
ByteArrayOutputStream output = new ByteArrayOutputStream();

messageCodec.serialize(to, output);
Expand Down

0 comments on commit 249bd76

Please sign in to comment.