From 5da4ab53b1d4b91f3010046f4130f62202b17743 Mon Sep 17 00:00:00 2001 From: fickludd Date: Wed, 11 Apr 2018 10:12:44 +0200 Subject: [PATCH] Add tests for not writing when setting properties to the existing value. --- .../kernel/api/GraphPropertiesTestBase.java | 26 +++++++++++++++- .../kernel/api/NodeWriteTestBase.java | 26 ++++++++++++++++ .../kernel/api/RelationshipWriteTestBase.java | 30 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java index 03e60576a3b4d..70ae8d8217b66 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/GraphPropertiesTestBase.java @@ -21,6 +21,8 @@ import org.junit.Test; +import org.neo4j.values.storable.Value; + import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertFalse; @@ -173,7 +175,7 @@ public void shouldSeeUpdatedGraphPropertyInTransaction() throws Exception } @Test - public void shouldNotSeeURemovedGraphPropertyInTransaction() throws Exception + public void shouldNotSeeRemovedGraphPropertyInTransaction() throws Exception { int prop; try ( Transaction tx = session.beginTransaction() ) @@ -192,4 +194,26 @@ public void shouldNotSeeURemovedGraphPropertyInTransaction() throws Exception assertFalse( cursor.next() ); } } + + @Test + public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception + { + // Given + int prop; + Value theValue = stringValue( "The Value" ); + + try ( Transaction tx = session.beginTransaction() ) + { + prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); + tx.dataWrite().graphSetProperty( prop, theValue ); + tx.success(); + } + + // When + Transaction tx = session.beginTransaction(); + assertThat( tx.dataWrite().graphSetProperty( prop, theValue ), equalTo( theValue ) ); + tx.success(); + + assertThat( tx.closeTransaction(), equalTo( Transaction.READ_ONLY ) ); + } } diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/NodeWriteTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/NodeWriteTestBase.java index d7c01331141c9..74e1386542571 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/NodeWriteTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/NodeWriteTestBase.java @@ -27,6 +27,7 @@ import org.neo4j.graphdb.NotFoundException; import org.neo4j.helpers.collection.Iterables; import org.neo4j.internal.kernel.api.exceptions.KernelException; +import org.neo4j.values.storable.Value; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -431,4 +432,29 @@ public void shouldUpdatePropertyToNodeInTransaction() throws Exception assertThat( graphDb.getNodeById( node ).getProperty( "prop" ), equalTo( 1337 ) ); } } + + @Test + public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception + { + // Given + long nodeId; + String propertyKey = "prop"; + Value theValue = stringValue( "The Value" ); + + try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) + { + Node node = graphDb.createNode(); + node.setProperty( propertyKey, theValue.asObject() ); + nodeId = node.getId(); + ctx.success(); + } + + // When + Transaction tx = session.beginTransaction(); + int property = tx.token().propertyKeyGetOrCreateForName( propertyKey ); + assertThat( tx.dataWrite().nodeSetProperty( nodeId, property, theValue ), equalTo( theValue ) ); + tx.success(); + + assertThat( tx.closeTransaction(), equalTo( Transaction.READ_ONLY ) ); + } } diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipWriteTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipWriteTestBase.java index 4e16bed972bb7..4261f8eb4b01f 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipWriteTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/RelationshipWriteTestBase.java @@ -29,6 +29,7 @@ import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.RelationshipType; import org.neo4j.helpers.collection.Iterables; +import org.neo4j.values.storable.Value; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -384,4 +385,33 @@ public void shouldUpdatePropertyToRelationshipInTransaction() throws Exception assertThat( graphDb.getRelationshipById( relationshipId ).getProperty( "prop" ), equalTo( 1337 ) ); } } + + @Test + public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception + { + // Given + long relationshipId; + String propertyKey = "prop"; + Value theValue = stringValue( "The Value" ); + + try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) + { + Node node1 = graphDb.createNode(); + Node node2 = graphDb.createNode(); + + Relationship r = node1.createRelationshipTo( node2, RelationshipType.withName( "R" ) ); + + r.setProperty( propertyKey, theValue.asObject() ); + relationshipId = r.getId(); + ctx.success(); + } + + // When + Transaction tx = session.beginTransaction(); + int property = tx.token().propertyKeyGetOrCreateForName( propertyKey ); + assertThat( tx.dataWrite().relationshipSetProperty( relationshipId, property, theValue ), equalTo( theValue ) ); + tx.success(); + + assertThat( tx.closeTransaction(), equalTo( Transaction.READ_ONLY ) ); + } }