This is an automated email from the ASF dual-hosted git repository. lhotari pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push: new a3b31fff6e7 [fix][test] Fix resource leaks in ProxyTest and fix invalid tests (#24204) a3b31fff6e7 is described below commit a3b31fff6e7939bd0c745b07bcddf70b182625a9 Author: Lari Hotari <lhot...@users.noreply.github.com> AuthorDate: Thu Apr 24 08:58:26 2025 +0300 [fix][test] Fix resource leaks in ProxyTest and fix invalid tests (#24204) --- .../org/apache/pulsar/proxy/server/ProxyTest.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java index be67534e6c8..9d66692c3fa 100644 --- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java +++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyTest.java @@ -155,12 +155,11 @@ public class ProxyTest extends MockedPulsarServiceBaseTest { @Override @AfterClass(alwaysRun = true) protected void cleanup() throws Exception { - internalCleanup(); - proxyService.close(); if (proxyClientAuthentication != null) { proxyClientAuthentication.close(); } + internalCleanup(); } @Test @@ -246,6 +245,8 @@ public class ProxyTest extends MockedPulsarServiceBaseTest { **/ @Test public void testAutoCreateTopic() throws Exception{ + TopicType originalAllowAutoTopicCreationType = pulsar.getConfiguration().getAllowAutoTopicCreationType(); + int originalDefaultNumPartitions = pulsar.getConfiguration().getDefaultNumPartitions(); int defaultPartition = 2; int defaultNumPartitions = pulsar.getConfiguration().getDefaultNumPartitions(); pulsar.getConfiguration().setAllowAutoTopicCreationType(TopicType.PARTITIONED); @@ -257,10 +258,10 @@ public class ProxyTest extends MockedPulsarServiceBaseTest { String topic = "persistent://sample/test/local/partitioned-proxy-topic"; CompletableFuture<List<String>> partitionNamesFuture = client.getPartitionsForTopic(topic); List<String> partitionNames = partitionNamesFuture.get(30000, TimeUnit.MILLISECONDS); - Assert.assertEquals(partitionNames.size(), defaultPartition); + assertEquals(partitionNames.size(), defaultPartition); } finally { - pulsar.getConfiguration().setAllowAutoTopicCreationType(TopicType.NON_PARTITIONED); - pulsar.getConfiguration().setDefaultNumPartitions(defaultNumPartitions); + pulsar.getConfiguration().setAllowAutoTopicCreationType(originalAllowAutoTopicCreationType); + pulsar.getConfiguration().setDefaultNumPartitions(originalDefaultNumPartitions); } } @@ -319,8 +320,9 @@ public class ProxyTest extends MockedPulsarServiceBaseTest { }; } - @Test(timeOut = 60_000, dataProvider = "topicTypes", invocationCount = 100) + @Test(timeOut = 60_000, dataProvider = "topicTypes") public void testRegexSubscriptionWithTopicDiscovery(TopicType topicType) throws Exception { + @Cleanup final PulsarClient client = PulsarClient.builder().serviceUrl(proxyService.getServiceUrl()).build(); final int topics = 10; final String subName = "s1"; @@ -395,7 +397,7 @@ public class ProxyTest extends MockedPulsarServiceBaseTest { SchemaInfo schemaInfo = ((PulsarClientImpl) client).getLookup() .getSchema(TopicName.get("persistent://sample/test/local/get-schema"), schemaVersion) .get().orElse(null); - Assert.assertEquals(new String(schemaInfo.getSchema()), new String(schema.getSchemaInfo().getSchema())); + assertEquals(new String(schemaInfo.getSchema()), new String(schema.getSchemaInfo().getSchema())); } @Test @@ -463,7 +465,7 @@ public class ProxyTest extends MockedPulsarServiceBaseTest { PulsarClient client = PulsarClient.builder().serviceUrl(proxyService.getServiceUrl()) .build(); - String topic = "persistent://sample/test/local/testGetClientVersion"; + String topic = BrokerTestUtil.newUniqueName("persistent://sample/test/local/testGetClientVersion"); String subName = "test-sub"; @Cleanup @@ -474,8 +476,8 @@ public class ProxyTest extends MockedPulsarServiceBaseTest { consumer.receiveAsync(); - - Assert.assertEquals(admin.topics().getStats(topic).getSubscriptions().get(subName).getConsumers() + String partition = TopicName.get(topic).getPartition(0).toString(); + assertEquals(admin.topics().getStats(partition).getSubscriptions().get(subName).getConsumers() .get(0).getClientVersion(), String.format("Pulsar-Java-v%s", PulsarVersion.getVersion())); }