lhotari commented on code in PR #25104:
URL: https://github.com/apache/pulsar/pull/25104#discussion_r2642299986
##########
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:
the 2 separate operations aren't atomic together so I don't see how the
behavior could be validated this way.
It's possible to have a valid data race for example between the put and
remove where the `records` becomes inconsistent even though there's no problem.
t1
```
cursor.putProperty(randomKey, randomValue);
records.put(randomKey, randomValue);
```
t2
```
cursor.removeProperty(randomKey);
records.remove(randomKey);
```
For example with the order of operations:
```
t1 - cursor.putProperty(randomKey, randomValue);
t2 - cursor.removeProperty(randomKey);
t2 - records.remove(randomKey);
t1 - records.put(randomKey, randomValue);
```
--
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]