GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [test][admin] PIP-478: fail the build when a new admin resource is no… · apache/pulsar@4d0f838

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pulsar-client-admin/src
    • main/java/org/apache/pulsar/client/admin/internal
      • BaseResource.java
      • PulsarAdminImpl.java
    • test/java/org/apache/pulsar/client/admin/internal
      • AdminAuthOffloadTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/BaseResource.java‎

Copy file name to clipboardExpand all lines: pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/BaseResource.java
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ void setBlockingAuthExecutor(Executor blockingAuthExecutor) {
9595
this.blockingAuthExecutor = blockingAuthExecutor;
9696
}
9797

98+
/**
99+
* The executor lent by {@link PulsarAdminImpl}, or {@code null} when none was (VisibleForTesting). The
100+
* lending is opt-in per construction site, and a resource that misses it still works — it just falls
101+
* back to the shared pool — so the only thing that can catch a resource added without it is a test that
102+
* reads this.
103+
*
104+
* @return the lent blocking authentication executor, or {@code null}
105+
*/
106+
Executor blockingAuthExecutorForTest() {
107+
return blockingAuthExecutor;
108+
}
109+
98110
public Builder request(final WebTarget target) throws PulsarAdminException {
99111
try {
100112
return requestAsync(target).get();
Collapse file

‎pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/PulsarAdminImpl.java‎

Copy file name to clipboardExpand all lines: pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/PulsarAdminImpl.java
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ private <T extends BaseResource> T lendAuthExecutor(T resource) {
629629
return resource;
630630
}
631631

632+
/**
633+
* The pool the resources above are lent, so a test can assert every one of them got it
634+
* (VisibleForTesting). Lending is per construction site: a resource added later without the wrapper
635+
* compiles, runs, and silently falls back to the shared pool.
636+
*
637+
* @return this admin's blocking authentication executor
638+
*/
639+
ThreadPoolExecutor blockingAuthExecutorForTest() {
640+
return blockingAuthExecutor;
641+
}
642+
632643
/**
633644
* Build the admin's bounded executor for potentially-blocking authentication work (PIP-478).
634645
*
Collapse file

‎pulsar-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AdminAuthOffloadTest.java‎

Copy file name to clipboardExpand all lines: pulsar-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AdminAuthOffloadTest.java
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
package org.apache.pulsar.client.admin.internal;
2020

2121
import static org.assertj.core.api.Assertions.assertThat;
22+
import java.lang.reflect.Method;
23+
import java.lang.reflect.Modifier;
2224
import java.net.URI;
25+
import java.util.ArrayList;
26+
import java.util.List;
2327
import java.util.Map;
2428
import java.util.Set;
2529
import java.util.concurrent.CompletableFuture;
30+
import java.util.concurrent.Executor;
2631
import java.util.concurrent.ExecutorService;
2732
import java.util.concurrent.Executors;
2833
import java.util.concurrent.TimeUnit;
@@ -192,6 +197,44 @@ public void theV4CompositionRunsOnTheOwningAdminsOwnPool() throws Exception {
192197
}
193198
}
194199

200+
/**
201+
* Lending is opt-in per construction site, so a resource added to {@link PulsarAdminImpl} later without
202+
* the wrapper would compile, run, and silently fall back to the shared pool — the fix undone with no
203+
* symptom. Walking the admin's own accessors is what turns that into a test failure; pinning one
204+
* resource would not, since the twenty-fourth is the one that would be missed.
205+
*/
206+
@Test
207+
public void everyResourceTheAdminExposesIsLentThePool() throws Exception {
208+
try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl("http://broker.example:8080").build()) {
209+
Executor pool = ((PulsarAdminImpl) admin).blockingAuthExecutorForTest();
210+
List<String> notLent = new ArrayList<>();
211+
int checked = 0;
212+
213+
for (Method accessor : PulsarAdmin.class.getMethods()) {
214+
if (accessor.getParameterCount() != 0 || Modifier.isStatic(accessor.getModifiers())
215+
|| accessor.getReturnType() == void.class) {
216+
continue;
217+
}
218+
if (accessor.invoke(admin) instanceof BaseResource resource) {
219+
checked++;
220+
if (resource.blockingAuthExecutorForTest() != pool) {
221+
notLent.add(accessor.getName());
222+
}
223+
}
224+
}
225+
// The one resource accessor that takes an argument, so the loop above cannot reach it.
226+
checked++;
227+
if (((BaseResource) admin.topicPolicies(true)).blockingAuthExecutorForTest() != pool) {
228+
notLent.add("topicPolicies(true)");
229+
}
230+
231+
assertThat(notLent).as("admin resources left on the shared pool").isEmpty();
232+
assertThat(checked)
233+
.as("the walk must actually reach the admin's resources, not silently filter them all out")
234+
.isGreaterThanOrEqualTo(20);
235+
}
236+
}
237+
195238
/**
196239
* {@code newRequestHeader} is the second synchronous v4 hook. A plugin that completes the stage
197240
* asynchronously completes it from a thread of its own — its HTTP callback thread — and a plain

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.