@Test public void shouldAcquireSchemaReadLockBeforeGettingConstraintsByLabel() { // WHEN allStoreHolder.constraintsGetForLabel( 42 ); // THEN order.verify( locks ).acquireShared( LockTracer.NONE, ResourceTypes.LABEL, 42 ); order.verify( storageReader ).constraintsGetForLabel( 42 ); }
@Override public Iterator<ConstraintDescriptor> constraintsGetForLabel( int labelId ) { acquireSharedLock( ResourceTypes.LABEL, labelId ); ktx.assertOpen(); Iterator<ConstraintDescriptor> constraints = storageReader.constraintsGetForLabel( labelId ); if ( ktx.hasTxStateWithChanges() ) { return ktx.txState().constraintsChangesForLabel( labelId ).apply( constraints ); } return constraints; }
storageReader = mock( StorageReader.class ); when( storageReader.nodeExists( anyLong() ) ).thenReturn( true ); when( storageReader.constraintsGetForLabel( anyInt() )).thenReturn( Collections.emptyIterator() ); when( storageReader.constraintsGetAll() ).thenReturn( Collections.emptyIterator() ); when( engine.newReader() ).thenReturn( storageReader );
@Test public void shouldListAllConstraintsForLabel() { // Given createUniquenessConstraint( label1, propertyKey ); createUniquenessConstraint( label2, propertyKey ); // When Set<ConstraintDescriptor> constraints = asSet( storageReader.constraintsGetForLabel( labelId( label1 ) ) ); // Then Set<?> expectedConstraints = asSet( uniqueConstraintDescriptor( label1, propertyKey ) ); assertEquals( expectedConstraints, constraints ); }
@Override public Iterator<ConstraintDescriptor> constraintsGetForLabel( int labelId ) { acquireSharedLock( ResourceTypes.LABEL, labelId ); ktx.assertOpen(); Iterator<ConstraintDescriptor> constraints = storageReader.constraintsGetForLabel( labelId ); if ( ktx.hasTxStateWithChanges() ) { return ktx.txState().constraintsChangesForLabel( labelId ).apply( constraints ); } return constraints; }