alex-plekhanov commented on code in PR #10768:
URL: https://github.com/apache/ignite/pull/10768#discussion_r1221414869
##########
modules/core/src/test/java/org/apache/ignite/internal/managers/communication/IgniteMessageFactoryImplTest.java:
##########
@@ -112,6 +132,75 @@ public void testRegisterTheSameType() {
new IgniteMessageFactoryImpl(factories);
}
+ /** */
+ @Test
+ public void testIoMessageSerializationAndDeserializationConsistency()
throws Exception {
+ TestMessageReader oneFieldReader = new TestMessageReader(1);
+ TestMessageWriter oneFieldWriter = new TestMessageWriter(1);
+
+ TestMessageReader unboundedReader = new TestMessageReader(MAX_VALUE);
+ TestMessageWriter unboundedWriter = new TestMessageWriter(MAX_VALUE);
+
+ IgniteMessageFactoryImpl msgFactory = new IgniteMessageFactoryImpl(new
MessageFactory[]{new GridIoMessageFactory()});
Review Comment:
What about `GridH2ValueMessageFactory` and `CalciteMessageFactory`?
##########
modules/core/src/test/java/org/apache/ignite/internal/managers/communication/IgniteMessageFactoryImplTest.java:
##########
@@ -112,6 +132,75 @@ public void testRegisterTheSameType() {
new IgniteMessageFactoryImpl(factories);
}
+ /** */
+ @Test
+ public void testIoMessageSerializationAndDeserializationConsistency()
throws Exception {
+ TestMessageReader oneFieldReader = new TestMessageReader(1);
+ TestMessageWriter oneFieldWriter = new TestMessageWriter(1);
+
+ TestMessageReader unboundedReader = new TestMessageReader(MAX_VALUE);
+ TestMessageWriter unboundedWriter = new TestMessageWriter(MAX_VALUE);
+
+ IgniteMessageFactoryImpl msgFactory = new IgniteMessageFactoryImpl(new
MessageFactory[]{new GridIoMessageFactory()});
+
+ for (short msgType : msgFactory.registeredDirectTypes()) {
+ checkSerializationAndDeserializationConsistency(msgFactory,
msgType, oneFieldWriter, unboundedReader);
+
+ checkSerializationAndDeserializationConsistency(msgFactory,
msgType, unboundedWriter, oneFieldReader);
+
+ checkSerializationAndDeserializationConsistency(msgFactory,
msgType, oneFieldWriter, oneFieldReader);
+
+ checkSerializationAndDeserializationConsistency(msgFactory,
msgType, unboundedWriter, unboundedReader);
+ }
+ }
+
+ /** */
+ private void checkSerializationAndDeserializationConsistency(
+ IgniteMessageFactory msgFactory,
+ short msgType,
+ TestMessageWriter writer,
+ TestMessageReader reader
+ ) throws Exception {
+ writer.reset();
+ reader.reset();
+
+ Message msg = msgFactory.create(msgType);
+
+ initializeMessage(msg);
+
+ while (!msg.writeTo(TEST_BYTE_BUFFER, writer)) {
+ // No-op.
+ }
+
+ msg = msgFactory.create(msgType);
+
+ reader.setCurrentReadClass(msg.getClass());
+
+ while (!msg.readFrom(TEST_BYTE_BUFFER, reader)) {
+ // No-op.
+ }
+
+ assertEquals("The serialization and deserialization protocol is not
consistent for the message [cls="
+ + msg.getClass().getName() + ']', writer.writtenFields,
reader.readFields);
+ }
+
+ /** */
+ private Message initializeMessage(Message msg) throws Exception {
+ if (msg instanceof NodeIdMessage) {
+ int msgSize = U.field(NodeIdMessage.class, "MESSAGE_SIZE");
+
+ FieldUtils.writeField(msg, "nodeIdBytes", new byte[msgSize], true);
+ }
+ else if (msg instanceof BinaryObjectImpl)
Review Comment:
Perhaps, it's better to fix BinaryObjectImpl and use method
`writeByteArray("valBytes", valBytes)` instead of `writeByteArray("valBytes",
valBytes, 0, valBytes.length)` with the same result, but removing exception in
test. WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]