ashishkumar50 commented on code in PR #10125:
URL: https://github.com/apache/ozone/pull/10125#discussion_r3158584474
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingService.java:
##########
@@ -240,6 +246,56 @@ public void testMultithreadedDirectoryDeletion() throws
Exception {
}
}
+ @Test
+ @DisplayName("DirectoryDeletingService uses configured number of worker
threads")
+ public void testDirectoryDeletionWorkerPoolUsesConfiguredThreadCount()
throws Exception {
+ int threadCount = 10;
+ OzoneConfiguration conf = createConfAndInitValues(threadCount);
+ OmTestManagers omTestManagers = new OmTestManagers(conf);
+ OzoneManager ozoneManager = omTestManagers.getOzoneManager();
+ try {
+ DirectoryDeletingService service =
+ (DirectoryDeletingService)
ozoneManager.getKeyManager().getDirDeletingService();
+ ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor)
getPrivateField(service, "deletionThreadPool");
+
+ assertThat(threadPoolExecutor.getCorePoolSize()).as(
+ "core pool size should match configured directory deletion
threads").isEqualTo(threadCount);
+
+ CountDownLatch tasksStarted = new CountDownLatch(threadCount);
+ CountDownLatch releaseTasks = new CountDownLatch(1);
+ Set<String> workerThreads = Collections.synchronizedSet(new HashSet<>());
+ List<CompletableFuture<Void>> futures = new ArrayList<>();
+
+ for (int i = 0; i < threadCount; i++) {
+ futures.add(CompletableFuture.runAsync(() -> {
+ workerThreads.add(Thread.currentThread().getName());
+ tasksStarted.countDown();
+ try {
+ assertTrue(releaseTasks.await(10, TimeUnit.SECONDS));
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new AssertionError("Interrupted while waiting for release
latch", e);
+ }
+ }, threadPoolExecutor));
+ }
+
+ assertTrue(tasksStarted.await(10, TimeUnit.SECONDS), "Expected all
submitted tasks to start");
+ assertThat(workerThreads).as("Expected tasks to run in parallel using
configured workers").hasSize(threadCount);
+
+ releaseTasks.countDown();
+ CompletableFuture.allOf(futures.toArray(new
CompletableFuture[0])).get(10, TimeUnit.SECONDS);
+ } finally {
+ ozoneManager.stop();
+ }
+ }
+
+ private static Object getPrivateField(Object target, String fieldName)
Review Comment:
We should not use privatefield instead use `VisibleForTesting`.
Also there is a test `testMultithreadedDirectoryDeletion` which verifies
multithread for directorydeleting service. Please look why test is passing even
though only one thread is running? Please correct the same test instead of
writing new test.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]