Skip to content

Commit

Permalink
Add tests for hasLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed May 8, 2018
1 parent ffc5e76 commit 8d5e4d9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Expand Up @@ -141,6 +141,7 @@ public void shouldReadLabels()
labels = nodes.labels();
assertEquals( "number of labels", 1, labels.numberOfLabels() );
int fooLabel = labels.label( 0 );
assertTrue( nodes.hasLabel( fooLabel ) );
assertFalse( "should only access a single node", nodes.next() );

// when
Expand All @@ -151,6 +152,8 @@ public void shouldReadLabels()
labels = nodes.labels();
assertEquals( "number of labels", 1, labels.numberOfLabels() );
int barLabel = labels.label( 0 );
assertFalse( nodes.hasLabel( fooLabel ) );
assertTrue( nodes.hasLabel( barLabel ) );
assertFalse( "should only access a single node", nodes.next() );

// when
Expand All @@ -161,6 +164,9 @@ public void shouldReadLabels()
labels = nodes.labels();
assertEquals( "number of labels", 1, labels.numberOfLabels() );
int bazLabel = labels.label( 0 );
assertFalse( nodes.hasLabel( fooLabel ) );
assertFalse( nodes.hasLabel( barLabel ) );
assertTrue( nodes.hasLabel( bazLabel ) );
assertFalse( "should only access a single node", nodes.next() );

assertNotEquals( "distinct labels", fooLabel, barLabel );
Expand All @@ -183,6 +189,10 @@ public void shouldReadLabels()
assertEquals( bazLabel, labels.label( 0 ) );
assertEquals( barLabel, labels.label( 1 ) );
}
assertFalse( nodes.hasLabel( fooLabel ) );
assertTrue( nodes.hasLabel( barLabel ) );
assertTrue( nodes.hasLabel( barLabel ) );

assertFalse( "should only access a single node", nodes.next() );

// when
Expand All @@ -192,6 +202,9 @@ public void shouldReadLabels()
assertTrue( "should access defined node", nodes.next() );
labels = nodes.labels();
assertEquals( "number of labels", 0, labels.numberOfLabels() );
assertFalse( nodes.hasLabel( fooLabel ) );
assertFalse( nodes.hasLabel( barLabel ) );
assertFalse( nodes.hasLabel( barLabel ) );
assertFalse( "should only access a single node", nodes.next() );
}
}
Expand Down
Expand Up @@ -83,6 +83,8 @@ public void shouldSeeNewLabeledNodeInTransaction() throws Exception
LabelSet labels = node.labels();
assertEquals( 1, labels.numberOfLabels() );
assertEquals( labelId, labels.label( 0 ) );
assertTrue( node.hasLabel( labelId ) );
assertFalse( node.hasLabel( labelId + 1 ) );
assertFalse( "should only find one node", node.next() );
}
tx.success();
Expand Down Expand Up @@ -139,6 +141,10 @@ public void shouldSeeLabelChangesInTransaction() throws Exception
assertTrue( "should access node", node.next() );

assertLabels( node.labels(), toRetain, toAdd );
assertTrue( node.hasLabel( toAdd ) );
assertTrue( node.hasLabel( toRetain ) );
assertFalse( node.hasLabel( toDelete ) );
assertFalse( node.hasLabel( toRegret ) );
assertFalse( "should only find one node", node.next() );
}
tx.success();
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.storageengine.api.txstate.ReadableDiffSets;

import static java.util.Collections.emptySet;

Expand Down Expand Up @@ -135,10 +136,15 @@ public boolean hasLabel( int label )
if ( hasChanges() )
{
TransactionState txState = read.txState();
if ( txState.nodeStateLabelDiffSets( getId() ).getAdded().contains( label ) )
ReadableDiffSets<Integer> diffSets = txState.nodeStateLabelDiffSets( getId() );
if ( diffSets.getAdded().contains( label ) )
{
return true;
}
if ( diffSets.getRemoved().contains( label ) )
{
return false;
}
}

//Get labels from store and put in intSet, unfortunately we get longs back
Expand All @@ -147,6 +153,7 @@ public boolean hasLabel( int label )
{
if ( labelToken == label )
{
assert (int) labelToken == labelToken : "value too big to be represented as and int";
return true;
}
}
Expand Down
Expand Up @@ -83,6 +83,7 @@ public boolean contains( int labelToken )
//label sizes (≤100 labels)
for ( long label : labels )
{
assert (int) label == label : "value too big to be represented as and int";
if ( label == labelToken )
{
return true;
Expand Down

0 comments on commit 8d5e4d9

Please sign in to comment.