From f4b7335eb502c22fb76cb4f703bbdad3c131b03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Fern=C3=A1ndez=20Casta=C3=B1o?= Date: Thu, 2 Feb 2023 13:52:30 +0100 Subject: [PATCH] Remove extra logging from PrioritizedThrottledTaskRunnerTests (#93456) --- .../PrioritizedThrottledTaskRunnerTests.java | 47 +++++++------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/common/util/concurrent/PrioritizedThrottledTaskRunnerTests.java b/server/src/test/java/org/elasticsearch/common/util/concurrent/PrioritizedThrottledTaskRunnerTests.java index 01ecce705856f..05d650f2fe804 100644 --- a/server/src/test/java/org/elasticsearch/common/util/concurrent/PrioritizedThrottledTaskRunnerTests.java +++ b/server/src/test/java/org/elasticsearch/common/util/concurrent/PrioritizedThrottledTaskRunnerTests.java @@ -9,8 +9,6 @@ package org.elasticsearch.common.util.concurrent; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.logging.LogManager; -import org.elasticsearch.logging.Logger; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; @@ -49,16 +47,12 @@ public void tearDown() throws Exception { } static class TestTask extends AbstractRunnable implements Comparable { - private final Logger logger = LogManager.getLogger(TestTask.class); - private final Runnable runnable; private final int priority; - private final String taskDescription; - TestTask(Runnable runnable, int priority, String taskDescription) { + TestTask(Runnable runnable, int priority) { this.runnable = runnable; this.priority = priority; - this.taskDescription = taskDescription; } @Override @@ -68,9 +62,7 @@ public int compareTo(TestTask o) { @Override public void doRun() { - logger.info("--> starting to execute task [{}]", taskDescription); runnable.run(); - logger.info("--> finished task [{}]", taskDescription); } @Override @@ -96,7 +88,7 @@ public void testMultiThreadedEnqueue() throws Exception { throw new AssertionError(e); } executedCountDown.countDown(); - }, getRandomPriority(), "testMultiThreadedEnqueue-" + taskId)); + }, getRandomPriority())); assertThat(taskRunner.runningTasks(), lessThanOrEqualTo(maxTasks)); }).start(); } @@ -117,7 +109,7 @@ public void testTasksRunInOrder() throws Exception { taskRunner.enqueueTask(new TestTask(() -> { awaitBarrier(blockBarrier); // notify main thread that the runner is blocked awaitBarrier(blockBarrier); // wait for main thread to finish enqueuing tasks - }, getRandomPriority(), "blocking task")); + }, getRandomPriority())); blockBarrier.await(10, TimeUnit.SECONDS); // wait for blocking task to start executing @@ -135,7 +127,7 @@ public void testTasksRunInOrder() throws Exception { taskRunner.enqueueTask(new TestTask(() -> { executedPriorities.add(priority); executedCountDown.countDown(); - }, priority, "concurrent enqueued tasks - " + taskId)); + }, priority)); awaitBarrier(enqueuedBarrier); // notify main thread that the task is enqueued }).start(); } @@ -171,7 +163,7 @@ public void testEnqueueSpawnsNewTasksUpToMax() throws Exception { throw new RuntimeException(e); } executedCountDown.countDown(); - }, getRandomPriority(), "testEnqueueSpawnsNewTasksUpToMax-" + taskId)); + }, getRandomPriority())); assertThat(taskRunner.runningTasks(), equalTo(i + 1)); } // Enqueueing one or more new tasks would create only one new running task @@ -184,7 +176,7 @@ public void testEnqueueSpawnsNewTasksUpToMax() throws Exception { throw new RuntimeException(e); } executedCountDown.countDown(); - }, getRandomPriority(), "testEnqueueSpawnsNewTasksUpToMax-" + taskId)); + }, getRandomPriority())); assertThat(taskRunner.runningTasks(), equalTo(maxTasks)); } assertThat(taskRunner.queueSize(), equalTo(newTasks - 1)); @@ -209,19 +201,17 @@ public void testFailsTasksOnRejectionOrShutdown() throws Exception { try { while (true) { assertTrue(permits.tryAcquire(10, TimeUnit.SECONDS)); - taskRunner.enqueueTask( - new TestTask(taskCompleted::countDown, getRandomPriority(), "testFailsTasksOnRejectionOrShutdown") { - @Override - public void onRejection(Exception e) { - rejectionCountDown.countDown(); - } + taskRunner.enqueueTask(new TestTask(taskCompleted::countDown, getRandomPriority()) { + @Override + public void onRejection(Exception e) { + rejectionCountDown.countDown(); + } - @Override - public void onAfter() { - permits.release(); - } + @Override + public void onAfter() { + permits.release(); } - ); + }); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -244,14 +234,9 @@ private int getRandomPriority() { } private void assertNoRunningTasks(PrioritizedThrottledTaskRunner taskRunner) { - logger.info("--> ensure that there are no running tasks in the executor. Max number of threads [{}]", maxThreads); final var barrier = new CyclicBarrier(maxThreads + 1); for (int i = 0; i < maxThreads; i++) { - executor.execute(() -> { - logger.info("--> await until barrier is released"); - awaitBarrier(barrier); - logger.info("--> the barrier is released"); - }); + executor.execute(() -> { awaitBarrier(barrier); }); } awaitBarrier(barrier); assertThat(taskRunner.runningTasks(), equalTo(0));