Skip to content

Commit

Permalink
Add tests for not writing when setting properties to the existing value.
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Apr 11, 2018
1 parent a401b73 commit 5da4ab5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -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() )
Expand All @@ -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 ) );
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) );
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) );
}
}

0 comments on commit 5da4ab5

Please sign in to comment.