sumangala-patki commented on a change in pull request #2549:
URL: https://github.com/apache/hadoop/pull/2549#discussion_r555528200



##########
File path: 
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestGetContentSummary.java
##########
@@ -0,0 +1,204 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.services;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import org.apache.hadoop.fs.ContentSummary;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.azurebfs.AbstractAbfsIntegrationTest;
+import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystem;
+
+import static 
org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.DEFAULT_AZURE_LIST_MAX_RESULTS;
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
+
+public class TestGetContentSummary extends AbstractAbfsIntegrationTest {
+
+  private final String[] directories = {"/testFolder",
+      "/testFolder/testFolder1",
+      "/testFolder/testFolder2", "/testFolder/testFolder3", "/testFolderII",
+      "/testFolder/testFolder2/testFolder4",
+      "/testFolder/testFolder2/testFolder5",
+      "/testFolder/testFolder3/testFolder6",
+      "/testFolder/testFolder3/testFolder7",
+      "/testFolder/testFolder3/testFolder6/leafDir",
+      "/testFolderII/listMaxDir",
+      "/testFolderII/listMaxDir/" + DEFAULT_AZURE_LIST_MAX_RESULTS/2 + 
"_mid_folder"};
+
+  private final Path pathToFile = new Path("/testFolder/test1");
+  private final Path pathToListMaxDir = new Path("/testFolderII/listMaxDir");
+  private final Path pathToLeafDir =
+      new Path("/testFolder/testFolder3/testFolder6/leafDir");
+  private final Path pathToIntermediateDirWithFilesOnly = new Path(
+        "/testFolder/testFolder2/testFolder5");
+  private final Path pathToIntermediateDirWithFilesAndSubdirs = new Path(
+        "/testFolder/testFolder3");
+  private final String[] dirsWithNonEmptyFiles = {"/testFolder", 
"/testFolder/testFolder1",
+      "/testFolder/testFolder2/testFolder5", "/testFolder/testFolder3"};
+
+  private final AzureBlobFileSystem fs = createFileSystem();
+  private final int testBufferSize = 20;
+  private final int filesPerDirectory = 2;
+  private final int numFilesForListMaxTest = DEFAULT_AZURE_LIST_MAX_RESULTS + 
10;
+  private final byte[] b = new byte[testBufferSize];
+  private final int maxThreads = 16;
+
+  public TestGetContentSummary() throws Exception {
+    createDirectoryStructure();
+    new Random().nextBytes(b);
+  }
+
+  @Test
+  public void testFilesystemRoot()
+      throws IOException {
+    int fileCount =
+        (directories.length - 2) * filesPerDirectory + numFilesForListMaxTest;
+    ContentSummary contentSummary = fs.getContentSummary(new Path("/"));
+    checkContentSummary(contentSummary, directories.length, fileCount,
+        dirsWithNonEmptyFiles.length * filesPerDirectory * testBufferSize);
+  }
+
+  @Test
+  public void testFileContentSummary() throws IOException {
+    ContentSummary contentSummary = fs.getContentSummary(pathToFile);
+    checkContentSummary(contentSummary, 0, 1, testBufferSize);
+  }
+
+  @Test
+  public void testLeafDir() throws IOException {
+    ContentSummary contentSummary = fs.getContentSummary(pathToLeafDir);
+    checkContentSummary(contentSummary, 0, 0, 0);
+  }
+
+  @Test
+  public void testIntermediateDirWithFilesOnly() throws IOException {
+    ContentSummary contentSummary =
+        fs.getContentSummary(pathToIntermediateDirWithFilesOnly);
+    checkContentSummary(contentSummary, 0, filesPerDirectory,
+        testBufferSize * filesPerDirectory);
+  }
+
+  @Test
+  public void testIntermediateDirWithFilesAndSubdirs() throws IOException {
+    ContentSummary contentSummary =
+        fs.getContentSummary(pathToIntermediateDirWithFilesAndSubdirs);
+    checkContentSummary(contentSummary, 3, 3 * filesPerDirectory,
+        testBufferSize * filesPerDirectory);
+  }
+
+  @Test
+  public void testDirOverListMaxResultsItems()
+      throws IOException {
+    checkContentSummary(
+        fs.getContentSummary(pathToListMaxDir), 1,
+        numFilesForListMaxTest + filesPerDirectory, 0);
+  }
+
+  @Test
+  public void testInvalidPath() throws Exception {
+    intercept(IOException.class, () -> fs.getContentSummary(new Path(
+        "/nonExistentPath")));
+  }
+
+  @Test
+  public void testConcurrentGetContentSummaryCalls()
+          throws InterruptedException, ExecutionException {
+    ExecutorService executorService = new ThreadPoolExecutor(1,
+            maxThreads, 5, TimeUnit.SECONDS, new SynchronousQueue<>());
+    ArrayList<Future<ContentSummary>> futures = new ArrayList<>();
+    for (String directory : directories) {
+      Future<ContentSummary> future = executorService.submit(
+              () -> fs.getContentSummary(new Path(directory)));
+      futures.add(future);
+    }
+    int[][] dirCS = {{8, 8 * filesPerDirectory, 8 * testBufferSize}, {0, 
filesPerDirectory, 2 * testBufferSize},
+            {2, 3 * filesPerDirectory, 2 * testBufferSize}, {3, 3 * 
filesPerDirectory, 2 * testBufferSize},
+            {2, numFilesForListMaxTest + 2 * filesPerDirectory, 0}, {0, 
filesPerDirectory, 0},
+            {0, filesPerDirectory, filesPerDirectory * testBufferSize}, {1, 
filesPerDirectory, 0},
+            {0, filesPerDirectory, 0}, {0, 0, 0}, {1, numFilesForListMaxTest + 
2, 0}, {0, filesPerDirectory, 0}};
+    executorService.shutdown();
+    for (int i=0; i<directories.length; i++) {
+      ContentSummary contentSummary = futures.get(i).get();
+      checkContentSummary(contentSummary, dirCS[i][0], dirCS[i][1], 
dirCS[i][2]);
+    }
+  }
+
+  private void checkContentSummary(ContentSummary contentSummary,

Review comment:
       done




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



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

Reply via email to