ascherbakoff commented on code in PR #7799:
URL: https://github.com/apache/ignite-3/pull/7799#discussion_r3055754365
##########
modules/transactions/src/test/java/org/apache/ignite/internal/tx/HeapLockManagerTest.java:
##########
@@ -150,4 +169,1220 @@ public void
testCompatibilityLockMapSizePropertyNameWasNotChanged() {
LOCK_MAP_SIZE_PROPERTY_NAME
);
}
+
+ @Test
+ public void testSingleKeyWrite() {
+ UUID txId1 = TestTransactionIds.newTransactionId();
+
+ LockKey key = lockKey();
+
+ CompletableFuture<Lock> fut0 = lockManager.acquire(txId1, key, X);
+
+ assertTrue(fut0.isDone());
+
+ Collection<UUID> queue = lockManager.queue(key);
+
+ assertTrue(queue.size() == 1 && queue.iterator().next().equals(txId1));
+
+ Waiter waiter = lockManager.waiter(key, txId1);
+
+ assertTrue(waiter.locked());
+
+ lockManager.release(fut0.join());
+ }
+
+ @Test
+ public void testSingleKeyWriteLock() {
+ UUID txId1 = TestTransactionIds.newTransactionId();
+ UUID txId2 = TestTransactionIds.newTransactionId();
+
+ LockKey key = lockKey();
+
+ CompletableFuture<Lock> fut0 = lockManager.acquire(txId2, key, X);
+
+ assertTrue(fut0.isDone());
+
+ assertTrue(txId2.compareTo(txId1) > 0);
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(txId1, key, X);
+
+ assertFalse(fut1.isDone());
+
+ assertTrue(lockManager.waiter(key, txId2).locked());
+ assertFalse(lockManager.waiter(key, txId1).locked());
+
+ lockManager.release(fut0.join());
+
+ assertTrue(fut1.isDone());
+
+ assertNull(lockManager.waiter(key, txId2));
+ assertTrue(lockManager.waiter(key, txId1).locked());
+
+ lockManager.release(fut1.join());
+
+ assertNull(lockManager.waiter(key, txId2));
+ assertNull(lockManager.waiter(key, txId1));
+ }
+
+ @Test
+ public void downgradeLockOutOfTurnTest() {
+ UUID txId0 = TestTransactionIds.newTransactionId();
+ UUID txId1 = TestTransactionIds.newTransactionId();
+ UUID txId2 = TestTransactionIds.newTransactionId();
+
+ LockKey key = lockKey();
+
+ lockManager.acquire(txId0, key, S).join();
+ Lock lock = lockManager.acquire(txId2, key, S).join();
+
+ CompletableFuture<Lock> fut0 = lockManager.acquire(txId0, key, X);
+ assertFalse(fut0.isDone());
+
+ CompletableFuture<Lock> fut2 = lockManager.acquire(txId2, key, X);
+ expectConflict(fut2);
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(txId1, key, S);
+ fut1.join();
+
+ assertFalse(fut0.isDone());
+
+ lockManager.release(lock);
+ fut0.thenAccept(l -> lockManager.release(l));
Review Comment:
Fixed the test (however, this test is not written by me)
--
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]