Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions clients/src/test/java/org/apache/kafka/test/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.kafka.common.requests.ByteBufferChannel;
import org.apache.kafka.common.requests.RequestHeader;
import org.apache.kafka.common.utils.Exit;
import org.apache.kafka.common.utils.KafkaThread;
import org.apache.kafka.common.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -150,17 +149,6 @@ public static String randomString(final int len) {
public static File tempFile(final String prefix, final String suffix) throws IOException {
final File file = Files.createTempFile(prefix, suffix).toFile();
file.deleteOnExit();

// Note that we don't use Exit.addShutdownHook here because it allows for the possibility of accidently
// overriding the behaviour of this hook leading to leaked files.
Runtime.getRuntime().addShutdownHook(KafkaThread.nonDaemon("delete-temp-file-shutdown-hook", () -> {
try {
Utils.delete(file);
} catch (IOException e) {
log.error("Error deleting {}", file.getAbsolutePath(), e);
}
}));
Comment on lines -154 to -162
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For temp files this extra thread does not seem necessary. file.deleteOnExit already registers a shutdown hook.


return file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DynamicNumNetworkThreadsTest extends BaseRequestTest {
properties.put(KafkaConfig.ListenersProp, s"$internal://localhost:0, $external://localhost:0")
properties.put(KafkaConfig.ListenerSecurityProtocolMapProp, s"$internal:PLAINTEXT, $external:PLAINTEXT")
properties.put(s"listener.name.${internal.toLowerCase}.${KafkaConfig.NumNetworkThreadsProp}", "2")
properties.put(KafkaConfig.NumNetworkThreadsProp, Defaults.NumNetworkThreads.toString)
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@ class SocketServerTest {
val sslProps = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, interBrokerSecurityProtocol = Some(SecurityProtocol.SSL),
trustStoreFile = Some(trustStoreFile))
sslProps.put(KafkaConfig.ListenersProp, "SSL://localhost:0")
sslProps.put(KafkaConfig.NumNetworkThreadsProp, "1")
sslProps
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,9 @@ class DynamicBrokerConfigTest {
val zkClient: KafkaZkClient = mock(classOf[KafkaZkClient])
when(zkClient.getEntityConfigs(anyString(), anyString())).thenReturn(new java.util.Properties())

val oldConfig = KafkaConfig.fromProps(TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 9092))
val initialProps = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 9092)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TestDynamicThreadPool mock class expects the various thread count props to be initialized to the defaults. So I am removing the static overrides.

initialProps.remove(KafkaConfig.BackgroundThreadsProp)
val oldConfig = KafkaConfig.fromProps(initialProps)
val dynamicBrokerConfig = new DynamicBrokerConfig(oldConfig)
dynamicBrokerConfig.initialize(Some(zkClient))
dynamicBrokerConfig.addBrokerReconfigurable(new TestDynamicThreadPool)
Expand Down
3 changes: 3 additions & 0 deletions core/src/test/scala/unit/kafka/utils/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ object TestUtils extends Logging {
if (!props.containsKey(KafkaConfig.GroupInitialRebalanceDelayMsProp))
props.put(KafkaConfig.GroupInitialRebalanceDelayMsProp, "0")
rack.foreach(props.put(KafkaConfig.RackProp, _))
// Reduce number of threads per broker
props.put(KafkaConfig.NumNetworkThreadsProp, "2")
props.put(KafkaConfig.BackgroundThreadsProp, "2")

if (protocolAndPorts.exists { case (protocol, _) => usesSslTransportLayer(protocol) })
props ++= sslConfigs(Mode.SERVER, false, trustStoreFile, s"server$nodeId")
Expand Down