3pacccccc commented on code in PR #25104:
URL: https://github.com/apache/pulsar/pull/25104#discussion_r2642889320
##########
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java:
##########
@@ -204,6 +206,81 @@ public void testOpenCursorWithNullInitialPosition() throws
Exception {
assertEquals(cursor.getMarkDeletedPosition(),
ledger.getLastConfirmedEntry());
}
+ @Test
+ public void testConcurrentPropertyOperationsThreadSafety() throws
Exception {
+ ManagedLedgerConfig config = new ManagedLedgerConfig();
+ ManagedLedger ledger =
factory.open("testConcurrentPropertyOperationsThreadSafety", config);
+ ManagedCursorImpl cursor = (ManagedCursorImpl)
ledger.openCursor("c_concurrent", null);
+
+ int threadCount = 100;
+ ExecutorService executor = Executors.newFixedThreadPool(threadCount);
+
+ //Stress test with random operations for 5 seconds
+ long testEndTime = System.currentTimeMillis() + 5000;
+ AtomicLong totalOperations = new AtomicLong(0);
+ AtomicLong exceptionCount = new AtomicLong(0);
+ AtomicBoolean inconsistencyDetected = new AtomicBoolean(false);
+
+ ConcurrentHashMap<String, Long> records = new ConcurrentHashMap<>();
+ while (System.currentTimeMillis() < testEndTime) {
+ executor.submit(() -> {
+ try {
+ totalOperations.incrementAndGet();
+ Random random = new Random();
+ int operationType = random.nextInt(3);
+ String randomKey = "key" + random.nextInt(20);
+
+ switch (operationType) {
+ case 0: // Put operation
+ Long randomValue = random.nextLong();
+ cursor.putProperty(randomKey, randomValue);
+ records.put(randomKey, randomValue);
Review Comment:
@lhotari Thanks for the catch! You're right about the atomicity issue. I've
removed the tracking map and now the test just checks for thread safety issues
directly - no exceptions and no data corruption
--
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]