@Override public Iterator<ConstraintDescriptor> constraintsGetAll() { ktx.assertOpen(); Iterator<ConstraintDescriptor> constraints = storageReader.constraintsGetAll(); if ( ktx.hasTxStateWithChanges() ) { constraints = ktx.txState().constraintsChanges().apply( constraints ); } return Iterators.map( this::lockConstraint, constraints ); }
@Test public void shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints() { // given int labelId = 1; int relTypeId = 2; UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel( labelId, 2, 3, 3 ); RelExistenceConstraintDescriptor existenceConstraint = existsForRelType( relTypeId, 3, 4, 5 ); when( storageReader.constraintsGetAll() ) .thenReturn( Iterators.iterator( uniquenessConstraint, existenceConstraint ) ); // when Iterator<ConstraintDescriptor> result = allStoreHolder.constraintsGetAll( ); Iterators.count( result ); // then assertThat( asList( result ), empty() ); order.verify( storageReader ).constraintsGetAll(); order.verify( locks ).acquireShared( LockTracer.NONE, ResourceTypes.LABEL, labelId ); order.verify( locks ).acquireShared( LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId ); }
Iterator<ConstraintDescriptor> constraintsGetForProperty( int propertyKey ) { ktx.assertOpen(); Iterator<ConstraintDescriptor> constraints = storageReader.constraintsGetAll(); if ( ktx.hasTxStateWithChanges() ) { constraints = ktx.txState().constraintsChanges().apply( constraints ); } return Iterators.map( this::lockConstraint, Iterators.filter( hasProperty( propertyKey ), constraints ) ); }
@Test public void shouldAcquireSchemaReadLockBeforeSettingPropertyOnNode() throws Exception { // given when( nodeCursor.next() ).thenReturn( true ); when( nodeCursor.labels() ).thenReturn( LabelSet.NONE ); int relatedLabelId = 50; int unrelatedLabelId = 51; int propertyKeyId = 8; int unrelatedPropertyKeyId = 88; Value value = Values.of( 9 ); when( propertyCursor.next() ).thenReturn( true ); when( propertyCursor.propertyKey() ).thenReturn( propertyKeyId ); when( propertyCursor.propertyValue() ).thenReturn( NO_VALUE ); when( storageReader.constraintsGetAll() ).thenReturn( Iterators.iterator( ConstraintDescriptorFactory.uniqueForLabel( relatedLabelId, propertyKeyId ), ConstraintDescriptorFactory.uniqueForLabel( unrelatedLabelId, unrelatedPropertyKeyId )) ); // when operations.nodeSetProperty( 123, propertyKeyId, value ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 123 ); order.verify( locks ).acquireShared( LockTracer.NONE, ResourceTypes.LABEL, relatedLabelId ); order.verify( locks, never() ).acquireShared( LockTracer.NONE, ResourceTypes.LABEL, unrelatedLabelId ); order.verify( txState ).nodeDoAddProperty( 123, propertyKeyId, value ); }
when( storageReader.nodeExists( anyLong() ) ).thenReturn( true ); when( storageReader.constraintsGetForLabel( anyInt() )).thenReturn( Collections.emptyIterator() ); when( storageReader.constraintsGetAll() ).thenReturn( Collections.emptyIterator() ); when( engine.newReader() ).thenReturn( storageReader ); allStoreHolder = new AllStoreHolder( storageReader, transaction, cursors, mock(
@Test public void shouldListAllConstraints() { // Given createUniquenessConstraint( label1, propertyKey ); createUniquenessConstraint( label2, propertyKey ); // When Set<ConstraintDescriptor> constraints = asSet( storageReader.constraintsGetAll() ); // Then Set<?> expectedConstraints = asSet( uniqueConstraintDescriptor( label1, propertyKey ), uniqueConstraintDescriptor( label2, propertyKey ) ); assertEquals( expectedConstraints, constraints ); }
@Override public Iterator<ConstraintDescriptor> constraintsGetAll() { ktx.assertOpen(); Iterator<ConstraintDescriptor> constraints = storageReader.constraintsGetAll(); if ( ktx.hasTxStateWithChanges() ) { constraints = ktx.txState().constraintsChanges().apply( constraints ); } return Iterators.map( this::lockConstraint, constraints ); }
Iterator<ConstraintDescriptor> constraintsGetForProperty( int propertyKey ) { ktx.assertOpen(); Iterator<ConstraintDescriptor> constraints = storageReader.constraintsGetAll(); if ( ktx.hasTxStateWithChanges() ) { constraints = ktx.txState().constraintsChanges().apply( constraints ); } return Iterators.map( this::lockConstraint, Iterators.filter( hasProperty( propertyKey ), constraints ) ); }