You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2025/04/11 09:38:32 UTC

(pulsar) branch master updated: [fix][test] Fix remaining UnfinishedStubbingException issue with AuthZTests (#24174)

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 bfbd5cf4a0c [fix][test] Fix remaining UnfinishedStubbingException issue with AuthZTests (#24174)
bfbd5cf4a0c is described below

commit bfbd5cf4a0c2c97325f6a658de359b12f7db69ef
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Fri Apr 11 12:38:25 2025 +0300

    [fix][test] Fix remaining UnfinishedStubbingException issue with AuthZTests (#24174)
---
 .../org/apache/pulsar/broker/admin/AuthZTest.java  | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AuthZTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AuthZTest.java
index d09ffe268d1..2d46ce26334 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AuthZTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AuthZTest.java
@@ -23,6 +23,7 @@ import io.jsonwebtoken.Jwts;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Consumer;
+import lombok.SneakyThrows;
 import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.pulsar.broker.BrokerTestUtil;
 import org.apache.pulsar.broker.authorization.AuthorizationService;
@@ -34,7 +35,6 @@ import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 
 public abstract class AuthZTest extends MockedPulsarStandalone {
 
@@ -44,8 +44,6 @@ public abstract class AuthZTest extends MockedPulsarStandalone {
 
     protected AuthorizationService authorizationService;
 
-    protected AuthorizationService orignalAuthorizationService;
-
     protected static final String TENANT_ADMIN_SUBJECT =  UUID.randomUUID().toString();
     protected static final String TENANT_ADMIN_TOKEN = Jwts.builder()
             .claim("sub", TENANT_ADMIN_SUBJECT).signWith(SECRET_KEY).compact();
@@ -63,15 +61,19 @@ public abstract class AuthZTest extends MockedPulsarStandalone {
             tenantManagerAdmin.close();
             tenantManagerAdmin = null;
         }
-        authorizationService = null;
-        orignalAuthorizationService = null;
+        if (authorizationService != null) {
+            Mockito.reset(authorizationService);
+            authorizationService = null;
+        }
         super.close();
     }
 
-    @BeforeMethod(alwaysRun = true)
-    public void before() throws IllegalAccessException {
-        orignalAuthorizationService = getPulsarService().getBrokerService().getAuthorizationService();
-        authorizationService = BrokerTestUtil.spyWithoutRecordingInvocations(orignalAuthorizationService);
+    @SneakyThrows
+    @Override
+    protected void start() {
+        super.start();
+        authorizationService = BrokerTestUtil.spyWithoutRecordingInvocations(
+                getPulsarService().getBrokerService().getAuthorizationService());
         FieldUtils.writeField(getPulsarService().getBrokerService(), "authorizationService",
                 authorizationService, true);
         Mockito.doAnswer(invocationOnMock -> {
@@ -98,8 +100,6 @@ public abstract class AuthZTest extends MockedPulsarStandalone {
 
     @AfterMethod(alwaysRun = true)
     public void after() throws IllegalAccessException {
-        FieldUtils.writeField(getPulsarService().getBrokerService(), "authorizationService",
-                orignalAuthorizationService, true);
         allowNamespaceOperationAsyncHandler = null;
         allowTopicOperationAsyncHandler = null;
     }