From 9935f35f52de82277c7287c3990d295d431491cd Mon Sep 17 00:00:00 2001 From: Lari Hotari Date: Thu, 12 Jan 2023 21:39:15 +0200 Subject: [PATCH] [fix][ci] Fix resource leak in PulsarFunctionLocalRunTest --- .../worker/PulsarFunctionLocalRunTest.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionLocalRunTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionLocalRunTest.java index a8a1c8384dd11..6555cc841e945 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionLocalRunTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/PulsarFunctionLocalRunTest.java @@ -272,7 +272,7 @@ void setup(Method method) throws Exception { primaryHost = pulsar.getWebServiceAddress(); // create cluster metadata - ClusterData clusterData = ClusterData.builder().serviceUrl(urlTls.toString()).build(); + ClusterData clusterData = ClusterData.builder().serviceUrlTls(urlTls.toString()).build(); admin.clusters().createCluster(config.getClusterName(), clusterData); ClientBuilder clientBuilder = PulsarClient.builder() @@ -308,14 +308,30 @@ && isNotBlank(workerConfig.getBrokerClientAuthenticationParameters())) { void shutdown() throws Exception { try { log.info("--- Shutting down ---"); - fileServer.stop(); - pulsarClient.close(); - admin.close(); - pulsar.close(); - bkEnsemble.stop(); + if (fileServer != null) { + fileServer.stop(); + fileServer = null; + } + if (pulsarClient != null) { + pulsarClient.close(); + pulsarClient = null; + } + if (admin != null) { + admin.close(); + admin = null; + } + if (pulsar != null) { + pulsar.close(); + pulsar = null; + } + if (bkEnsemble != null) { + bkEnsemble.stop(); + bkEnsemble = null; + } } finally { if (tempDirectory != null) { tempDirectory.delete(); + tempDirectory = null; } } } @@ -1099,7 +1115,7 @@ public void testPulsarSinkStatsByteBufferType() throws Throwable { public void testPulsarSinkWithFunction() throws Throwable { testPulsarSinkLocalRun(null, 1, StatsNullSink.class.getName(), "builtin://exclamation", "org.apache.pulsar.functions.api.examples.RecordFunction"); } - + public static class TestErrorSink implements Sink { private Map config; @Override