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_r405106456
 
 

 ##########
 File path: 
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsOutputStreamStatistics.java
 ##########
 @@ -0,0 +1,296 @@
+/**
+ * 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 ITestAbfsOutputStreamStatistics
+    extends AbstractAbfsIntegrationTest {
+  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;
+
+  public ITestAbfsOutputStreamStatistics() throws Exception {
+  }
+
+  /**
+   * 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 = path(getMethodName());
+    String testBytesToUpload = "bytes";
+
+    try (AbfsOutputStream outForSomeBytes = createAbfsOutputStream(fs,
+        uploadBytesFilePath)
+    ) {
+
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatisticsForUploadBytes =
+          outForSomeBytes.getOutputStreamStatistics();
+
+      //Test for zero bytes To upload.
+      assertValues("bytes to upload", 0,
+          abfsOutputStreamStatisticsForUploadBytes.getBytesToUpload());
+
+      outForSomeBytes.write(testBytesToUpload.getBytes());
+      outForSomeBytes.flush();
+      abfsOutputStreamStatisticsForUploadBytes =
+          outForSomeBytes.getOutputStreamStatistics();
+
+      //Test for bytes to upload.
+      assertValues("bytes to upload", testBytesToUpload.getBytes().length,
+          abfsOutputStreamStatisticsForUploadBytes.getBytesToUpload());
+
+      //Test for successful bytes uploaded.
+      assertValues("successful bytes uploaded",
+          testBytesToUpload.getBytes().length,
+          abfsOutputStreamStatisticsForUploadBytes.getBytesUploadSuccessful());
+
+      //Populating random value for bytesFailed.
+      int randomBytesFailed = new Random().nextInt(LOW_RANGE_FOR_RANDOM_VALUE);
+      abfsOutputStreamStatisticsForUploadBytes.uploadFailed(randomBytesFailed);
+      //Test for bytes failed to upload.
+      assertValues("number fo bytes failed to upload", randomBytesFailed,
+          abfsOutputStreamStatisticsForUploadBytes.getBytesUploadFailed());
+
+    }
+
+    try (AbfsOutputStream outForLargeBytes = createAbfsOutputStream(fs,
+        uploadBytesFilePath)) {
+
+      for (int i = 0; i < LARGE_OPERATIONS; i++) {
+        outForLargeBytes.write(testBytesToUpload.getBytes());
+      }
+      outForLargeBytes.flush();
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          outForLargeBytes.getOutputStreamStatistics();
+
+      //Test for bytes to upload.
+      assertValues("bytes to upload",
+          LARGE_OPERATIONS * (testBytesToUpload.getBytes().length),
+          abfsOutputStreamStatistics.getBytesToUpload());
+
+      //Test for successful bytes uploaded.
+      assertValues("successful bytes uploaded",
+          LARGE_OPERATIONS * (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 = path(getMethodName());
+
+    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 spend on waiting for tasks to complete", 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 spend on waiting for tasks to complete",
+          smallDiff + randomDiff,
+          abfsOutputStreamStatistics.getTimeSpendOnTaskWait());
+    }
+
+  }
+
+  /**
+   * Tests to check number of {@code
+   * AbfsOutputStream#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 = path(getMethodName());
+    String testQueueShrink = "testQueue";
+
+    try (AbfsOutputStream outForOneOp = createAbfsOutputStream(fs,
+        queueShrinkFilePath)) {
+
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          outForOneOp.getOutputStreamStatistics();
+
+      //Test for shrinking Queue zero time.
+      assertValues("Queue shrunk operations", 0,
+          abfsOutputStreamStatistics.getQueueShrunkOps());
+
+      outForOneOp.write(testQueueShrink.getBytes());
+      // Queue is shrunk 2 times when outputStream is flushed.
+      outForOneOp.flush();
+
+      abfsOutputStreamStatistics = outForOneOp.getOutputStreamStatistics();
+
+      //Test for shrinking Queue 2 times.
+      assertValues("Queue shrunk operations", 2,
+          abfsOutputStreamStatistics.getQueueShrunkOps());
+
+    }
+
+    try (AbfsOutputStream outForLargeOps = createAbfsOutputStream(fs,
+        queueShrinkFilePath)) {
+      for (int i = 0; i < LARGE_OPERATIONS; i++) {
+        outForLargeOps.write(testQueueShrink.getBytes());
+        outForLargeOps.flush();
+      }
+
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          outForLargeOps.getOutputStreamStatistics();
+
+      //Test for 20 queue shrink operations.
+      assertValues("Queue shrunk operations",
+          2 * LARGE_OPERATIONS,
+          abfsOutputStreamStatistics.getQueueShrunkOps());
+    }
+
+  }
+
+  /**
+   * Test to check number of {@code
+   * AbfsOutputStream#writeCurrentBufferToService()} calls.
+   * After writing data, AbfsOutputStream doesn't upload data till flush() is
+   * called. Hence, flush() calls were made after write() to simulate the
+   * scenario.
+   *
+   * @throws IOException
+   */
+  @Test
+  public void testAbfsOutputStreamWriteBuffer() throws IOException {
+    describe("Testing writeCurrentBufferToService() calls");
+    final AzureBlobFileSystem fs = getFileSystem();
+    Path writeBufferFilePath = path(getMethodName());
+    String testWriteBuffer = "Buffer";
+
+    try (AbfsOutputStream outForOneOp = createAbfsOutputStream(fs,
+        writeBufferFilePath)) {
+
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          outForOneOp.getOutputStreamStatistics();
+
+      //Test for zero time writing Buffer to service.
+      assertValues("number writeCurrentBufferToService() calls", 0,
+          abfsOutputStreamStatistics.getWriteCurrentBufferOperations());
+
+      outForOneOp.write(testWriteBuffer.getBytes());
+      outForOneOp.flush();
+
+      abfsOutputStreamStatistics = outForOneOp.getOutputStreamStatistics();
+
+      //Test for one time writeCurrentBuffer() call.
+      assertValues("number writeCurrentBufferToService() calls", 1,
+          abfsOutputStreamStatistics.getWriteCurrentBufferOperations());
+    }
+
+    try (AbfsOutputStream outForLargeOps = createAbfsOutputStream(fs,
+        writeBufferFilePath)) {
+
+      for (int i = 0; i < LARGE_OPERATIONS; i++) {
+        outForLargeOps.write(testWriteBuffer.getBytes());
+        outForLargeOps.flush();
+      }
+      AbfsOutputStreamStatisticsImpl abfsOutputStreamStatistics =
+          outForLargeOps.getOutputStreamStatistics();
+      //Test for 10 writeBufferOperations.
+      assertValues("number of writeCurrentBufferToService() calls",
+          LARGE_OPERATIONS,
+          abfsOutputStreamStatistics.getWriteCurrentBufferOperations());
+    }
+
+  }
+
+  /**
+   * Generic create File and setting OutputStreamFlush to false.
 
 Review comment:
   *disableOutputStreamFlush

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to