Skip to content

Commit 3d6f805

Browse files
committed
[fix][test] Verify getPoliciesAsync uses NamespaceBundleFactory after bundle split
1 parent 7ec3bf5 commit 3d6f805

1 file changed

Lines changed: 38 additions & 20 deletions

File tree

pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,30 +3430,48 @@ public void testCreateAndDeleteNamespaceWithBundles() throws Exception {
34303430
}
34313431

34323432
@Test
3433-
public void testGetNamespacePoliciesSyncAsyncBundlesConsistency() throws Exception {
3434-
// Test that sync (getPolicies) and async (getPoliciesAsync) methods return consistent bundles data.
3433+
public void testGetNamespacePoliciesAsyncReflectsBundleSplit() throws Exception {
3434+
// Test that getPoliciesAsync reflects latest bundles from NamespaceBundleFactory after bundle split.
3435+
// This verifies that the async method uses NamespaceBundleFactory.getBundlesAsync()
3436+
// instead of LocalPolicies.bundles (which may be stale after split).
34353437
String ns = BrokerTestUtil.newUniqueName("prop-xyz/ns");
3436-
int numBundles = 16;
34373438

3438-
admin.namespaces().createNamespace(ns, numBundles);
3439+
// Create namespace with 1 bundle
3440+
admin.namespaces().createNamespace(ns, 1);
34393441

34403442
try {
3441-
// Get policies using sync method
3442-
Policies syncPolicies = admin.namespaces().getPolicies(ns);
3443-
3444-
// Get policies using async method
3445-
Policies asyncPolicies = admin.namespaces().getPoliciesAsync(ns).get();
3446-
3447-
// Verify bundles are consistent between sync and async
3448-
assertNotNull(syncPolicies.bundles, "Sync policies should have bundles");
3449-
assertNotNull(asyncPolicies.bundles, "Async policies should have bundles");
3450-
assertEquals(asyncPolicies.bundles.getNumBundles(), syncPolicies.bundles.getNumBundles(),
3451-
"Number of bundles should match between sync and async");
3452-
assertEquals(asyncPolicies.bundles.getBoundaries(), syncPolicies.bundles.getBoundaries(),
3453-
"Bundle boundaries should match between sync and async");
3454-
3455-
// Also verify the expected number of bundles
3456-
assertEquals(syncPolicies.bundles.getNumBundles(), numBundles);
3443+
// Verify initial state - should have 1 bundle
3444+
Policies initialPolicies = admin.namespaces().getPoliciesAsync(ns).get();
3445+
assertEquals(initialPolicies.bundles.getNumBundles(), 1, "Should start with 1 bundle");
3446+
assertEquals(initialPolicies.bundles.getBoundaries().size(), 2,
3447+
"1 bundle should have 2 boundaries");
3448+
3449+
// Split the bundle into 2
3450+
admin.namespaces().splitNamespaceBundle(ns, "0x00000000_0xffffffff", true, null);
3451+
3452+
// Wait for split to complete in NamespaceBundleFactory
3453+
Awaitility.await().untilAsserted(() -> {
3454+
NamespaceBundles bundles = pulsar.getNamespaceService()
3455+
.getNamespaceBundleFactory()
3456+
.getBundles(NamespaceName.get(ns));
3457+
assertEquals(bundles.getBundles().size(), 2,
3458+
"NamespaceBundleFactory should have 2 bundles after split");
3459+
});
3460+
3461+
// getPoliciesAsync should now reflect the split bundles from NamespaceBundleFactory
3462+
// Before the fix: LocalPolicies.bundles would still show 1 bundle (stale data)
3463+
// After the fix: NamespaceBundleFactory.getBundlesAsync() provides latest 2 bundles
3464+
Policies afterSplitPolicies = admin.namespaces().getPoliciesAsync(ns).get();
3465+
assertEquals(afterSplitPolicies.bundles.getNumBundles(), 2,
3466+
"getPoliciesAsync should reflect bundles from NamespaceBundleFactory after split");
3467+
assertEquals(afterSplitPolicies.bundles.getBoundaries().size(), 3,
3468+
"2 bundles should have 3 boundaries");
3469+
3470+
// Verify the boundaries are correct (0x00000000, 0x7fffffff, 0xffffffff)
3471+
List<String> boundaries = afterSplitPolicies.bundles.getBoundaries();
3472+
assertEquals(boundaries.get(0), "0x00000000");
3473+
assertEquals(boundaries.get(1), "0x7fffffff");
3474+
assertEquals(boundaries.get(2), "0xffffffff");
34573475
} finally {
34583476
deleteNamespaceWithRetry(ns, false);
34593477
}

0 commit comments

Comments
 (0)