mukund-thakur 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_r404608299
 
 

 ##########
 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
 
 Review comment:
   Looks like this an UT. Should move under UT folder. Create a new class 
TestAbfsOutputStreamStatictics and write all UT's there. You don't even have to 
create a file there. What do you say @steveloughran?

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