steveloughran commented on a change in pull request #2548: URL: https://github.com/apache/hadoop/pull/2548#discussion_r556477782
########## File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ListStatusRemoteIterator.java ########## @@ -0,0 +1,149 @@ +/** + * 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.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.CompletableFuture; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore; + +public class ListStatusRemoteIterator implements RemoteIterator<FileStatus> { + + private static final Logger LOG = LoggerFactory + .getLogger(ListStatusRemoteIterator.class); + + private static final boolean FETCH_ALL_FALSE = false; + private static final int MAX_QUEUE_SIZE = 10; + + private final Path path; + private final AzureBlobFileSystemStore abfsStore; + private final ArrayBlockingQueue<Iterator<FileStatus>> iteratorsQueue; + private final Object asyncOpLock = new Object(); + + private boolean firstBatch = true; + private boolean isAsyncInProgress = false; + private String continuation; + private Iterator<FileStatus> currIterator; + private IOException ioException; + + public ListStatusRemoteIterator(final Path path, Review comment: use interface for operations, as with org.apache.hadoop.fs.s3a.impl.ListingOperationCallbacks ########## File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ListStatusRemoteIterator.java ########## @@ -0,0 +1,149 @@ +/** + * 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.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.CompletableFuture; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore; + +public class ListStatusRemoteIterator implements RemoteIterator<FileStatus> { + + private static final Logger LOG = LoggerFactory + .getLogger(ListStatusRemoteIterator.class); + + private static final boolean FETCH_ALL_FALSE = false; + private static final int MAX_QUEUE_SIZE = 10; + + private final Path path; + private final AzureBlobFileSystemStore abfsStore; + private final ArrayBlockingQueue<Iterator<FileStatus>> iteratorsQueue; + private final Object asyncOpLock = new Object(); + + private boolean firstBatch = true; + private boolean isAsyncInProgress = false; + private String continuation; + private Iterator<FileStatus> currIterator; + private IOException ioException; + + public ListStatusRemoteIterator(final Path path, + final AzureBlobFileSystemStore abfsStore) { + this.path = path; + this.abfsStore = abfsStore; + iteratorsQueue = new ArrayBlockingQueue<>(MAX_QUEUE_SIZE); + currIterator = Collections.emptyIterator(); + fetchBatchesAsync(); + } + + @Override + public boolean hasNext() throws IOException { + if (currIterator.hasNext()) { + return true; + } + updateCurrentIterator(); + return currIterator.hasNext(); + } + + @Override + public FileStatus next() throws IOException { + if (!this.hasNext()) { + throw new NoSuchElementException(); + } + return currIterator.next(); + } + + private void updateCurrentIterator() throws IOException { + fetchBatchesAsync(); + synchronized (this) { + if (iteratorsQueue.isEmpty()) { + if (ioException != null) { + throw ioException; + } + if (isListingComplete()) { + return; + } + } + } + try { + currIterator = iteratorsQueue.take(); + if (!currIterator.hasNext() && !isListingComplete()) { + updateCurrentIterator(); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LOG.error("Thread got interrupted: {}", e); + } + } + + private boolean isListingComplete() { + return !firstBatch && (continuation == null || continuation.isEmpty()); + } + + private void fetchBatchesAsync() { + CompletableFuture.runAsync(() -> asyncOp()); Review comment: should only be scheduled if there isn't one already in progress ########## File path: hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemListStatusIterator.java ########## @@ -0,0 +1,190 @@ +/** + * 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; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.mockito.Mockito; + +import org.apache.hadoop.fs.azurebfs.services.ListStatusRemoteIterator; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; + +/** + * Test listStatus operation. + */ +public class ITestAzureBlobFileSystemListStatusIterator + extends AbstractAbfsIntegrationTest { + + private static final int TEST_FILES_NUMBER = 1000; + + public ITestAzureBlobFileSystemListStatusIterator() throws Exception { + super(); + } + + @Test + public void testListPath() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPath = "testRoot1"; + final List<String> fileNames = createFiles(TEST_FILES_NUMBER, rootPath, + "testListPath"); + AzureBlobFileSystemStore abfsStore = getAbfsStore(fs); + abfsStore.getAbfsConfiguration().setListMaxResults(10); + RemoteIterator<FileStatus> fsIt = fs.listStatusIterator(new Path(rootPath)); + int itrCount = 0; + while (fsIt.hasNext()) { Review comment: also need to test a loop of it.next() until NoMoreElementsException is raised ########## File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java ########## @@ -37,6 +37,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; +import org.apache.hadoop.fs.RemoteIterator; Review comment: needs to go into the non-shaded bit of hadoop imports. ########## File path: hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemListStatusIterator.java ########## @@ -0,0 +1,190 @@ +/** + * 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; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.mockito.Mockito; + +import org.apache.hadoop.fs.azurebfs.services.ListStatusRemoteIterator; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; + +/** + * Test listStatus operation. + */ +public class ITestAzureBlobFileSystemListStatusIterator + extends AbstractAbfsIntegrationTest { + + private static final int TEST_FILES_NUMBER = 1000; + + public ITestAzureBlobFileSystemListStatusIterator() throws Exception { + super(); + } + + @Test + public void testListPath() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPath = "testRoot1"; + final List<String> fileNames = createFiles(TEST_FILES_NUMBER, rootPath, + "testListPath"); + AzureBlobFileSystemStore abfsStore = getAbfsStore(fs); + abfsStore.getAbfsConfiguration().setListMaxResults(10); + RemoteIterator<FileStatus> fsIt = fs.listStatusIterator(new Path(rootPath)); + int itrCount = 0; + while (fsIt.hasNext()) { + FileStatus fileStatus = fsIt.next(); + String pathStr = fileStatus.getPath().toString(); + fileNames.remove(pathStr); + itrCount++; + } + assertEquals(TEST_FILES_NUMBER, itrCount); + assertEquals(0, fileNames.size()); + } + + @Test + public void testNextWhenNoMoreElementsPresent() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot2"; + Path rootPath = new Path(rootPathStr); + getFileSystem().mkdirs(rootPath); + RemoteIterator<FileStatus> fsItr = fs.listStatusIterator(rootPath); + fsItr = Mockito.spy(fsItr); + Mockito.doReturn(false).when(fsItr).hasNext(); + + RemoteIterator<FileStatus> finalFsItr = fsItr; + Assertions.assertThatThrownBy(() -> finalFsItr.next()).describedAs( + "next() should throw NoSuchElementException if hasNext() return " + + "false").isInstanceOf(NoSuchElementException.class); + } + + @Test + public void testHasNextForEmptyDir() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot3"; + Path rootPath = new Path(rootPathStr); + getFileSystem().mkdirs(rootPath); + RemoteIterator<FileStatus> fsItr = fs.listStatusIterator(rootPath); + Assertions.assertThat(fsItr.hasNext()) + .describedAs("hasNext returns false for empty directory").isFalse(); + } + + @Test + public void testHasNextForFile() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot4"; + Path rootPath = new Path(rootPathStr); + getFileSystem().create(rootPath); + RemoteIterator<FileStatus> fsItr = fs.listStatusIterator(rootPath); + Assertions.assertThat(fsItr.hasNext()) + .describedAs("hasNext returns true for file").isTrue(); + } + + @Test + public void testHasNextForIOException() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot5"; + Path rootPath = new Path(rootPathStr); + getFileSystem().mkdirs(rootPath); + ListStatusRemoteIterator fsItr = (ListStatusRemoteIterator) fs + .listStatusIterator(rootPath); + Thread.sleep(1000); + + String exceptionMessage = "test exception"; + setPrivateField(fsItr, ListStatusRemoteIterator.class, "ioException", Review comment: this is an abuse of internals. If you use a callback for the listing operations, you can explicitly raise the IOE instead. ########## File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ListStatusRemoteIterator.java ########## @@ -0,0 +1,149 @@ +/** + * 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.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.CompletableFuture; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore; + +public class ListStatusRemoteIterator implements RemoteIterator<FileStatus> { + + private static final Logger LOG = LoggerFactory + .getLogger(ListStatusRemoteIterator.class); + + private static final boolean FETCH_ALL_FALSE = false; + private static final int MAX_QUEUE_SIZE = 10; + + private final Path path; + private final AzureBlobFileSystemStore abfsStore; + private final ArrayBlockingQueue<Iterator<FileStatus>> iteratorsQueue; + private final Object asyncOpLock = new Object(); + + private boolean firstBatch = true; + private boolean isAsyncInProgress = false; + private String continuation; + private Iterator<FileStatus> currIterator; + private IOException ioException; + + public ListStatusRemoteIterator(final Path path, + final AzureBlobFileSystemStore abfsStore) { + this.path = path; + this.abfsStore = abfsStore; + iteratorsQueue = new ArrayBlockingQueue<>(MAX_QUEUE_SIZE); + currIterator = Collections.emptyIterator(); + fetchBatchesAsync(); + } + + @Override + public boolean hasNext() throws IOException { + if (currIterator.hasNext()) { + return true; + } + updateCurrentIterator(); Review comment: if, at the end of the loop I keep call hasNext() repeatedly, what happens? ########## File path: hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ListStatusRemoteIterator.java ########## @@ -0,0 +1,149 @@ +/** + * 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.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.CompletableFuture; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.fs.azurebfs.AzureBlobFileSystemStore; + +public class ListStatusRemoteIterator implements RemoteIterator<FileStatus> { + + private static final Logger LOG = LoggerFactory + .getLogger(ListStatusRemoteIterator.class); + + private static final boolean FETCH_ALL_FALSE = false; + private static final int MAX_QUEUE_SIZE = 10; + + private final Path path; + private final AzureBlobFileSystemStore abfsStore; + private final ArrayBlockingQueue<Iterator<FileStatus>> iteratorsQueue; + private final Object asyncOpLock = new Object(); + + private boolean firstBatch = true; + private boolean isAsyncInProgress = false; Review comment: these are going to have to be Atomic, aren't they? ########## File path: hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemListStatusIterator.java ########## @@ -0,0 +1,190 @@ +/** + * 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; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.mockito.Mockito; + +import org.apache.hadoop.fs.azurebfs.services.ListStatusRemoteIterator; +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; + +/** + * Test listStatus operation. + */ +public class ITestAzureBlobFileSystemListStatusIterator + extends AbstractAbfsIntegrationTest { + + private static final int TEST_FILES_NUMBER = 1000; + + public ITestAzureBlobFileSystemListStatusIterator() throws Exception { + super(); + } + + @Test + public void testListPath() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPath = "testRoot1"; + final List<String> fileNames = createFiles(TEST_FILES_NUMBER, rootPath, + "testListPath"); + AzureBlobFileSystemStore abfsStore = getAbfsStore(fs); + abfsStore.getAbfsConfiguration().setListMaxResults(10); + RemoteIterator<FileStatus> fsIt = fs.listStatusIterator(new Path(rootPath)); + int itrCount = 0; + while (fsIt.hasNext()) { + FileStatus fileStatus = fsIt.next(); + String pathStr = fileStatus.getPath().toString(); + fileNames.remove(pathStr); + itrCount++; + } + assertEquals(TEST_FILES_NUMBER, itrCount); + assertEquals(0, fileNames.size()); + } + + @Test + public void testNextWhenNoMoreElementsPresent() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot2"; + Path rootPath = new Path(rootPathStr); + getFileSystem().mkdirs(rootPath); + RemoteIterator<FileStatus> fsItr = fs.listStatusIterator(rootPath); + fsItr = Mockito.spy(fsItr); + Mockito.doReturn(false).when(fsItr).hasNext(); + + RemoteIterator<FileStatus> finalFsItr = fsItr; + Assertions.assertThatThrownBy(() -> finalFsItr.next()).describedAs( + "next() should throw NoSuchElementException if hasNext() return " + + "false").isInstanceOf(NoSuchElementException.class); + } + + @Test + public void testHasNextForEmptyDir() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot3"; + Path rootPath = new Path(rootPathStr); + getFileSystem().mkdirs(rootPath); + RemoteIterator<FileStatus> fsItr = fs.listStatusIterator(rootPath); + Assertions.assertThat(fsItr.hasNext()) + .describedAs("hasNext returns false for empty directory").isFalse(); + } + + @Test + public void testHasNextForFile() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot4"; + Path rootPath = new Path(rootPathStr); + getFileSystem().create(rootPath); + RemoteIterator<FileStatus> fsItr = fs.listStatusIterator(rootPath); + Assertions.assertThat(fsItr.hasNext()) + .describedAs("hasNext returns true for file").isTrue(); + } + + @Test + public void testHasNextForIOException() throws Exception { + final AzureBlobFileSystem fs = getFileSystem(); + String rootPathStr = "testRoot5"; + Path rootPath = new Path(rootPathStr); + getFileSystem().mkdirs(rootPath); + ListStatusRemoteIterator fsItr = (ListStatusRemoteIterator) fs + .listStatusIterator(rootPath); + Thread.sleep(1000); + + String exceptionMessage = "test exception"; + setPrivateField(fsItr, ListStatusRemoteIterator.class, "ioException", + new IOException(exceptionMessage)); + setPrivateFinalField(fsItr, ListStatusRemoteIterator.class, + "iteratorsQueue", new ArrayBlockingQueue<Iterator>(1)); + + Assertions.assertThatThrownBy(() -> fsItr.hasNext()).describedAs( + "When ioException is not null and queue is empty exception should be " + + "thrown").isInstanceOf(IOException.class) + .hasMessage(exceptionMessage); + } + + private void setPrivateField(Object obj, Class classObj, String fieldName, + Object value) throws NoSuchFieldException, IllegalAccessException { + Field field = classObj.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(obj, value); + } + + private void setPrivateFinalField(Object obj, Class classObj, + String fieldName, Object value) + throws NoSuchFieldException, IllegalAccessException { + Field field = classObj.getDeclaredField(fieldName); + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(obj, value); + } + + private List<String> createFiles(int numFiles, String rootPathStr, + String filenamePrefix) + throws ExecutionException, InterruptedException, IOException { + final List<Future<Void>> tasks = new ArrayList<>(); + final List<String> fileNames = new ArrayList<>(); + ExecutorService es = Executors.newFixedThreadPool(10); + final Path rootPath = new Path(rootPathStr); + for (int i = 0; i < numFiles; i++) { + final Path filePath = new Path(rootPath, filenamePrefix + i); + Callable<Void> callable = new Callable<Void>() { + @Override + public Void call() throws Exception { + getFileSystem().create(filePath); + fileNames.add(makeQualified(filePath).toString()); + return null; + } + }; + tasks.add(es.submit(callable)); + } + for (Future<Void> task : tasks) { + task.get(); + } + es.shutdownNow(); + return fileNames; + } + + private AzureBlobFileSystemStore getAbfsStore(FileSystem fs) Review comment: this is why you need a list callback. This is low-level field abuse. Better to have a {{getAbfsStoreForTesting()}} call, at the very least ---------------------------------------------------------------- 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]
