Skip to content

Commit

Permalink
More randomized DropOtherLabelIndexesIT
Browse files Browse the repository at this point in the history
plus fix found for when trying to delete non-existent native lss
  • Loading branch information
tinwelint authored and burqen committed Mar 7, 2017
1 parent 2d421c3 commit ef61287
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
Expand Up @@ -292,7 +292,7 @@ public void init() throws IOException
{
// GBPTree is corrupt. Try to rebuild.
monitor.notValidIndex();
drop();
dropStrict();
instantiateTree();
needsRebuild = true;
}
Expand Down Expand Up @@ -323,6 +323,18 @@ private void instantiateTree() throws IOException

@Override
public void drop() throws IOException
{
try
{
dropStrict();
}
catch ( NoSuchFileException e )
{
// Even better, it didn't even exist
}
}

private void dropStrict() throws IOException
{
storeFileHandle().delete();
}
Expand Down
Expand Up @@ -22,6 +22,9 @@
import org.junit.Rule;
import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.ResourceIterator;
Expand All @@ -30,6 +33,7 @@
import org.neo4j.graphdb.factory.GraphDatabaseSettings.LabelIndex;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.TestLabels;
import org.neo4j.test.rule.RandomRule;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertEquals;
Expand All @@ -39,6 +43,9 @@ public class DropOtherLabelIndexesIT
{
private static final TestLabels LABEL = TestLabels.LABEL_ONE;

@Rule
public final RandomRule random = new RandomRule();

@Rule
public final TestDirectory directory = TestDirectory.testDirectory();

Expand All @@ -50,30 +57,27 @@ public class DropOtherLabelIndexesIT
public void shouldDropUnselectedLabelIndexes() throws Exception
{
// GIVEN
GraphDatabaseService db = db( LabelIndex.NATIVE );
Node nodeA = createNode( db );
assertNodes( db, nodeA );
db.shutdown();

// WHEN
db = db( LabelIndex.LUCENE );
Node nodeB = createNode( db );
assertNodes( db, nodeA, nodeB );
db.shutdown();
LabelIndex[] types = LabelIndex.values();
Set<Node> expectedNodes = new HashSet<>();
for ( int i = 0; i < 5; i++ )
{
// WHEN
GraphDatabaseService db = db( random.among( types ) );
Node node = createNode( db );
expectedNodes.add( node );

// THEN
db = db( LabelIndex.NATIVE );
Node nodeC = createNode( db );
assertNodes( db, nodeA, nodeB, nodeC );
db.shutdown();
// THEN
assertNodes( db, expectedNodes );
db.shutdown();
}
}

private void assertNodes( GraphDatabaseService db, Node... expectedNodes )
private void assertNodes( GraphDatabaseService db, Set<Node> expectedNodes )
{
try ( Transaction tx = db.beginTx();
ResourceIterator<Node> found = db.findNodes( LABEL ) )
{
assertEquals( asSet( expectedNodes ), asSet( found ) );
assertEquals( expectedNodes, asSet( found ) );
tx.success();
}
}
Expand Down

0 comments on commit ef61287

Please sign in to comment.