Fix tests for executorService.shutdown()
Even if `Executors.newSingleThreadExecutor()` returns a `FinalizableDelegatedExecutorService`,
an instance is kept in the memory until JVM exists.
That may lead to memory leak since we have a lot of threads in memory.
(cherry picked from commit fdac8f1634)
This commit is contained in:
committed by
Spring Builds
parent
6a7581e6cc
commit
ec2cfeb9b8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
* Copyright 2013-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.kafka.config.xml;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@@ -125,8 +126,8 @@ class KafkaOutboundAdapterParserTests {
|
||||
handler.setTimeoutBuffer(200);
|
||||
handler.setTopicExpression(new LiteralExpression("foo"));
|
||||
|
||||
Executors.newSingleThreadExecutor()
|
||||
.submit(() -> {
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
executorService.submit(() -> {
|
||||
RuntimeException exception = new RuntimeException("Async Producer Mock exception");
|
||||
while (!mockProducer.errorNext(exception)) {
|
||||
Thread.sleep(100);
|
||||
@@ -146,6 +147,8 @@ class KafkaOutboundAdapterParserTests {
|
||||
.isThrownBy(() -> handler.handleMessage(new GenericMessage<>("foo")))
|
||||
.withCauseInstanceOf(TimeoutException.class)
|
||||
.withStackTraceContaining("Timeout waiting for response from KafkaProducer");
|
||||
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user