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



##########
File path: 
ratis-test/src/test/java/org/apache/ratis/datastream/TestDataStream.java
##########
@@ -72,27 +129,47 @@ public void testDataStream(){
   }
 
   public void runTestDataStream(){
-    DataStreamOutput stream = client.stream();
-    ByteBuffer bf = ByteBuffer.allocateDirect(1024*1024);
-    for (int i = 0; i < bf.capacity(); i++) {
-      bf.put((byte)'a');
-    }
-    bf.flip();
-    int i = 0;
+    final int bufferSize = 1024*1024;
+    final int bufferNum = 10;
+    final DataStreamOutput out = client.stream();
 
-    while(i < 1000){
-      bf.position(0).limit(bf.capacity());
-      futures.add(stream.streamAsync(bf));
-      i++;
+    final List<CompletableFuture<DataStreamReply>> futures = new ArrayList<>();
+    futures.add(sendRequest(out, 1024));
+
+    //send data
+    final int halfBufferSize = bufferSize/2;
+    int dataSize = 0;
+    for(int i = 0; i < bufferNum; i++) {
+      final int size = halfBufferSize + 
ThreadLocalRandom.current().nextInt(halfBufferSize);
+      final ByteBuffer bf = initBuffer(dataSize, size);
+      futures.add(out.streamAsync(bf));
+      dataSize += size;
     }
-    try {
-      Thread.sleep(1000*3);
-    } catch (InterruptedException e) {
-      e.printStackTrace();
+    for(int i = 0; i < futures.size(); i++){
+      futures.get(i).join();
     }
+    Assert.assertEquals(dataSize, byteWritten);
     shutDownSetup();
-    for(i = 0; i < futures.size(); i++){
-      Assert.assertTrue(futures.get(i).isDone());
+  }
+
+  CompletableFuture<DataStreamReply> sendRequest(DataStreamOutput out, int 
size) {
+    // TODO RATIS-1085: create a RaftClientRequest and put it in the buffer
+    final ByteBuffer buffer = initBuffer(0, size);
+    return out.streamAsync(buffer);
+  }
+
+  static ByteBuffer initBuffer(int offset, int size) {
+    final ByteBuffer buffer = ByteBuffer.allocateDirect(size);
+    final int length = buffer.capacity();
+    buffer.position(0).limit(length);
+    final StringBuilder b = new StringBuilder();

Review comment:
       Yes, it is useless.




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