Search in sources :

Example 1 with TestKernelTransactionHandle

use of org.neo4j.kernel.impl.api.TestKernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method blockingChainDescriptionForDirectlyBlockedTransaction.

@Test
void blockingChainDescriptionForDirectlyBlockedTransaction() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 3, singletonList(new ActiveLock(ResourceTypes.NODE, EXCLUSIVE, 1, 1)));
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, SHARED, ResourceTypes.NODE, 1, 1)));
    TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
    assertThat(resolver.describeBlockingTransactions(handle1)).isEmpty();
    assertEquals("[transaction-3]", resolver.describeBlockingTransactions(handle2));
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) Optional(java.util.Optional) HashMap(java.util.HashMap) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Example 2 with TestKernelTransactionHandle

use of org.neo4j.kernel.impl.api.TestKernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method detectBlockedTransactionsByExclusiveLock.

@Test
void detectBlockedTransactionsByExclusiveLock() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 0, singletonList(new ActiveLock(ResourceTypes.NODE, EXCLUSIVE, 1, 1)));
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, SHARED, ResourceTypes.NODE, 1, 1)));
    TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
    assertFalse(resolver.isBlocked(handle1));
    assertTrue(resolver.isBlocked(handle2));
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) Optional(java.util.Optional) HashMap(java.util.HashMap) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Example 3 with TestKernelTransactionHandle

use of org.neo4j.kernel.impl.api.TestKernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method blockingChainDescriptionForIndependentTransactionsIsEmpty.

@Test
void blockingChainDescriptionForIndependentTransactionsIsEmpty() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshot(2)));
    TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
    assertThat(resolver.describeBlockingTransactions(handle1)).isEmpty();
    assertThat(resolver.describeBlockingTransactions(handle2)).isEmpty();
}
Also used : Optional(java.util.Optional) HashMap(java.util.HashMap) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Example 4 with TestKernelTransactionHandle

use of org.neo4j.kernel.impl.api.TestKernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method detectIndependentTransactionsAsNotBlocked.

@Test
void detectIndependentTransactionsAsNotBlocked() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshot(2)));
    TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
    assertFalse(resolver.isBlocked(handle1));
    assertFalse(resolver.isBlocked(handle2));
}
Also used : Optional(java.util.Optional) HashMap(java.util.HashMap) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Example 5 with TestKernelTransactionHandle

use of org.neo4j.kernel.impl.api.TestKernelTransactionHandle in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method blockingChainDescriptionForChainedBlockedTransaction.

@Test
void blockingChainDescriptionForChainedBlockedTransaction() {
    HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
    TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 4, singletonList(new ActiveLock(ResourceTypes.NODE, EXCLUSIVE, 4, 1)));
    TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 5, singletonList(new ActiveLock(ResourceTypes.NODE, SHARED, 5, 2)));
    TestKernelTransactionHandle handle3 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 6);
    map.put(handle1, Optional.of(createQuerySnapshot(1)));
    map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, EXCLUSIVE, ResourceTypes.NODE, 5, 1)));
    map.put(handle3, Optional.of(createQuerySnapshotWaitingForLock(3, EXCLUSIVE, ResourceTypes.NODE, 6, 2)));
    TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
    assertThat(resolver.describeBlockingTransactions(handle1)).isEmpty();
    assertEquals("[transaction-4]", resolver.describeBlockingTransactions(handle2));
    assertEquals("[transaction-4, transaction-5]", resolver.describeBlockingTransactions(handle3));
}
Also used : ActiveLock(org.neo4j.lock.ActiveLock) Optional(java.util.Optional) HashMap(java.util.HashMap) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) TestKernelTransactionHandle(org.neo4j.kernel.impl.api.TestKernelTransactionHandle) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)6 Optional (java.util.Optional)6 Test (org.junit.jupiter.api.Test)6 KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)6 TestKernelTransactionHandle (org.neo4j.kernel.impl.api.TestKernelTransactionHandle)6 ActiveLock (org.neo4j.lock.ActiveLock)4