SammyVimes commented on a change in pull request #102:
URL: https://github.com/apache/ignite-3/pull/102#discussion_r628204254



##########
File path: 
modules/network/src/test/java/org/apache/ignite/network/internal/netty/InboundDecoderTest.java
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network.internal.netty;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.UnpooledByteBufAllocator;
+import io.netty.channel.embedded.EmbeddedChannel;
+import java.nio.ByteBuffer;
+import java.util.Random;
+import java.util.stream.IntStream;
+import java.util.stream.LongStream;
+import org.apache.ignite.network.internal.AllTypesMessage;
+import org.apache.ignite.network.internal.AllTypesMessageGenerator;
+import org.apache.ignite.network.internal.AllTypesMessageSerializationFactory;
+import org.apache.ignite.network.internal.direct.DirectMessageWriter;
+import org.apache.ignite.network.message.MessageSerializationRegistry;
+import org.apache.ignite.network.message.MessageSerializer;
+import org.apache.ignite.network.message.NetworkMessage;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Tests for {@link InboundDecoder}.
+ */
+public class InboundDecoderTest {
+    /**
+     * Tests that an {@link InboundDecoder} can successfully read a message 
with all types supported
+     * by direct marshalling.
+     *
+     * @param seed Random seed.
+     * @throws Exception If failed.
+     */
+    @ParameterizedTest
+    @MethodSource("messageGenerationSeed")
+    public void test(long seed) throws Exception {
+        var registry = new MessageSerializationRegistry();
+
+        AllTypesMessage msg = AllTypesMessageGenerator.generate(seed, true);
+
+        registry.registerFactory(msg.directType(), new 
AllTypesMessageSerializationFactory());
+
+        var channel = new EmbeddedChannel(new InboundDecoder(registry));
+
+        var writer = new DirectMessageWriter(registry, 
ConnectionManager.DIRECT_PROTOCOL_VERSION);
+
+        MessageSerializer<NetworkMessage> serializer = 
registry.createSerializer(msg.directType());
+
+        UnpooledByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;
+
+        ByteBuffer buf = ByteBuffer.allocate(10_000);
+
+        AllTypesMessage output;
+
+        do {
+            buf.clear();
+
+            writer.setBuffer(buf);

Review comment:
       Whoops, I forgot, we actually do need to do that: the buffer is cleared 
after every write




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to