Skip to content

Commit ddb87cc

Browse files
new test addition
1 parent 54c6d96 commit ddb87cc

File tree

3 files changed

+126
-31
lines changed

3 files changed

+126
-31
lines changed

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
import java.io.IOException;
2222
import java.net.URI;
2323
import java.util.Hashtable;
24+
import java.util.List;
2425
import java.util.Map;
2526
import java.util.UUID;
2627
import java.util.concurrent.Callable;
28+
import java.util.concurrent.ExecutionException;
29+
import java.util.concurrent.Future;
2730

2831
import org.assertj.core.api.Assertions;
2932
import org.junit.After;
@@ -700,4 +703,34 @@ protected void assertPathDns(Path path) {
700703
.describedAs("Path does not contain expected DNS")
701704
.contains(expectedDns);
702705
}
706+
707+
/**
708+
* Checks a list of futures for exceptions.
709+
*
710+
* This method iterates over a list of futures, waits for each task to complete,
711+
* and handles any exceptions thrown by the lambda expressions. If a
712+
* RuntimeException is caught, it increments the exceptionCaught counter.
713+
* If an unexpected exception is caught, it prints the exception to the standard error.
714+
* Finally, it asserts that no RuntimeExceptions were caught.
715+
*
716+
* @param futures The list of futures to check for exceptions.
717+
*/
718+
public void checkFuturesForExceptions(List<Future<?>> futures, int exceptionVal) {
719+
int exceptionCaught = 0;
720+
for (Future<?> future : futures) {
721+
try {
722+
future.get(); // wait for the task to complete and handle any exceptions thrown by the lambda expression
723+
} catch (ExecutionException e) {
724+
Throwable cause = e.getCause();
725+
if (cause instanceof RuntimeException) {
726+
exceptionCaught++;
727+
} else {
728+
System.err.println("Unexpected exception caught: " + cause);
729+
}
730+
} catch (InterruptedException e) {
731+
// handle interruption
732+
}
733+
}
734+
assertEquals(exceptionCaught, exceptionVal);
735+
}
703736
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemAppend.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.List;
3030
import java.util.Random;
3131
import java.util.Set;
32-
import java.util.concurrent.ExecutionException;
3332
import java.util.concurrent.ExecutorService;
3433
import java.util.concurrent.Executors;
3534
import java.util.concurrent.Future;
@@ -510,36 +509,6 @@ public void testRecreateDirectoryAppendAndFlush() throws IOException {
510509
}
511510
}
512511

513-
/**
514-
* Checks a list of futures for exceptions.
515-
*
516-
* This method iterates over a list of futures, waits for each task to complete,
517-
* and handles any exceptions thrown by the lambda expressions. If a
518-
* RuntimeException is caught, it increments the exceptionCaught counter.
519-
* If an unexpected exception is caught, it prints the exception to the standard error.
520-
* Finally, it asserts that no RuntimeExceptions were caught.
521-
*
522-
* @param futures The list of futures to check for exceptions.
523-
*/
524-
private void checkFuturesForExceptions(List<Future<?>> futures, int exceptionVal) {
525-
int exceptionCaught = 0;
526-
for (Future<?> future : futures) {
527-
try {
528-
future.get(); // wait for the task to complete and handle any exceptions thrown by the lambda expression
529-
} catch (ExecutionException e) {
530-
Throwable cause = e.getCause();
531-
if (cause instanceof RuntimeException) {
532-
exceptionCaught++;
533-
} else {
534-
System.err.println("Unexpected exception caught: " + cause);
535-
}
536-
} catch (InterruptedException e) {
537-
// handle interruption
538-
}
539-
}
540-
assertEquals(exceptionCaught, exceptionVal);
541-
}
542-
543512
/**
544513
* Verify that parallel write with same offset from different output streams will not throw exception.
545514
**/

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
import java.util.ArrayList;
2626
import java.util.EnumSet;
2727
import java.util.List;
28+
import java.util.Random;
2829
import java.util.UUID;
2930
import java.util.concurrent.CompletableFuture;
3031
import java.util.concurrent.CompletionException;
3132
import java.util.concurrent.ExecutorService;
3233
import java.util.concurrent.Executors;
34+
import java.util.concurrent.Future;
3335

3436
import org.assertj.core.api.Assertions;
3537
import org.junit.Assume;
@@ -72,6 +74,7 @@
7274
import static java.net.HttpURLConnection.HTTP_PRECON_FAILED;
7375
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.CONNECTIONS_MADE;
7476
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.ROOT_PATH;
77+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ENABLE_CONDITIONAL_CREATE_OVERWRITE;
7578
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ENABLE_MKDIR_OVERWRITE;
7679
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ONE_MB;
7780
import static org.apache.hadoop.fs.azurebfs.services.RenameAtomicity.SUFFIX;
@@ -925,6 +928,96 @@ public void testCreateSubPath() throws Exception {
925928
intercept(IOException.class, () -> fs.create(new Path("a/b")));
926929
}
927930

931+
/**
932+
* Test create path in parallel with overwrite false.
933+
**/
934+
@Test
935+
public void testParallelCreateOverwriteFalse()
936+
throws Exception {
937+
Configuration configuration = getRawConfiguration();
938+
configuration.set(FS_AZURE_ENABLE_CONDITIONAL_CREATE_OVERWRITE, "false");
939+
try (AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(
940+
configuration)) {
941+
ExecutorService executorService = Executors.newFixedThreadPool(5);
942+
List<Future<?>> futures = new ArrayList<>();
943+
944+
final byte[] b = new byte[8 * ONE_MB];
945+
new Random().nextBytes(b);
946+
final Path filePath = path("/testPath");
947+
948+
futures.add(executorService.submit(() -> {
949+
try {
950+
fs.create(filePath, false);
951+
} catch (IOException e) {
952+
throw new RuntimeException(e);
953+
}
954+
}));
955+
956+
futures.add(executorService.submit(() -> {
957+
try {
958+
fs.create(filePath, false);
959+
} catch (IOException e) {
960+
throw new RuntimeException(e);
961+
}
962+
}));
963+
964+
futures.add(executorService.submit(() -> {
965+
try {
966+
fs.create(filePath, false);
967+
} catch (IOException e) {
968+
throw new RuntimeException(e);
969+
}
970+
}));
971+
972+
checkFuturesForExceptions(futures, 2);
973+
}
974+
}
975+
976+
/**
977+
* Test create path in parallel with overwrite true.
978+
**/
979+
@Test
980+
public void testParallelCreateOverwriteTrue()
981+
throws Exception {
982+
Configuration configuration = getRawConfiguration();
983+
configuration.set(FS_AZURE_ENABLE_CONDITIONAL_CREATE_OVERWRITE, "false");
984+
try (AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(
985+
configuration)) {
986+
ExecutorService executorService = Executors.newFixedThreadPool(5);
987+
List<Future<?>> futures = new ArrayList<>();
988+
989+
final byte[] b = new byte[8 * ONE_MB];
990+
new Random().nextBytes(b);
991+
final Path filePath = path("/testPath");
992+
993+
futures.add(executorService.submit(() -> {
994+
try {
995+
fs.create(filePath);
996+
} catch (IOException e) {
997+
throw new RuntimeException(e);
998+
}
999+
}));
1000+
1001+
futures.add(executorService.submit(() -> {
1002+
try {
1003+
fs.create(filePath);
1004+
} catch (IOException e) {
1005+
throw new RuntimeException(e);
1006+
}
1007+
}));
1008+
1009+
futures.add(executorService.submit(() -> {
1010+
try {
1011+
fs.create(filePath);
1012+
} catch (IOException e) {
1013+
throw new RuntimeException(e);
1014+
}
1015+
}));
1016+
1017+
checkFuturesForExceptions(futures, 0);
1018+
}
1019+
}
1020+
9281021
/**
9291022
* Creating path with parent explicit.
9301023
*/

0 commit comments

Comments
 (0)