### Question:
TransactionDependenciesResolver { public String describeBlockingTransactions( KernelTransactionHandle handle ) { Set<KernelTransactionHandle> allBlockers = new TreeSet<>( Comparator.comparingLong( KernelTransactionHandle::getUserTransactionId ) ); Set<KernelTransactionHandle> handles = directDependencies.get( handle ); if ( handles != null ) { Deque<KernelTransactionHandle> blockerQueue = new ArrayDeque<>( handles ); while ( !blockerQueue.isEmpty() ) { KernelTransactionHandle transactionHandle = blockerQueue.pop(); if ( allBlockers.add( transactionHandle ) ) { Set<KernelTransactionHandle> transactionHandleSet = directDependencies.get( transactionHandle ); if ( transactionHandleSet != null ) { blockerQueue.addAll( transactionHandleSet ); } } } } return describe( allBlockers ); } TransactionDependenciesResolver( Map<KernelTransactionHandle,List<QuerySnapshot>> handleSnapshotsMap ); boolean isBlocked( KernelTransactionHandle handle ); String describeBlockingTransactions( KernelTransactionHandle handle  ); Map<String,Object> describeBlockingLocks( KernelTransactionHandle handle );  }### Answer:
@Test public void blockingChainDescriptionForIndependentTransactionsIsEmpty() { HashMap<KernelTransactionHandle,List<QuerySnapshot>> map = new HashMap<>(); TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks( new StubKernelTransaction() ); TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks( new StubKernelTransaction() ); map.put( handle1, singletonList( createQuerySnapshot( 1 ) ) ); map.put( handle2, singletonList( createQuerySnapshot( 2 ) ) ); TransactionDependenciesResolver resolver = new TransactionDependenciesResolver( map ); assertThat( resolver.describeBlockingTransactions( handle1 ), isEmptyString() ); assertThat( resolver.describeBlockingTransactions( handle2 ), isEmptyString() ); }
@Test public void blockingChainDescriptionForDirectlyBlockedTransaction() { HashMap<KernelTransactionHandle,List<QuerySnapshot>> map = new HashMap<>(); TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks( new StubKernelTransaction(), 3, singletonList( ActiveLock.exclusiveLock( ResourceTypes.NODE, 1 ) ) ); TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks( new StubKernelTransaction() ); map.put( handle1, singletonList( createQuerySnapshot( 1 ) ) ); map.put( handle2, singletonList( createQuerySnapshotWaitingForLock( 2, false, ResourceTypes.NODE, 1 ) ) ); TransactionDependenciesResolver resolver = new TransactionDependenciesResolver( map ); assertThat( resolver.describeBlockingTransactions( handle1 ), isEmptyString() ); assertEquals( "[transaction-3]", resolver.describeBlockingTransactions( handle2 ) ); }
@Test public void blockingChainDescriptionForChainedBlockedTransaction() { HashMap<KernelTransactionHandle,List<QuerySnapshot>> map = new HashMap<>(); TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks( new StubKernelTransaction(), 4, singletonList( ActiveLock.exclusiveLock( ResourceTypes.NODE, 1 ) ) ); TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks( new StubKernelTransaction(), 5, singletonList( ActiveLock.sharedLock( ResourceTypes.NODE, 2) ) ); TestKernelTransactionHandle handle3 = new TestKernelTransactionHandleWithLocks( new StubKernelTransaction(), 6 ); map.put( handle1, singletonList( createQuerySnapshot( 1 ) ) ); map.put( handle2, singletonList( createQuerySnapshotWaitingForLock( 2, false, ResourceTypes.NODE, 1 ) ) ); map.put( handle3, singletonList( createQuerySnapshotWaitingForLock( 3, true, ResourceTypes.NODE, 2 ) ) ); TransactionDependenciesResolver resolver = new TransactionDependenciesResolver( map ); assertThat( resolver.describeBlockingTransactions( handle1 ), isEmptyString() ); assertEquals( "[transaction-4]", resolver.describeBlockingTransactions( handle2 ) ); assertEquals( "[transaction-4, transaction-5]", resolver.describeBlockingTransactions( handle3 ) ); }