-
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 2 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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ public class ClickHouseAsyncSinkSerializer extends AsyncSinkWriterStateSerialize | |
| protected void serializeRequestToStream(ClickHousePayload clickHousePayload, DataOutputStream dataOutputStream) throws IOException { | ||
| byte[] bytes = clickHousePayload.getPayload(); | ||
| if (bytes != null) { | ||
| dataOutputStream.writeInt(V1); | ||
| dataOutputStream.writeInt(bytes.length); | ||
| dataOutputStream.write(bytes); | ||
| } else { | ||
|
|
@@ -34,11 +35,16 @@ private ClickHousePayload deserializeV1(DataInputStream dataInputStream) throws | |
| } | ||
|
|
||
| @Override | ||
| protected ClickHousePayload deserializeRequestFromStream(long version, DataInputStream dataInputStream) throws IOException { | ||
| if (version == V1) { | ||
| return deserializeV1(dataInputStream); | ||
| protected ClickHousePayload deserializeRequestFromStream(long requestSize, DataInputStream dataInputStream) throws IOException { | ||
| if (requestSize > 0) { | ||
| int version = dataInputStream.readInt(); | ||
| if (version == V1) { | ||
| return deserializeV1(dataInputStream); | ||
| } else { | ||
| throw new IOException("Unsupported version " + version); | ||
mzitnik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } else { | ||
| throw new IOException("Unsupported version: " + version); | ||
| throw new IOException("Request size: " + requestSize); | ||
mzitnik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
39
to
49
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 a mismatch between serialization and deserialization logic. In Consider ensuring the serialization and deserialization logic are symmetric to maintain backward compatibility. |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| 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.ByteArrayInputStream; | ||||||
| import java.io.ByteArrayOutputStream; | ||||||
| import java.io.DataInputStream; | ||||||
| import java.io.DataOutputStream; | ||||||
|
|
||||||
| public class ClickHouseSinkStateTests { | ||||||
mzitnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| @Test | ||||||
| void SerializerTest() throws Exception { | ||||||
mzitnik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| 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()); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| 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.ByteArrayInputStream; | ||||||
| import java.io.ByteArrayOutputStream; | ||||||
| import java.io.DataInputStream; | ||||||
| import java.io.DataOutputStream; | ||||||
|
|
||||||
| public class ClickHouseSinkStateTests { | ||||||
|
|
||||||
| @Test | ||||||
| void SerializerTest() 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 deserialization step.
Suggested change
|
||||||
| Assertions.assertEquals(clickHousePayload.getPayloadLength(), clickHousePayload1.getPayloadLength()); | ||||||
| Assertions.assertArrayEquals(clickHousePayload.getPayload(), clickHousePayload1.getPayload()); | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.