-
Notifications
You must be signed in to change notification settings - Fork 1
Fix serialize and add test. #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||
| package org.apache.flink.connector.clickhouse.sink; | ||||||
|
|
||||||
| import org.apache.flink.connector.clickhouse.data.ClickHousePayload; | ||||||
| import org.junit.jupiter.api.Assertions; | ||||||
| import org.junit.jupiter.api.Test; | ||||||
|
|
||||||
| import java.io.*; | ||||||
|
|
||||||
| public class ClickHouseSinkStateTests { | ||||||
mzitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| @Test | ||||||
| void testSerializeAndDeserializePayload() throws Exception { | ||||||
| byte[] data = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'}; | ||||||
| ClickHousePayload clickHousePayload = new ClickHousePayload(data); | ||||||
|
|
||||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||||
| DataOutputStream dos = new DataOutputStream(baos); | ||||||
| ClickHouseAsyncSinkSerializer serializer = new ClickHouseAsyncSinkSerializer(); | ||||||
| serializer.serializeRequestToStream(clickHousePayload, dos); | ||||||
| DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||||||
|
|
||||||
| ClickHousePayload clickHousePayload1 = serializer.deserializeRequestFromStream(dos.size(), dis); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an issue with the size parameter in the deserialization call. DataOutputStream doesn't have a size() method, but ByteArrayOutputStream does. You should use
Suggested change
|
||||||
| Assertions.assertEquals(clickHousePayload.getPayloadLength(), clickHousePayload1.getPayloadLength()); | ||||||
| Assertions.assertArrayEquals(clickHousePayload.getPayload(), clickHousePayload1.getPayload()); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void testSerializeAndDeserializeEmptyPayload() throws Exception { | ||||||
| ClickHousePayload clickHousePayload = new ClickHousePayload(null); | ||||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||||
| DataOutputStream dos = new DataOutputStream(baos); | ||||||
| ClickHouseAsyncSinkSerializer serializer = new ClickHouseAsyncSinkSerializer(); | ||||||
| serializer.serializeRequestToStream(clickHousePayload, dos); | ||||||
| DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||||||
| ClickHousePayload clickHousePayload1 = serializer.deserializeRequestFromStream(dos.size(), dis); | ||||||
| Assertions.assertEquals(clickHousePayload.getPayloadLength(), clickHousePayload1.getPayloadLength()); | ||||||
| Assertions.assertArrayEquals(clickHousePayload.getPayload(), clickHousePayload1.getPayload()); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void testDeserializePayloadWithUnsuportedVersion() throws IOException { | ||||||
| byte[] data = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'}; | ||||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||||
| DataOutputStream dos = new DataOutputStream(baos); | ||||||
| DataOutputStream dataOutputStream = new DataOutputStream(baos); | ||||||
| int V2 = 2; | ||||||
| dataOutputStream.writeInt(V2); | ||||||
| dataOutputStream.writeInt(data.length); | ||||||
| dataOutputStream.write(data); | ||||||
| DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||||||
|
|
||||||
| ClickHouseAsyncSinkSerializer serializer = new ClickHouseAsyncSinkSerializer(); | ||||||
| Exception exception = Assertions.assertThrows(IOException.class, () -> { | ||||||
| serializer.deserializeRequestFromStream(dataOutputStream.size(), dis); | ||||||
| }); | ||||||
| Assertions.assertEquals("Unsupported serialization version: 2", exception.getMessage()); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||
| package org.apache.flink.connector.clickhouse.sink; | ||||||
|
|
||||||
| import org.apache.flink.connector.clickhouse.data.ClickHousePayload; | ||||||
| import org.junit.jupiter.api.Assertions; | ||||||
| import org.junit.jupiter.api.Test; | ||||||
|
|
||||||
| import java.io.*; | ||||||
|
|
||||||
| public class ClickHouseSinkStateTests { | ||||||
|
|
||||||
| @Test | ||||||
| void testSerializeAndDeserializePayload() throws Exception { | ||||||
| byte[] data = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'}; | ||||||
| ClickHousePayload clickHousePayload = new ClickHousePayload(data); | ||||||
|
|
||||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||||
| DataOutputStream dos = new DataOutputStream(baos); | ||||||
| ClickHouseAsyncSinkSerializer serializer = new ClickHouseAsyncSinkSerializer(); | ||||||
| serializer.serializeRequestToStream(clickHousePayload, dos); | ||||||
| DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||||||
| ClickHousePayload clickHousePayload1 = serializer.deserializeRequestFromStream(dos.size(), dis); | ||||||
| Assertions.assertEquals(clickHousePayload.getPayloadLength(), clickHousePayload1.getPayloadLength()); | ||||||
| Assertions.assertArrayEquals(clickHousePayload.getPayload(), clickHousePayload1.getPayload()); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void testSerializeAndDeserializeEmptyPayload() throws Exception { | ||||||
| ClickHousePayload clickHousePayload = new ClickHousePayload(null); | ||||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||||
| DataOutputStream dos = new DataOutputStream(baos); | ||||||
| ClickHouseAsyncSinkSerializer serializer = new ClickHouseAsyncSinkSerializer(); | ||||||
| serializer.serializeRequestToStream(clickHousePayload, dos); | ||||||
| DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||||||
| ClickHousePayload clickHousePayload1 = serializer.deserializeRequestFromStream(dos.size(), dis); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an issue with the deserialization step.
Suggested change
|
||||||
| Assertions.assertEquals(clickHousePayload.getPayloadLength(), clickHousePayload1.getPayloadLength()); | ||||||
| Assertions.assertArrayEquals(clickHousePayload.getPayload(), clickHousePayload1.getPayload()); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void testDeserializePayloadWithUnsuportedVersion() throws IOException { | ||||||
| byte[] data = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'}; | ||||||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||||||
| DataOutputStream dos = new DataOutputStream(baos); | ||||||
| DataOutputStream dataOutputStream = new DataOutputStream(baos); | ||||||
| int V2 = 2; | ||||||
| dataOutputStream.writeInt(V2); | ||||||
| dataOutputStream.writeInt(data.length); | ||||||
| dataOutputStream.write(data); | ||||||
| DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||||||
|
|
||||||
| ClickHouseAsyncSinkSerializer serializer = new ClickHouseAsyncSinkSerializer(); | ||||||
| Exception exception = Assertions.assertThrows(IOException.class, () -> { | ||||||
| serializer.deserializeRequestFromStream(dataOutputStream.size(), dis); | ||||||
| }); | ||||||
| Assertions.assertEquals("Unsupported serialization version: 2", exception.getMessage()); | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.