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_r404604989
########## 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; Review comment: Use LARGE_OPERATIONS directly. Why to create a new variable. ---------------------------------------------------------------- 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]
