@Override public ConstraintCreator createDeferredConstraint( Label label ) { return delegate.createDeferredConstraint( label ); }
@Test public void shouldRunConstraintPopulationJobAtShutdown() throws Throwable { // GIVEN IndexPopulator populator = mock( IndexPopulator.class ); IndexProvider provider = mock( IndexProvider.class ); IndexAccessor accessor = mock( IndexAccessor.class ); when( provider.getProviderDescriptor() ).thenReturn( DESCRIPTOR ); when( provider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( populator ); when( populator.sampleResult() ).thenReturn( new IndexSample() ); when( provider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( accessor ); when( provider.bless( any( IndexDescriptor.class ) ) ).thenCallRealMethod(); BatchInserter inserter = newBatchInserterWithIndexProvider( singleInstanceIndexProviderFactory( KEY, provider ), provider.getProviderDescriptor() ); inserter.createDeferredConstraint( label( "Hacker" ) ).assertPropertyIsUnique( "handle" ).create(); long nodeId = inserter.createNode( map( "handle", "Jakewins" ), label( "Hacker" ) ); // WHEN inserter.shutdown(); // THEN verify( provider ).init(); verify( provider ).start(); verify( provider ).getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ); verify( populator ).create(); verify( populator ).add( argThat( matchesCollection( add( nodeId, internalUniqueIndex.schema(), Values.of( "Jakewins" ) ) ) ) ); verify( populator ).verifyDeferredConstraints( any( NodePropertyAccessor.class ) ); verify( populator ).close( true ); verify( provider ).stop(); verify( provider ).shutdown(); }
@Test public void shouldNotAllowCreationOfDuplicateConstraint() { // GIVEN BatchInserter inserter = globalInserter; String labelName = "Hacker2-" + denseNodeThreshold; // WHEN inserter.createDeferredConstraint( label( labelName ) ).assertPropertyIsUnique( "handle" ).create(); try { inserter.createDeferredConstraint( label( labelName ) ).assertPropertyIsUnique( "handle" ).create(); fail( "Should have thrown exception." ); } catch ( ConstraintViolationException e ) { // THEN Good } }
@Test public void shouldNotAllowDuplicatedUniquenessConstraints() { // Given Label label = label( "Person2-" + denseNodeThreshold ); String property = "name"; BatchInserter inserter = globalInserter; // When inserter.createDeferredConstraint( label ).assertPropertyIsUnique( property ).create(); try { inserter.createDeferredConstraint( label ).assertPropertyIsUnique( property ).create(); fail( "Exception expected" ); } catch ( ConstraintViolationException e ) { // Then assertEquals( "It is not allowed to create node keys, uniqueness constraints or indexes on the same {label;property}", e.getMessage() ); } }
@Test public void uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated() throws Exception { // Given Label label = label( "Foo" ); String property = "Bar"; String value = "Baz"; BatchInserter inserter = newBatchInserter(); // When inserter.createDeferredConstraint( label ).assertPropertyIsUnique( property ).create(); inserter.createNode( Collections.singletonMap( property, value ), label ); inserter.createNode( Collections.singletonMap( property, value ), label ); // Then GraphDatabaseService db = switchToEmbeddedGraphDatabaseService( inserter ); try ( Transaction tx = db.beginTx() ) { IndexDefinition index = db.schema().getIndexes( label ).iterator().next(); String indexFailure = db.schema().getIndexFailure( index ); assertThat( indexFailure, containsString( "IndexEntryConflictException" ) ); assertThat( indexFailure, containsString( value ) ); tx.success(); } finally { db.shutdown(); } }
@Test public void shouldNotAllowCreationOfDeferredSchemaConstraintAfterIndexOnSameKeys() { // GIVEN BatchInserter inserter = globalInserter; String labelName = "Hacker3-" + denseNodeThreshold; // WHEN inserter.createDeferredSchemaIndex( label( labelName ) ).on( "handle" ).create(); try { inserter.createDeferredConstraint( label( labelName ) ).assertPropertyIsUnique( "handle" ).create(); fail( "Should have thrown exception." ); } catch ( ConstraintViolationException e ) { // THEN Good } }
@Test public void shouldNotAllowCreationOfDeferredSchemaIndexAfterConstraintOnSameKeys() { // GIVEN BatchInserter inserter = globalInserter; String labelName = "Hacker4-" + denseNodeThreshold; // WHEN inserter.createDeferredConstraint( label( labelName ) ).assertPropertyIsUnique( "handle" ).create(); try { inserter.createDeferredSchemaIndex( label( labelName ) ).on( "handle" ).create(); fail( "Should have thrown exception." ); } catch ( ConstraintViolationException e ) { // THEN Good } }
@Test public void shouldThrowWhenPopulatingWithNonUniquePoints() throws Exception { Config config = Config.defaults( stringMap( default_schema_provider.name(), schemaIndex.providerName() ) ); BatchInserter inserter = newBatchInserter( config ); PointValue point = Values.pointValue( CoordinateReferenceSystem.WGS84, 0.0, 0.0 ); inserter.createNode( MapUtil.map( "prop", point ), TestLabels.LABEL_ONE ); inserter.createNode( MapUtil.map( "prop", point ), TestLabels.LABEL_ONE ); inserter.createDeferredConstraint( TestLabels.LABEL_ONE ).assertPropertyIsUnique( "prop" ).create(); inserter.shutdown(); GraphDatabaseService db = graphDatabaseService( config ); try ( Transaction tx = db.beginTx() ) { Iterator<IndexDefinition> indexes = db.schema().getIndexes().iterator(); assertTrue( indexes.hasNext() ); IndexDefinition index = indexes.next(); Schema.IndexState indexState = db.schema().getIndexState( index ); assertEquals( Schema.IndexState.FAILED, indexState ); assertFalse( indexes.hasNext() ); tx.success(); } finally { db.shutdown(); } }
@Test public void shouldNotAllowCreationOfUniquenessConstraintAndIndexOnSameLabelAndProperty() { // Given Label label = label( "Person1-" + denseNodeThreshold ); String property = "name"; BatchInserter inserter = globalInserter; // When inserter.createDeferredConstraint( label ).assertPropertyIsUnique( property ).create(); try { inserter.createDeferredSchemaIndex( label ).on( property ).create(); fail( "Exception expected" ); } catch ( ConstraintViolationException e ) { // Then assertEquals( "Index for given {label;property} already exists", e.getMessage() ); } }
inserter.createDeferredConstraint( label( "Hacker" ) ).assertPropertyIsUnique( "handle" ).create();
@Test public void shouldCreateDeferredUniquenessConstraintInEmptyDatabase() throws Exception { // GIVEN BatchInserter inserter = newBatchInserter(); // WHEN ConstraintDefinition definition = inserter.createDeferredConstraint( label( "Hacker" ) ).assertPropertyIsUnique( "handle" ).create(); // THEN assertEquals( "Hacker", definition.getLabel().name() ); assertEquals( ConstraintType.UNIQUENESS, definition.getConstraintType() ); assertEquals( asSet( "handle" ), Iterables.asSet( definition.getPropertyKeys() ) ); inserter.shutdown(); }
inserter.createDeferredConstraint( label ).assertPropertyIsUnique( propertyKey ).create();
@Test public void shouldPopulateIndexWithUniquePointsThatCollideOnSpaceFillingCurve() throws Exception { Config config = Config.defaults( stringMap( default_schema_provider.name(), schemaIndex.providerName() ) ); BatchInserter inserter = newBatchInserter( config ); Pair<PointValue,PointValue> collidingPoints = SpatialIndexValueTestUtil.pointsWithSameValueOnSpaceFillingCurve( config ); inserter.createNode( MapUtil.map( "prop", collidingPoints.first() ), TestLabels.LABEL_ONE ); inserter.createNode( MapUtil.map( "prop", collidingPoints.other() ), TestLabels.LABEL_ONE ); inserter.createDeferredConstraint( TestLabels.LABEL_ONE ).assertPropertyIsUnique( "prop" ).create(); inserter.shutdown(); GraphDatabaseService db = graphDatabaseService( config ); try { awaitIndexesOnline( db ); try ( Transaction tx = db.beginTx() ) { assertSingleCorrectHit( db, collidingPoints.first() ); assertSingleCorrectHit( db, collidingPoints.other() ); tx.success(); } } finally { db.shutdown(); } }
@Override public ConstraintCreator createDeferredConstraint( Label label ) { return delegate.createDeferredConstraint( label ); }