mehakmeet commented on a change in pull request #1899: HADOOP-16914 Adding 
Output Stream Counters in ABFS
URL: https://github.com/apache/hadoop/pull/1899#discussion_r404807005
 
 

 ##########
 File path: 
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsOutputStream.java
 ##########
 @@ -0,0 +1,294 @@
+/**
+ * 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.hadoop.fs.azurebfs;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.junit.Test;
+
+import org.apache.hadoop.fs.Path;
+import 
org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
+import org.apache.hadoop.fs.azurebfs.services.AbfsOutputStream;
+import org.apache.hadoop.fs.azurebfs.services.AbfsOutputStreamStatisticsImpl;
+import org.apache.hadoop.fs.permission.FsPermission;
+
+/**
+ * Test AbfsOutputStream statistics.
+ */
+public class ITestAbfsOutputStream extends AbstractAbfsIntegrationTest {
+  public ITestAbfsOutputStream() throws Exception {
+  }
+
+  private static final int LARGE_OPERATIONS = 10;
+  private static final int LOW_RANGE_FOR_RANDOM_VALUE = 49;
+  private static final int HIGH_RANGE_FOR_RANDOM_VALUE = 9999;
+
+  /**
+   * Tests to check bytes Uploading in {@link AbfsOutputStream}.
+   *
+   * @throws IOException
+   */
+  @Test
+  public void testAbfsOutputStreamUploadingBytes() throws IOException {
+    describe("Testing Bytes uploaded in AbfsOutputSteam");
+    final AzureBlobFileSystem fs = getFileSystem();
+    Path uploadBytesFilePath = new Path("AbfsOutputStreamStatsPath");
+    String testBytesToUpload = "bytes";
+
+    try (AbfsOutputStream outForSomeBytes = createAbfsOutputStream(fs,
+        uploadBytesFilePath)
+    ) {
+
+      //Test for zero bytes To upload
+      assertValues("bytes to upload", 0,
+          outForSomeBytes.getOutputStreamStatistics().getBytesToUpload());
+
+      outForSomeBytes.write(testBytesToUpload.getBytes());
+      outForSomeBytes.flush();
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          outForSomeBytes.getOutputStreamStatistics();
+
+      //Test for bytes to upload
+      assertValues("bytes to upload", testBytesToUpload.getBytes().length,
+          abfsOutputStreamStatistics.getBytesToUpload());
+
+      //Test for successful bytes uploaded
+      assertValues("successful bytes uploaded",
+          testBytesToUpload.getBytes().length,
+          abfsOutputStreamStatistics.getBytesUploadSuccessful());
+
+      //Populating random value for bytesFailed
+      int randomBytesFailed = new Random().nextInt(LOW_RANGE_FOR_RANDOM_VALUE);
+      abfsOutputStreamStatistics.uploadFailed(randomBytesFailed);
+      //Test for bytes failed to upload
+      assertValues("number fo bytes failed to upload", randomBytesFailed,
+          abfsOutputStreamStatistics.getBytesUploadFailed());
+
+    }
+
+    try (AbfsOutputStream outForLargeBytes = createAbfsOutputStream(fs,
+        uploadBytesFilePath)) {
+
+      int largeValue = LARGE_OPERATIONS;
+      for (int i = 0; i < largeValue; i++) {
+        outForLargeBytes.write(testBytesToUpload.getBytes());
+      }
+      outForLargeBytes.flush();
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          outForLargeBytes.getOutputStreamStatistics();
+
+      //Test for bytes to upload
+      assertValues("bytes to upload",
+          largeValue * (testBytesToUpload.getBytes().length),
+          abfsOutputStreamStatistics.getBytesToUpload());
+
+      //Test for successful bytes uploaded
+      assertValues("successful bytes uploaded",
+          largeValue * (testBytesToUpload.getBytes().length),
+          abfsOutputStreamStatistics.getBytesUploadSuccessful());
+
+      //Populating random values for bytesFailed
+      int randomBytesFailed = new 
Random().nextInt(HIGH_RANGE_FOR_RANDOM_VALUE);
+      abfsOutputStreamStatistics.uploadFailed(randomBytesFailed);
+      //Test for bytes failed to upload
+      assertValues("bytes failed to upload", randomBytesFailed,
+          abfsOutputStreamStatistics.getBytesUploadFailed());
+    }
+  }
+
+  /**
+   * Tests to check time spent on waiting for tasks to be complete on a
+   * blocking queue in {@link AbfsOutputStream}.
+   *
+   * @throws IOException
+   */
+  @Test
+  public void testAbfsOutputStreamTimeSpentOnWaitTask() throws IOException {
+    describe("Testing Time Spend on Waiting for Task to be complete");
+    final AzureBlobFileSystem fs = getFileSystem();
+    Path timeSpendFilePath = new Path("AbfsOutputStreamStatsPath");
+
+    try (AbfsOutputStream out = createAbfsOutputStream(fs, timeSpendFilePath)) 
{
+
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          out.getOutputStreamStatistics();
+
+      //Test for initial value of timeSpentWaitTask
+      assertValues("Time spent on waiting tasks", 0,
+          abfsOutputStreamStatistics.getTimeSpendOnTaskWait());
+
+      int smallRandomStartTime =
+          new Random().nextInt(LOW_RANGE_FOR_RANDOM_VALUE);
+      int smallRandomEndTime =
+          new Random().nextInt(LOW_RANGE_FOR_RANDOM_VALUE)
+              + smallRandomStartTime;
+      int smallDiff = smallRandomEndTime - smallRandomStartTime;
+      abfsOutputStreamStatistics
+          .timeSpentTaskWait(smallRandomStartTime, smallRandomEndTime);
+      //Test for small random value of timeSpentWaitTask
+      assertValues("Time spent on waiting tasks", smallDiff,
+          abfsOutputStreamStatistics.getTimeSpendOnTaskWait());
+
+      int largeRandomStartTime =
+          new Random().nextInt(HIGH_RANGE_FOR_RANDOM_VALUE);
+      int largeRandomEndTime = new 
Random().nextInt(HIGH_RANGE_FOR_RANDOM_VALUE)
+          + largeRandomStartTime;
+      int randomDiff = largeRandomEndTime - largeRandomStartTime;
+      abfsOutputStreamStatistics
+          .timeSpentTaskWait(largeRandomStartTime, largeRandomEndTime);
+      /*
+      Test for large random value of timeSpentWaitTask plus the time spent
+      in previous test
+       */
+      assertValues("Time spent on waiting tasks", smallDiff + randomDiff,
+          abfsOutputStreamStatistics.getTimeSpendOnTaskWait());
+    }
+
+  }
+
+  /**
+   * Tests to check number of {@code shrinkWriteOperationQueue()}
+   * calls.
+   * After writing data, AbfsOutputStream doesn't upload the data until
+   * Flushed. Hence, flush() method is called after write() to test Queue
+   * shrink calls.
+   *
+   * @throws IOException
+   */
+  @Test
+  public void testAbfsOutputStreamQueueShrink() throws IOException {
+    describe("Testing Queue Shrink calls in AbfsOutputStream");
+    final AzureBlobFileSystem fs = getFileSystem();
+    Path queueShrinkFilePath = new Path("AbfsOutputStreamStatsPath");
+    String testQueueShrink = "testQueue";
+
+    try (AbfsOutputStream outForOneOp = createAbfsOutputStream(fs,
+        queueShrinkFilePath)) {
+
+      //Test for shrinking Queue zero time
+      assertValues("number of queueShrink() Calls", 0,
+          outForOneOp.getOutputStreamStatistics().getQueueShrink());
+
+      outForOneOp.write(testQueueShrink.getBytes());
+      // Queue is shrunk 2 times when outStream is flushed
+      outForOneOp.flush();
+
+      //Test for shrinking Queue 2 times
+      assertValues("number of queueShrink() Calls", 2,
+          outForOneOp.getOutputStreamStatistics().getQueueShrink());
+
+    }
+
 
 Review comment:
   I am setting disableOutputStreamFlush to false, which implies flush is 
enabled.

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to