Refine search
@Test public void shouldAcquireEntityWriteLockBeforeAddingLabelToNode() throws Exception { // given when( nodeCursor.next() ).thenReturn( true ); when( nodeCursor.labels() ).thenReturn( LabelSet.NONE ); // when operations.nodeAddLabel( 123L, 456 ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 123L ); order.verify( txState ).nodeDoAddLabel( 456, 123L ); }
@Test public void shouldNotAcquireEntityWriteLockBeforeAddingLabelToJustCreatedNode() throws Exception { // given when( nodeCursor.next() ).thenReturn( true ); when( nodeCursor.labels() ).thenReturn( LabelSet.NONE ); when( transaction.hasTxStateWithChanges() ).thenReturn( true ); // when txState.nodeDoCreate( 123 ); operations.nodeAddLabel( 123, 456 ); // then verify( locks, never() ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 123 ); }
@Test public void shouldAcquireEntityWriteLockBeforeDeletingNode() throws AutoIndexingKernelException { // GIVEN when( nodeCursor.next() ).thenReturn( true ); when( nodeCursor.labels() ).thenReturn( LabelSet.NONE ); when( allStoreHolder.nodeExistsInStore( 123 ) ).thenReturn( true ); // WHEN operations.nodeDelete( 123 ); //THEN order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 123 ); order.verify( txState ).nodeDoDelete( 123 ); }
@Test public void shouldNotAcquireEntityWriteLockBeforeDeletingJustCreatedNode() throws Exception { // THEN txState.nodeDoCreate( 123 ); when( transaction.hasTxStateWithChanges() ).thenReturn( true ); // WHEN operations.nodeDelete( 123 ); //THEN verify( locks, never() ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 123 ); verify( txState ).nodeDoDelete( 123 ); }
@Test public void shouldAcquireEntityWriteLockBeforeSettingPropertyOnNode() throws Exception { // given when( nodeCursor.next() ).thenReturn( true ); when( nodeCursor.labels() ).thenReturn( LabelSet.NONE ); int propertyKeyId = 8; Value value = Values.of( 9 ); when( propertyCursor.next() ).thenReturn( true ); when( propertyCursor.propertyKey() ).thenReturn( propertyKeyId ); when( propertyCursor.propertyValue() ).thenReturn( NO_VALUE ); // when operations.nodeSetProperty( 123, propertyKeyId, value ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 123 ); order.verify( txState ).nodeDoAddProperty( 123, propertyKeyId, value ); }
@Test public void shouldAcquireEntityWriteLockBeforeSettingPropertyOnRelationship() throws Exception { // given when( relationshipCursor.next() ).thenReturn( true ); int propertyKeyId = 8; Value value = Values.of( 9 ); when( propertyCursor.next() ).thenReturn( true ); when( propertyCursor.propertyKey() ).thenReturn( propertyKeyId ); when( propertyCursor.propertyValue() ).thenReturn( NO_VALUE ); // when operations.relationshipSetProperty( 123, propertyKeyId, value ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.RELATIONSHIP, 123 ); order.verify( txState ).relationshipDoReplaceProperty( 123, propertyKeyId, NO_VALUE, value ); }
@Test public void detachDeleteNodeWithoutRelationshipsExclusivelyLockNode() throws KernelException { long nodeId = 1L; returnRelationships( transaction, false, new TestRelationshipChain( nodeId ) ); when( transaction.ambientNodeCursor() ).thenReturn( new StubNodeCursor( false ) ); when( nodeCursor.next() ).thenReturn( true ); LabelSet labels = mock( LabelSet.class ); when( labels.all() ).thenReturn( EMPTY_LONG_ARRAY ); when( nodeCursor.labels() ).thenReturn( labels ); operations.nodeDetachDelete( nodeId ); order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, nodeId ); order.verify( locks, never() ).releaseExclusive( ResourceTypes.NODE, nodeId ); order.verify( txState ).nodeDoDelete( nodeId ); }
@Test public void shouldAcquireEntityWriteLockCreatingRelationship() throws Exception { // when long rId = operations.relationshipCreate( 1, 2, 3 ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 1 ); order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 3 ); order.verify( txState ).relationshipDoCreate( rId, 2, 1, 3 ); }
@Test public void shouldAcquiredSharedLabelLocksWhenRemovingNodeLabel() throws EntityNotFoundException { // given long nodeId = 1L; int labelId = 1; when( nodeCursor.next() ).thenReturn( true ); when( nodeCursor.hasLabel( labelId ) ).thenReturn( true ); // when operations.nodeRemoveLabel( nodeId, labelId ); // then InOrder order = inOrder( locks ); order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, nodeId ); order.verify( locks ).acquireShared( LockTracer.NONE, ResourceTypes.LABEL, labelId ); order.verifyNoMoreInteractions(); }
@Test public void shouldNotAcquireEntityWriteLockBeforeSettingPropertyOnJustCreatedNode() throws Exception { // given when( nodeCursor.next() ).thenReturn( true ); when( nodeCursor.labels() ).thenReturn( LabelSet.NONE ); when( transaction.hasTxStateWithChanges() ).thenReturn( true ); txState.nodeDoCreate( 123 ); int propertyKeyId = 8; Value value = Values.of( 9 ); // when operations.nodeSetProperty( 123, propertyKeyId, value ); // then verify( locks, never() ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 123 ); verify( txState ).nodeDoAddProperty( 123, propertyKeyId, value ); }
@Test public void shouldNotAcquireEntityWriteLockBeforeSettingPropertyOnJustCreatedRelationship() throws Exception { // given when( relationshipCursor.next() ).thenReturn( true ); when( transaction.hasTxStateWithChanges() ).thenReturn( true ); txState.relationshipDoCreate( 123, 42, 43, 45 ); int propertyKeyId = 8; Value value = Values.of( 9 ); // when operations.relationshipSetProperty( 123, propertyKeyId, value ); // then verify( locks, never() ).acquireExclusive( LockTracer.NONE, ResourceTypes.RELATIONSHIP, 123 ); verify( txState ).relationshipDoReplaceProperty( 123, propertyKeyId, NO_VALUE, value ); }
@Test public void shouldAcquireSchemaWriteLockBeforeRemovingIndexRule() throws Exception { // given CapableIndexDescriptor index = TestIndexDescriptorFactory.forLabel( 0, 0 ).withId( 0 ).withoutCapabilities(); when( storageReader.indexGetForSchema( any() )).thenReturn( index ); // when operations.indexDrop( index ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.LABEL, 0 ); order.verify( txState ).indexDoDrop( index ); }
@Test public void shouldAcquireSchemaWriteLockBeforeDroppingConstraint() throws Exception { // given UniquenessConstraintDescriptor constraint = uniqueForSchema( descriptor ); when( storageReader.constraintExists( constraint ) ).thenReturn( true ); // when operations.constraintDrop( constraint ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.LABEL, descriptor.getLabelId() ); order.verify( txState ).constraintDoDrop( constraint ); }
@Test public void shouldAcquireSchemaWriteLockBeforeCreatingUniquenessConstraint() throws Exception { // given String defaultProvider = Config.defaults().get( default_schema_provider ); when( constraintIndexCreator.createUniquenessConstraintIndex( transaction, descriptor, defaultProvider ) ).thenReturn( 42L ); when( storageReader.constraintsGetForSchema( descriptor.schema() ) ).thenReturn( Collections.emptyIterator() ); // when operations.uniquePropertyConstraintCreate( descriptor ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.LABEL, descriptor.getLabelId() ); order.verify( txState ).constraintDoAdd( ConstraintDescriptorFactory.uniqueForSchema( descriptor ), 42L ); }
@Test( expected = LockClientStoppedException.class ) public void shouldNotBeAbleToAcquireExclusiveLockFromClosedClient() { clientA.close(); clientA.acquireExclusive( LockTracer.NONE, NODE, 1L ); }
@Test( expected = LockClientStoppedException.class ) public void acquireExclusiveThrowsWhenClientStopped() { stoppedClient().acquireExclusive( TRACER, NODE, 1 ); }
@Test public void lockNodeWithoutRelationships() throws Exception { Collector collector = new Collector(); TwoPhaseNodeForRelationshipLocking locking = new TwoPhaseNodeForRelationshipLocking( collector, locks, NONE ); returnRelationships( transaction, false, new TestRelationshipChain( 42 ) ); locking.lockAllNodesAndConsumeRelationships( nodeId, transaction, new StubNodeCursor( false ) ); verify( locks ).acquireExclusive( NONE, NODE, nodeId ); verifyNoMoreInteractions( locks ); }
@Test public void shouldTraceWaitTimeWhenTryingToAcquireExclusiveLockAndExclusiveIsHeld() throws Exception { // given Tracer tracerA = new Tracer(); Tracer tracerB = new Tracer(); clientA.acquireExclusive( tracerA, NODE, 17 ); // when Future<Object> future = acquireExclusive( clientB, tracerB, NODE, 17 ).callAndAssertWaiting(); // then clientA.releaseExclusive( NODE, 17 ); future.get(); tracerA.assertCalls( 0 ); tracerB.assertCalls( 1 ); }
@Test public void shouldTraceWaitTimeWhenTryingToAcquireSharedLockAndExclusiveIsHeld() throws Exception { // given Tracer tracerA = new Tracer(); Tracer tracerB = new Tracer(); clientA.acquireExclusive( tracerA, NODE, 17 ); // when Future<Object> future = acquireShared( clientB, tracerB, NODE, 17 ).callAndAssertWaiting(); // then clientA.releaseExclusive( NODE, 17 ); future.get(); tracerA.assertCalls( 0 ); tracerB.assertCalls( 1 ); }
@Test public void sharedShouldWaitForExclusive() { // When clientA.acquireExclusive( LockTracer.NONE, NODE, 1L ); // Then shared locks should wait Future<Object> clientBLock = acquireShared( clientB, LockTracer.NONE, NODE, 1L ).callAndAssertWaiting(); // And when clientA.releaseExclusive( NODE, 1L ); // Then this should not block assertNotWaiting( clientB, clientBLock ); }