@Test public void onlineConstraintShouldAcceptUniqueEntryChanges() { // Given givenOnlineConstraint(); // When transaction( setProperty( a, "a1" ), success ); // This is a CHANGE update // Then transaction( assertLookupNode( "a1", is( a ) ) ); }
@Test public void onlineConstraintShouldAddAndRemoveFromIndexAsPropertiesAndLabelsChange() { // Given givenOnlineConstraint(); // When transaction( setProperty( b, "b" ), success ); transaction( setProperty( c, "c" ), addLabel( c, label ), success ); transaction( setProperty( d, "d" ), addLabel( d, label ), success ); transaction( removeProperty( a ), success ); transaction( removeProperty( b ), success ); transaction( removeProperty( c ), success ); transaction( setProperty( a, "a" ), success ); transaction( setProperty( c, "c2" ), success ); // Then transaction( assertLookupNode( "a", is( a ) ), assertLookupNode( "b", is( nullValue( Node.class ) ) ), assertLookupNode( "c", is( nullValue( Node.class ) ) ), assertLookupNode( "d", is( d ) ), assertLookupNode( "c2", is( c ) ) ); }
@Test public void onlineConstraintShouldNotConflictOnIntermediateStatesInSameTransaction() { // Given givenOnlineConstraint(); // When transaction( setProperty( a, "b" ), setProperty( b, "a" ), success ); // Then transaction( assertLookupNode( "a", is( b ) ), assertLookupNode( "b", is( a ) ) ); }
@Test( expected = ConstraintViolationException.class ) public void onlineConstraintShouldRejectAddingEntryForValueAlreadyIndexedByPriorChange() { // Given givenOnlineConstraint(); // When transaction( setProperty( a, "a1" ), success ); // This is a CHANGE update // Then transaction( setProperty( b, "a1" ), success, fail( "Setting b.name = \"a1\" should have caused a conflict" ) ); }
@Test( expected = ConstraintViolationException.class ) public void onlineConstraintShouldRejectChangingEntryToAlreadyIndexedValue() { // Given givenOnlineConstraint(); transaction( setProperty( b, "b" ), success ); // When transaction( setProperty( b, "a" ), success, fail( "Changing a property to an already indexed value should have thrown" ) ); }
@Test public void onlineConstraintShouldAcceptUniqueEntries() { // Given givenOnlineConstraint(); // When transaction( setProperty( b, "b" ), addLabel( d, label ), success ); transaction( setProperty( c, "c" ), addLabel( c, label ), success ); // Then transaction( assertLookupNode( "a", is( a ) ), assertLookupNode( "b", is( b ) ), assertLookupNode( "c", is( c ) ), assertLookupNode( "d", is( d ) ) ); }
@Test( expected = ConstraintViolationException.class ) public void onlineConstraintShouldRejectConflictingLabelChange() { // Given givenOnlineConstraint(); // Then transaction( addLabel( c, label ), success, fail( "Setting c:Cybermen should have caused a conflict" ) ); }
@Test( expected = ConstraintViolationException.class ) public void onlineConstraintShouldRejectConflictingPropertyChange() { // Given givenOnlineConstraint(); // Then transaction( setProperty( b, "a" ), success, fail( "Setting b.name = \"a\" should have caused a conflict" ) ); }
@Test( expected = ConstraintViolationException.class ) public void populatingConstraintMustRejectDatasetWithDuplicateEntries() { // Given givenUniqueDataset(); transaction( setProperty( c, "b" ), // same property value as 'b' has success ); // Then this must throw: createUniqueConstraint(); }
@Test public void populatingConstraintMustAcceptDatasetWithDalseIndexCollisions() { // Given givenUniqueDataset(); transaction( setProperty( b, COLLISION_X ), setProperty( c, COLLISION_Y ), success ); // Then this does not throw: createUniqueConstraint(); }
@Test( expected = ConstraintViolationException.class ) public void onlineConstraintShouldRejectConflictsInTheSameTransaction() { // Given givenOnlineConstraint(); // Then transaction( setProperty( a, "x" ), setProperty( b, "x" ), success, fail( "Should have rejected changes of two node/properties to the same index value" ) ); }
@Test( expected = ConstraintViolationException.class ) public void onlineConstraintShouldRejectDuplicateEntriesAddedInSameTransaction() { // Given givenOnlineConstraint(); // Then transaction( setProperty( b, "d" ), addLabel( d, label ), success, fail( "Setting b.name = \"d\" and d:Cybermen should have caused a conflict" )); }
@Test public void populatingConstraintMustAcceptDatasetThatGestUpdatedWithFalseIndexCollisions() throws Exception { // Given givenUniqueDataset(); transaction( setProperty( a, COLLISION_X ), success ); // When Future<?> createConstraintTransaction = applyChangesToPopulatingUpdater( d.getId(), a.getId(), setProperty( d, COLLISION_Y ) ); // Then observe that our constraint was created successfully: createConstraintTransaction.get(); // Future.get() will throw an ExecutionException, if the Runnable threw an exception. }
@Test public void onlineConstraintShouldAcceptDistinctValuesInDifferentTransactions() { // Given givenOnlineConstraint(); // When Node n; try ( Transaction tx = db.beginTx() ) { n = db.createNode( label ); n.setProperty( property, "n" ); tx.success(); } // Then transaction( assertLookupNode( "a", is( a ) ), assertLookupNode( "n" , is( n ) ) ); }
@Test public void onlineConstraintShouldAcceptDistinctValuesInSameTransaction() { // Given givenOnlineConstraint(); // When Node n; Node m; try ( Transaction tx = db.beginTx() ) { n = db.createNode( label ); n.setProperty( property, "n" ); m = db.createNode( label ); m.setProperty( property, "m" ); tx.success(); } // Then transaction( assertLookupNode( "n", is( n ) ), assertLookupNode( "m", is( m ) ) ); }
@Test public void onlineConstraintShouldRejectChangingEntryToAlreadyIndexedValueThatOtherTransactionsAreRemoving() { // Given givenOnlineConstraint(); transaction( setProperty( b, "b" ), success ); Transaction otherTx = db.beginTx(); a.removeLabel( label ); suspend( otherTx ); // When try { transaction( setProperty( b, "a" ), success, fail( "Changing a property to an already indexed value should have thrown" ) ); } catch ( ConstraintViolationException ignore ) { // we're happy } finally { resume( otherTx ); otherTx.failure(); otherTx.close(); } }
@Test public void onlineConstraintShouldNotFalselyCollideOnFindNodesByLabelAndProperty() { // Given givenOnlineConstraint(); Node n; Node m; try ( Transaction tx = db.beginTx() ) { n = db.createNode( label ); n.setProperty( property, COLLISION_X ); tx.success(); } // When try ( Transaction tx = db.beginTx() ) { m = db.createNode( label ); m.setProperty( property, COLLISION_Y ); tx.success(); } // Then transaction( assertLookupNode( COLLISION_X, is( n ) ), assertLookupNode( COLLISION_Y, is( m ) ) ); }