You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xy...@apache.org on 2022/08/08 01:43:10 UTC

[pulsar] branch branch-2.8 updated: Fix testProducerInvalidMessageMemoryRelease

This is an automated email from the ASF dual-hosted git repository.

xyz pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.8 by this push:
     new 9bc0115c727 Fix testProducerInvalidMessageMemoryRelease
9bc0115c727 is described below

commit 9bc0115c727b9e84d2d27dd188b64fb6c56c420a
Author: Yunze Xu <xy...@163.com>
AuthorDate: Mon Aug 8 09:42:27 2022 +0800

    Fix testProducerInvalidMessageMemoryRelease
---
 .../apache/pulsar/client/impl/ProducerMemoryLimitTest.java    | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerMemoryLimitTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerMemoryLimitTest.java
index 0856dfc88b2..7522f339622 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerMemoryLimitTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ProducerMemoryLimitTest.java
@@ -23,13 +23,12 @@ import org.apache.pulsar.client.api.ProducerConsumerBase;
 import org.apache.pulsar.client.api.PulsarClient;
 import org.apache.pulsar.client.api.PulsarClientException;
 import org.apache.pulsar.client.api.SizeUnit;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import java.lang.reflect.Field;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.TimeUnit;
 
@@ -61,11 +60,11 @@ public class ProducerMemoryLimitTest extends ProducerConsumerBase {
                 .enableBatching(true)
                 .create();
         this.stopBroker();
+        Field maxMessageSizeFiled = ClientCnx.class.getDeclaredField("maxMessageSize");
+        maxMessageSizeFiled.setAccessible(true);
+        maxMessageSizeFiled.set(null, 8);
         try {
-            try (MockedStatic<ClientCnx> mockedStatic = Mockito.mockStatic(ClientCnx.class)) {
-                mockedStatic.when(ClientCnx::getMaxMessageSize).thenReturn(8);
-                producer.send("memory-test".getBytes(StandardCharsets.UTF_8));
-            }
+            producer.send("memory-test".getBytes(StandardCharsets.UTF_8));
             throw new IllegalStateException("can not reach here");
         } catch (PulsarClientException.InvalidMessageException ex) {
             PulsarClientImpl clientImpl = (PulsarClientImpl) this.pulsarClient;