@Test public void droppingExistingIndexRuleShouldSucceed() { // GIVEN IndexDefinition index = createIndex( db, label, propertyKey ); // WHEN dropIndex( index ); // THEN assertThat( getIndexes( db, label ), isEmpty() ); }
@Test public void shouldDropUniquenessConstraint() { // GIVEN ConstraintDefinition constraint = createUniquenessConstraint( label, propertyKey ); // WHEN dropConstraint( db, constraint ); // THEN assertThat( getConstraints( db, label ), isEmpty() ); }
@Test public void searchingByLabelAndPropertyReturnsEmptyWhenMissingLabelOrProperty() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); // When/Then assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), isEmpty() ); }
@Test public void shouldIndexArraysPostPopulation() { long[] arrayPropertyValue = {42, 23, 87}; Node node1; try ( Transaction tx = db.beginTx() ) { node1 = createNode( label, propertyKey, arrayPropertyValue ); tx.success(); } createIndex( db, label, propertyKey ); restart(); assertThat( getIndexes( db, label ), inTx( db, haveState( db, IndexState.ONLINE ) ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, arrayPropertyValue, db ), containsOnly( node1 ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, new long[]{42, 23}, db ), isEmpty() ); assertThat( findNodesByLabelAndProperty( label, propertyKey, Arrays.toString( arrayPropertyValue ), db ), isEmpty() ); }
@Test public void shouldIndexArrays() { long[] arrayPropertyValue = {42, 23, 87}; createIndex( db, label, propertyKey ); Node node1; try ( Transaction tx = db.beginTx() ) { node1 = createNode( label, propertyKey, arrayPropertyValue ); tx.success(); } restart(); assertThat( getIndexes( db, label ), inTx( db, haveState( db, IndexState.ONLINE ) )); assertThat( findNodesByLabelAndProperty( label, propertyKey, arrayPropertyValue, db ), containsOnly( node1 ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, new long[]{42, 23}, db ), isEmpty() ); assertThat( findNodesByLabelAndProperty( label, propertyKey, Arrays.toString( arrayPropertyValue ), db ), isEmpty() ); }
@Test public void shouldIndexStringArrays() { String[] arrayPropertyValue = {"A, B", "C"}; createIndex( db, label, propertyKey ); Node node1; try ( Transaction tx = db.beginTx() ) { node1 = createNode( label, propertyKey, arrayPropertyValue ); tx.success(); } restart(); assertThat( getIndexes( db, label ), inTx( db, haveState( db, IndexState.ONLINE ) ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, arrayPropertyValue, db ), containsOnly( node1 ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, new String[]{"A", "B, C"}, db ), isEmpty() ); assertThat( findNodesByLabelAndProperty( label, propertyKey, Arrays.toString( arrayPropertyValue ), db ), isEmpty() ); }
assertThat( labels( myNode ), containsOnly( LABEL2, LABEL3 ) ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Feynman", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Feynman", beansAPI ), containsOnly( myNode ) ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Feynman", beansAPI ), containsOnly( myNode ) );
@Test public void recoveryAfterCreateAndDropIndex() throws Exception { // GIVEN IndexDefinition indexDefinition = createIndex( db, label, propertyKey ); createSomeData( label, propertyKey ); doStuff( db, label, propertyKey ); dropIndex( indexDefinition ); doStuff( db, label, propertyKey ); // WHEN crashAndRestart(); // THEN assertThat( getIndexes( db, label ), isEmpty() ); }
@Test public void shouldCorrectlyUpdateIndexesWhenChangingLabelsAndPropertyAtTheSameTime() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Node myNode = createNode( beansAPI, map( "name", "Hawking" ), LABEL1, LABEL2 ); Neo4jMatchers.createIndex( beansAPI, LABEL1, "name" ); Neo4jMatchers.createIndex( beansAPI, LABEL2, "name" ); Neo4jMatchers.createIndex( beansAPI, LABEL3, "name" ); // When try ( Transaction tx = beansAPI.beginTx() ) { myNode.removeLabel( LABEL1 ); myNode.addLabel( LABEL3 ); myNode.setProperty( "name", "Einstein" ); tx.success(); } // Then assertThat( myNode, inTx( beansAPI, hasProperty("name").withValue( "Einstein" ) ) ); assertThat( labels( myNode ), containsOnly( LABEL2, LABEL3 ) ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL1, "name", "Einstein", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL2, "name", "Einstein", beansAPI ), containsOnly( myNode ) ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Hawking", beansAPI ), isEmpty() ); assertThat( findNodesByLabelAndProperty( LABEL3, "name", "Einstein", beansAPI ), containsOnly( myNode ) ); }
@Documented( "Drop uniqueness constraint.\n" + "Drop uniqueness constraint for a label and a property." ) @Test @GraphDescription.Graph( nodes = {} ) public void drop_constraint() { data.get(); String labelName = labels.newInstance(); String propertyKey = properties.newInstance(); ConstraintDefinition constraintDefinition = createLabelUniquenessPropertyConstraint( labelName, propertyKey ); assertThat( getConstraints( graphdb(), label( labelName ) ), containsOnly( constraintDefinition ) ); gen.get().expectedStatus( 204 ).delete( getSchemaConstraintLabelUniquenessPropertyUri( labelName, propertyKey ) ).entity(); assertThat( getConstraints( graphdb(), label( labelName ) ), isEmpty() ); }
assertThat( findNodesByLabelAndProperty( LABEL1, "key", smallValue, beansAPI ), isEmpty() );