You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/02/27 03:32:15 UTC
[james-project] 08/08: Suppress concurrent test runner logs in case
of huge number of operations
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit d209e7658f44e603d559c8f9cd98ff54b063d6d1
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue Feb 25 13:07:08 2020 +0700
Suppress concurrent test runner logs in case of huge number of operations
---
.../james/mailbox/events/RabbitMQEventBusTest.java | 2 ++
.../util/concurrency/ConcurrentTestRunner.java | 22 ++++++++++++++++++----
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
index 3656e35..bac1407 100644
--- a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
+++ b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
@@ -555,6 +555,7 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
.operation((threadNumber, step) -> eventBus.dispatch(EVENT, KEY_1).block())
.threadCount(THREAD_COUNT)
.operationCount(OPERATION_COUNT)
+ .noErrorLogs()
.run()) {
TimeUnit.SECONDS.sleep(2);
@@ -647,6 +648,7 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
.operation((threadNumber, step) -> eventBus.dispatch(EVENT, KEY_1).block())
.threadCount(THREAD_COUNT)
.operationCount(OPERATION_COUNT)
+ .noErrorLogs()
.run()) {
TimeUnit.SECONDS.sleep(2);
diff --git a/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java b/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
index 4ad57ab..dad6e84 100644
--- a/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
+++ b/server/container/util/src/main/java/org/apache/james/util/concurrency/ConcurrentTestRunner.java
@@ -90,6 +90,7 @@ public class ConcurrentTestRunner implements Closeable {
private final int threadCount;
private final ConcurrentOperation operation;
private Optional<Integer> operationCount;
+ private Optional<Boolean> noErrorLogs;
private Builder(int threadCount, ConcurrentOperation operation) {
Preconditions.checkArgument(threadCount > 0, "Thread count should be strictly positive");
@@ -98,6 +99,7 @@ public class ConcurrentTestRunner implements Closeable {
this.threadCount = threadCount;
this.operation = operation;
this.operationCount = Optional.empty();
+ this.noErrorLogs = Optional.empty();
}
public Builder operationCount(int operationCount) {
@@ -106,10 +108,16 @@ public class ConcurrentTestRunner implements Closeable {
return this;
}
+ public Builder noErrorLogs() {
+ this.noErrorLogs = Optional.of(true);
+ return this;
+ }
+
private ConcurrentTestRunner build() {
return new ConcurrentTestRunner(
threadCount,
operationCount.orElse(DEFAULT_OPERATION_COUNT),
+ noErrorLogs.orElse(false),
operation);
}
@@ -149,11 +157,13 @@ public class ConcurrentTestRunner implements Closeable {
private class ConcurrentRunnableTask implements Runnable {
private final int threadNumber;
private final ConcurrentOperation concurrentOperation;
+ private final boolean noErrorLogs;
private Exception exception;
- public ConcurrentRunnableTask(int threadNumber, ConcurrentOperation concurrentOperation) {
+ public ConcurrentRunnableTask(int threadNumber, ConcurrentOperation concurrentOperation, boolean noErrorLogs) {
this.threadNumber = threadNumber;
this.concurrentOperation = concurrentOperation;
+ this.noErrorLogs = noErrorLogs;
}
@Override
@@ -164,7 +174,9 @@ public class ConcurrentTestRunner implements Closeable {
try {
concurrentOperation.execute(threadNumber, i);
} catch (Exception e) {
- LOGGER.error("Error caught during concurrent testing (iteration {}, threadNumber {})", i, threadNumber, e);
+ if (!noErrorLogs) {
+ LOGGER.error("Error caught during concurrent testing (iteration {}, threadNumber {})", i, threadNumber, e);
+ }
exception = e;
}
}
@@ -186,15 +198,17 @@ public class ConcurrentTestRunner implements Closeable {
private final int threadCount;
private final int operationCount;
+ private final boolean suppressLogger;
private final CountDownLatch countDownLatch;
private final ConcurrentOperation biConsumer;
private final ExecutorService executorService;
private final List<Future<?>> futures;
- private ConcurrentTestRunner(int threadCount, int operationCount, ConcurrentOperation biConsumer) {
+ private ConcurrentTestRunner(int threadCount, int operationCount, boolean suppressLogger, ConcurrentOperation biConsumer) {
this.threadCount = threadCount;
this.operationCount = operationCount;
this.countDownLatch = new CountDownLatch(threadCount);
+ this.suppressLogger = suppressLogger;
this.biConsumer = biConsumer;
ThreadFactory threadFactory = NamedThreadFactory.withClassName(getClass());
this.executorService = Executors.newFixedThreadPool(threadCount, threadFactory);
@@ -203,7 +217,7 @@ public class ConcurrentTestRunner implements Closeable {
public ConcurrentTestRunner run() {
for (int i = 0; i < threadCount; i++) {
- futures.add(executorService.submit(new ConcurrentRunnableTask(i, biConsumer)));
+ futures.add(executorService.submit(new ConcurrentRunnableTask(i, biConsumer, suppressLogger)));
}
return this;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org