You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/11/12 06:10:20 UTC

[GitHub] [incubator-ratis] szetszwo commented on a change in pull request #272: RATIS-1130. Add E2E test for Ratis streaming based on MiniRaftCluster

szetszwo commented on a change in pull request #272:
URL: https://github.com/apache/incubator-ratis/pull/272#discussion_r521858513



##########
File path: ratis-client/src/main/java/org/apache/ratis/client/api/DataStreamApi.java
##########
@@ -36,5 +38,5 @@
  */
 public interface DataStreamApi {
   /** Create a stream to write data. */
-  DataStreamOutput stream();
+  DataStreamOutputRpc stream();

Review comment:
       DataStreamApi is user API.  We want to hide the RPC API from users.  So, please don't make this change.
   
   We may cast it to DataStreamOutputRpc in the test.

##########
File path: ratis-server/src/main/java/org/apache/ratis/server/DisabledDataStreamServerFactory.java
##########
@@ -33,6 +34,11 @@ public DataStreamServerRpc newDataStreamServerRpc(RaftServer server) {
       @Override
       public void start() {}
 
+      @Override
+      public InetSocketAddress getInetSocketAddress() {
+        return InetSocketAddress.createUnresolved("0.0.0.0", 0);

Review comment:
       Is it okay to return null?

##########
File path: ratis-server/src/test/java/org/apache/ratis/DataStreamTestUtils.java
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.ratis;
+
+import java.nio.ByteBuffer;
+import org.junit.Assert;
+
+public class DataStreamTestUtils {
+    public static final int MODULUS = 23;
+
+    public static byte pos2byte(int pos) {
+        return (byte) ('A' + pos%MODULUS);
+    }
+
+    public static ByteBuffer initBuffer(int offset, int size) {
+        final ByteBuffer buffer = ByteBuffer.allocateDirect(size);
+        final int length = buffer.capacity();
+        buffer.position(0).limit(length);
+        for (int j = 0; j < length; j++) {
+            buffer.put(pos2byte(offset + j));
+        }
+        buffer.flip();
+        Assert.assertEquals(length, buffer.remaining());
+        return buffer;
+    }

Review comment:
       2-space indentations please.

##########
File path: ratis-server/src/test/java/org/apache/ratis/DataStreamTests.java
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.ratis;
+
+import static org.apache.ratis.DataStreamTestUtils.initBuffer;
+import static org.apache.ratis.RaftTestUtil.waitForLeader;
+
+import org.apache.ratis.client.DataStreamOutputRpc;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto;
+import org.apache.ratis.protocol.DataStreamReply;
+import org.apache.ratis.protocol.RaftGroup;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.server.impl.RaftServerImpl;
+import org.apache.ratis.server.protocol.TermIndex;
+import org.apache.ratis.server.raftlog.RaftLog;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ThreadLocalRandom;
+
+public abstract class DataStreamTests <CLUSTER extends MiniRaftCluster> extends BaseTest

Review comment:
       2-space indentation please.

##########
File path: ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyServerStreamRpc.java
##########
@@ -326,8 +327,11 @@ private StreamInfo newStreamInfo(ByteBuf buf) {
   }
 
   static long writeTo(ByteBuf buf, DataStream stream) {
-    final WritableByteChannel channel = stream.getWritableByteChannel();
     long byteWritten = 0;
+    if (stream == null) {

Review comment:
       Why the stream could be null?




----------------------------------------------------------------
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:
users@infra.apache.org