Skip to content

Commit

Permalink
increased assertion level in NodeValueIndexCursor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Nov 9, 2017
1 parent c2f12be commit fc4caac
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 69 deletions.
Expand Up @@ -107,7 +107,7 @@ public static StringPrefixPredicate stringPrefix( int propertyKeyId, String pref
*/ */
public static StringContainsPredicate stringContains( int propertyKeyId, String contains ) public static StringContainsPredicate stringContains( int propertyKeyId, String contains )
{ {
return new StringContainsPredicate( propertyKeyId, contains ); return new StringContainsPredicate( propertyKeyId, contains );
} }


/** /**
Expand Down
Expand Up @@ -27,9 +27,9 @@
import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.neo4j.graphdb.RelationshipType.withName; import static org.neo4j.graphdb.RelationshipType.withName;
import static org.neo4j.internal.kernel.api.IndexReadAsserts.assertFoundRelationships;
import static org.neo4j.internal.kernel.api.IndexReadAsserts.assertNodeCount;
import static org.neo4j.values.storable.Values.stringValue; import static org.neo4j.values.storable.Values.stringValue;


public abstract class ExplicitIndexCursorTestBase<G extends KernelAPIReadTestSupport> public abstract class ExplicitIndexCursorTestBase<G extends KernelAPIReadTestSupport>
Expand Down Expand Up @@ -59,13 +59,13 @@ public void shouldFindNodeByLookup() throws Exception
indexRead.nodeExplicitIndexLookup( cursor, "foo", "bar", stringValue( "this is it" ) ); indexRead.nodeExplicitIndexLookup( cursor, "foo", "bar", stringValue( "this is it" ) );


// then // then
assertFoundNodes( cursor, 1, nodes ); assertNodeCount( cursor, 1, nodes );


// when // when
indexRead.nodeExplicitIndexLookup( cursor, "foo", "bar", stringValue( "not that" ) ); indexRead.nodeExplicitIndexLookup( cursor, "foo", "bar", stringValue( "not that" ) );


// then // then
assertFoundNodes( cursor, 0, nodes ); assertNodeCount( cursor, 0, nodes );
} }
} }


Expand All @@ -80,26 +80,26 @@ public void shouldFindNodeByQuery() throws Exception
indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar:this*" ); indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar:this*" );


// then // then
assertFoundNodes( cursor, 1, nodes ); assertNodeCount( cursor, 1, nodes );


// when // when
nodes.clear(); nodes.clear();
indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar", "this*" ); indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar", "this*" );


// then // then
assertFoundNodes( cursor, 1, nodes ); assertNodeCount( cursor, 1, nodes );


// when // when
indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar:that*" ); indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar:that*" );


// then // then
assertFoundNodes( cursor, 0, nodes ); assertNodeCount( cursor, 0, nodes );


// when // when
indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar", "that*" ); indexRead.nodeExplicitIndexQuery( cursor, "foo", "bar", "that*" );


// then // then
assertFoundNodes( cursor, 0, nodes ); assertNodeCount( cursor, 0, nodes );
} }
} }


Expand Down Expand Up @@ -164,23 +164,4 @@ public void shouldFindRelationshipByQuery() throws Exception
} }
} }


static void assertFoundNodes( NodeIndexCursor node, int nodes, PrimitiveLongSet uniqueIds )
{
for ( int i = 0; i < nodes; i++ )
{
assertTrue( "at least " + nodes + " nodes", node.next() );
assertTrue( uniqueIds.add( node.nodeReference() ) );
}
assertFalse( "no more than " + nodes + " nodes", node.next() );
}

static void assertFoundRelationships( RelationshipIndexCursor edge, int edges, PrimitiveLongSet uniqueIds )
{
for ( int i = 0; i < edges; i++ )
{
assertTrue( "at least " + edges + " relationships", edge.next() );
assertTrue( uniqueIds.add( edge.relationshipReference() ) );
}
assertFalse( "no more than " + edges + " relationships", edge.next() );
}
} }
Expand Up @@ -283,6 +283,7 @@ public void testStringContains_SomeValues()


Assert.assertFalse( test( p, "dog" ) ); Assert.assertFalse( test( p, "dog" ) );
Assert.assertFalse( test( p, "cameraman" ) ); Assert.assertFalse( test( p, "cameraman" ) );
Assert.assertFalse( test( p, "Cat" ) );
Assert.assertTrue( test( p, "cat" ) ); Assert.assertTrue( test( p, "cat" ) );
Assert.assertTrue( test( p, "bobcat" ) ); Assert.assertTrue( test( p, "bobcat" ) );
Assert.assertTrue( test( p, "scatman" ) ); Assert.assertTrue( test( p, "scatman" ) );
Expand Down
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.kernel.api;

import org.neo4j.collection.primitive.PrimitiveLongSet;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class IndexReadAsserts
{
static void assertNodes( NodeIndexCursor node, PrimitiveLongSet uniqueIds, long... expected )
{
uniqueIds.clear();
for ( long count : expected )
{
assertTrue( "at least " + expected.length + " nodes", node.next() );
assertTrue( uniqueIds.add( node.nodeReference() ) );
}
assertFalse( "no more than " + expected.length + " nodes", node.next() );
assertEquals( "all nodes are unique", expected.length, uniqueIds.size() );
for ( long expectedNode : expected )
{
assertTrue( "expected node " + expectedNode, uniqueIds.contains( expectedNode ) );
}
}

static void assertNodeCount( NodeIndexCursor node, int expectedCount, PrimitiveLongSet uniqueIds )
{
uniqueIds.clear();
for ( int i = 0; i < expectedCount; i++ )
{
assertTrue( "at least " + expectedCount + " nodes", node.next() );
assertTrue( uniqueIds.add( node.nodeReference() ) );
}
assertFalse( "no more than " + expectedCount + " nodes", node.next() );
}

static void assertFoundRelationships( RelationshipIndexCursor edge, int edges, PrimitiveLongSet uniqueIds )
{
for ( int i = 0; i < edges; i++ )
{
assertTrue( "at least " + edges + " relationships", edge.next() );
assertTrue( uniqueIds.add( edge.relationshipReference() ) );
}
assertFalse( "no more than " + edges + " relationships", edge.next() );
}
}
Expand Up @@ -27,7 +27,7 @@
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;


import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.Label.label;
import static org.neo4j.internal.kernel.api.ExplicitIndexCursorTestBase.assertFoundNodes; import static org.neo4j.internal.kernel.api.IndexReadAsserts.assertNodeCount;


public abstract class NodeLabelIndexCursorTestBase<G extends KernelAPIReadTestSupport> public abstract class NodeLabelIndexCursorTestBase<G extends KernelAPIReadTestSupport>
extends KernelAPIReadTestBase<G> extends KernelAPIReadTestBase<G>
Expand Down Expand Up @@ -63,26 +63,26 @@ public void shouldFindNodesByLabel() throws Exception
read.nodeLabelScan( one, cursor ); read.nodeLabelScan( one, cursor );


// then // then
assertFoundNodes( cursor, 1, uniqueIds ); assertNodeCount( cursor, 1, uniqueIds );


// when // when
read.nodeLabelScan( two, cursor ); read.nodeLabelScan( two, cursor );


// then // then
assertFoundNodes( cursor, 2, uniqueIds ); assertNodeCount( cursor, 2, uniqueIds );


// when // when
read.nodeLabelScan( three, cursor ); read.nodeLabelScan( three, cursor );


// then // then
assertFoundNodes( cursor, 3, uniqueIds ); assertNodeCount( cursor, 3, uniqueIds );


// when // when
uniqueIds.clear(); uniqueIds.clear();
read.nodeLabelScan( first, cursor ); read.nodeLabelScan( first, cursor );


// then // then
assertFoundNodes( cursor, 3, uniqueIds ); assertNodeCount( cursor, 3, uniqueIds );
} }
} }


Expand All @@ -100,7 +100,7 @@ public void shouldFindNodesByDisjunction() throws Exception
read.nodeLabelUnionScan( cursor, first, two ); read.nodeLabelUnionScan( cursor, first, two );


// then // then
assertFoundNodes( cursor, 4, uniqueIds ); assertNodeCount( cursor, 4, uniqueIds );
} }
} }


Expand All @@ -118,7 +118,7 @@ public void shouldFindNodesByConjunction() throws Exception
read.nodeLabelIntersectionScan( cursor, first, two ); read.nodeLabelIntersectionScan( cursor, first, two );


// then // then
assertFoundNodes( cursor, 1, uniqueIds ); assertNodeCount( cursor, 1, uniqueIds );
} }
} }
} }

0 comments on commit fc4caac

Please sign in to comment.