Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Test fixed size arrays #67

Merged
merged 4 commits into from
Apr 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.assertTrue;

import com.google.common.collect.Lists;
import java.util.Arrays;

import org.jboss.netty.buffer.ChannelBuffer;
import org.junit.Before;
Expand Down Expand Up @@ -266,4 +267,127 @@ public void testFloat64Array() {
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testChannelBufferFixedSizeWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
buffer.writeBytes(new byte[] { 1, 2, 3, 4, 5 });
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setChannelBuffer("data", buffer);
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testChannelBufferFixedSizeWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
buffer.writeBytes(new byte[] { 1, 2, 3 });
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setChannelBuffer("data", buffer);
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testChannelBufferFixedSizeNoInitialization() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this test and a simple byte array? Should we add a byte array test too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will see to add tests for byte arrays, although according to this comment ChannelBuffer is the preferred way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found this in the RawMessage interface:

  /**
   * @deprecated replaced by {@link #setInt8(String, byte)}
   */
  void setByte(String name, byte value);

  /**
   * @deprecated replaced by {@link #setInt8Array(String, byte[])}
   */
  void setByteArray(String name, byte[] value);

  /**
   * @deprecated replaced by {@link #setUInt8(String, byte)}
   */
  void setChar(String name, short value);

  /**
   * @deprecated replaced by {@link #setUInt8Array(String, byte[])}
   */
  void setCharArray(String name, short[] value);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the tests for byte arrays and they are failing too.

image

topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setChannelBuffer("data", buffer);
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testInt32FixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt32Array("data", new int[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testInt32FixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt32Array("data", new int[] { 1, 2, 3 });
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testInt32FixedSizeArrayNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testFloat64FixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testFloat64FixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3 });
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testFloat64FixedSizeArrayNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testStringFixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
String[] stringArray = new String[] { "String 1", "String 2", "String 3", "String 4", "String 5" };
rawMessage.setStringList("data", Arrays.asList(stringArray));
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testStringFixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
String[] stringArray = new String[] { "String 1", "String 2", "String 3" };
rawMessage.setStringList("data", Arrays.asList(stringArray));
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testStringFixedSizeArrayWithNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testByteFixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt8Array("data", new byte[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testByteFixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt8Array("data", new byte[] { 1, 2, 3 });
checkSerializeAndDeserialize(rawMessage);
}

@Test
public void testByteFixedSizeArrayWithNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}
}