shibd commented on code in PR #25293:
URL: https://github.com/apache/pulsar/pull/25293#discussion_r2944139870


##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/TableViewTest.java:
##########
@@ -97,6 +102,17 @@ protected void cleanup() throws Exception {
         super.internalCleanup();
     }
 
+    @Test
+    public void testFailedCreateReader() throws Exception {

Review Comment:
   This test needs to assert a throw exception. 
   
   In fact, this test duplication with 
[broker/transaction/buffer/impl/TableViewTest.java‎](https://github.com/apache/pulsar/pull/25293/changes#diff-edfc112d734b7be5af2074033fa84f7f49e22ca47223cf064ae2bc19208eabb4)



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/buffer/impl/TableViewTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.transaction.buffer.impl;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.function.Function;
+import org.apache.pulsar.broker.systopic.SystemTopicClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.util.FutureUtil;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TableViewTest {
+
+    @Test
+    public void testFailedCreateReader() throws Exception {

Review Comment:
   A more targeted test could focus on the actual contention this PR fixes:
   
   - `ns1` gets a blocked `CompletableFuture<Reader<T>>`
   - thread A calls `readLatest("public/ns1/t1")`
   - before `future1` completes, thread B calls `readLatest("public/ns2/t2")`
   - assert that `ns2` can still reach `readerCreator` and cache its own future
   
   That is the observable difference from the old code: previously thread B 
would be stuck behind the global `SimpleCache.get()` lock while thread A was 
waiting inside the synchronized block.
   
   Pseudo-code:
   ```java
   CompletableFuture<Reader<Object>> future1 = new CompletableFuture<>();
   CompletableFuture<Reader<Object>> future2 = new CompletableFuture<>();
   CountDownLatch ns1Called = new CountDownLatch(1);
   CountDownLatch ns2Called = new CountDownLatch(1);
   
   readerCreator = topic -> {
       if (topic.getNamespaceObject().toString().equals("public/ns1")) {
           ns1Called.countDown();
           return future1;
       } else {
           ns2Called.countDown();
           return future2;
       }
   };
   
   runAsync(() -> tableView.readLatest("public/ns1/t1"));
   assertTrue(ns1Called.await(1, SECONDS));
   runAsync(() -> tableView.readLatest("public/ns2/t2"));
   assertTrue(ns2Called.await(1, SECONDS)); // this is the key assertion
   
   future1.complete(mockReaderReturningNoEvents());
   future2.complete(mockReaderReturningNoEvents());
   ```
   
   If `ns2Called` cannot fire until `future1` completes, the old lock 
amplification behavior is still present.



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/buffer/impl/TableViewTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.transaction.buffer.impl;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.function.Function;
+import org.apache.pulsar.broker.systopic.SystemTopicClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.common.naming.TopicName;
+import org.apache.pulsar.common.util.FutureUtil;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TableViewTest {
+
+    @Test
+    public void testFailedCreateReader() throws Exception {

Review Comment:
   This test covers the failure path, but it does not exercise the contention 
scenario that this PR is actually fixing. Could we add a targeted concurrency 
test where one namespace caches a blocked `CompletableFuture<Reader<T>>`, and 
then a second `readLatest()` on another namespace is started before the first 
future completes? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to