ascherbakoff commented on code in PR #7799:
URL: https://github.com/apache/ignite-3/pull/7799#discussion_r3055764838
##########
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));
+ }
+
+ @Test
+ public void upgradeLockImmediatelyTest() {
+ UUID txId0 = TestTransactionIds.newTransactionId();
+ UUID txId1 = TestTransactionIds.newTransactionId();
+ UUID txId2 = TestTransactionIds.newTransactionId();
+
+ LockKey key = lockKey();
+
+ CompletableFuture<Lock> fut = lockManager.acquire(txId0, key, IS);
+ assertTrue(fut.isDone());
+
+ CompletableFuture<Lock> fut0 = lockManager.acquire(txId1, key, IS);
+ assertTrue(fut0.isDone());
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(txId2, key, IS);
+ assertTrue(fut1.isDone());
+
+ CompletableFuture<Lock> fut2 = lockManager.acquire(txId1, key, IX);
+ assertTrue(fut2.isDone());
+
+ lockManager.release(fut1.join());
+ }
+
+ @Test
+ public void testSingleKeyReadWriteLock() {
+ UUID txId0 = TestTransactionIds.newTransactionId();
+ UUID txId1 = TestTransactionIds.newTransactionId();
+ UUID txId2 = TestTransactionIds.newTransactionId();
+ UUID txId3 = TestTransactionIds.newTransactionId();
+ assertTrue(txId3.compareTo(txId2) > 0);
+ assertTrue(txId2.compareTo(txId1) > 0);
+ assertTrue(txId1.compareTo(txId0) > 0);
+ LockKey key = lockKey();
+
+ CompletableFuture<Lock> fut3 = lockManager.acquire(txId3, key, S);
+ assertTrue(fut3.isDone());
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(txId1, key, S);
+ assertTrue(fut1.isDone());
+
+ CompletableFuture<Lock> fut2 = lockManager.acquire(txId2, key, S);
+ assertTrue(fut2.isDone());
+
+ CompletableFuture<Lock> fut0 = lockManager.acquire(txId0, key, X);
+ assertFalse(fut0.isDone());
+
+ assertTrue(lockManager.waiter(key, txId3).locked());
+ assertTrue(lockManager.waiter(key, txId2).locked());
+ assertTrue(lockManager.waiter(key, txId1).locked());
+ assertFalse(lockManager.waiter(key, txId0).locked());
+
+ lockManager.release(fut1.join());
+
+ assertTrue(lockManager.waiter(key, txId3).locked());
+ assertTrue(lockManager.waiter(key, txId2).locked());
+ assertNull(lockManager.waiter(key, txId1));
+ assertFalse(lockManager.waiter(key, txId0).locked());
+
+ lockManager.release(fut3.join());
+
+ assertNull(lockManager.waiter(key, txId3));
+ assertTrue(lockManager.waiter(key, txId2).locked());
+ assertNull(lockManager.waiter(key, txId1));
+ assertFalse(lockManager.waiter(key, txId0).locked());
+
+ lockManager.release(fut2.join());
+
+ assertNull(lockManager.waiter(key, txId3));
+ assertNull(lockManager.waiter(key, txId2));
+ assertNull(lockManager.waiter(key, txId1));
+ assertTrue(lockManager.waiter(key, txId0).locked());
+ }
+
+ @Test
+ public void testSingleKeyReadWriteConflict() {
+ UUID txId0 = TestTransactionIds.newTransactionId();
+ UUID txId1 = TestTransactionIds.newTransactionId();
+ LockKey key = lockKey();
+
+ // Lock in order
+ CompletableFuture<Lock> fut0 = lockManager.acquire(txId1, key, S);
+ assertTrue(fut0.isDone());
+
+ CompletableFuture<Lock> fut1 = lockManager.acquire(txId0, key, X);
+ assertFalse(fut1.isDone());
+
+ lockManager.release(fut0.join());
+ assertTrue(fut1.isDone());
+
+ lockManager.release(fut1.join());
+
+ assertTrue(lockManager.queue(key).isEmpty());
+
+ // Lock not in order
+ fut0 = lockManager.acquire(txId0, key, S);
+ assertTrue(fut0.isDone());
+
+ try {
+ lockManager.acquire(txId1, key, X).join();
+
+ fail();
+ } catch (CompletionException e) {
+ // Expected.
+ }
Review Comment:
Fixed
--
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]