Skip to content

Commit

Permalink
NativeLabelScanStoreUpdateIT (part of lss compliance testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Jan 22, 2017
1 parent f5caecd commit 5b3656b
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 21 deletions.
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.graphdb;

import org.junit.Before;
import org.junit.ClassRule;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -31,10 +30,6 @@

import org.neo4j.helpers.collection.Iterables;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.ImpermanentDatabaseRule;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
Expand All @@ -43,11 +38,8 @@
import static org.neo4j.helpers.collection.Iterators.emptySetOf;
import static org.neo4j.helpers.collection.Iterators.single;

public class LabelScanStoreUpdateIT
public abstract class LabelScanStoreUpdateIT
{
@ClassRule
public static final DatabaseRule dbRule = new ImpermanentDatabaseRule();

@Rule
public final TestName testName = new TestName();

Expand Down Expand Up @@ -178,7 +170,7 @@ public void retrieveNodeIdsInAscendingOrder()
public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exception
{
// Given
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
GraphDatabaseService db = db();
int labelsToAdd = 80;
int labelsToRemove = 40;

Expand Down Expand Up @@ -216,11 +208,13 @@ public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exce
}
}

protected abstract GraphDatabaseService db();

private void verifyFoundNodes( Label label, String sizeMismatchMessage, long... expectedNodeIds )
{
try ( Transaction ignored = dbRule.getGraphDatabaseAPI().beginTx() )
try ( Transaction ignored = db().beginTx() )
{
ResourceIterator<Node> nodes = dbRule.getGraphDatabaseAPI().findNodes( label );
ResourceIterator<Node> nodes = db().findNodes( label );
List<Node> nodeList = Iterators.asList( nodes );
assertThat( sizeMismatchMessage, nodeList, Matchers.hasSize( expectedNodeIds.length ) );
int index = 0;
Expand All @@ -233,7 +227,7 @@ private void verifyFoundNodes( Label label, String sizeMismatchMessage, long...

private void removeLabels( Node node, Label... labels )
{
try ( Transaction tx = dbRule.getGraphDatabaseAPI().beginTx() )
try ( Transaction tx = db().beginTx() )
{
for ( Label label : labels )
{
Expand All @@ -245,7 +239,7 @@ private void removeLabels( Node node, Label... labels )

private void deleteNode( Node node )
{
try ( Transaction tx = dbRule.getGraphDatabaseAPI().beginTx() )
try ( Transaction tx = db().beginTx() )
{
node.delete();
tx.success();
Expand All @@ -254,25 +248,25 @@ private void deleteNode( Node node )

private Set<Node> getAllNodesWithLabel( Label label )
{
try ( Transaction tx = dbRule.getGraphDatabaseAPI().beginTx() )
try ( Transaction tx = db().beginTx() )
{
return asSet( dbRule.getGraphDatabaseAPI().findNodes( label ) );
return asSet( db().findNodes( label ) );
}
}

private Node createLabeledNode( Label... labels )
{
try ( Transaction tx = dbRule.getGraphDatabaseAPI().beginTx() )
try ( Transaction tx = db().beginTx() )
{
Node node = dbRule.getGraphDatabaseAPI().createNode( labels );
Node node = db().createNode( labels );
tx.success();
return node;
}
}

private void addLabels( Node node, Label... labels )
{
try ( Transaction tx = dbRule.getGraphDatabaseAPI().beginTx() )
try ( Transaction tx = db().beginTx() )
{
for ( Label label : labels )
{
Expand All @@ -284,9 +278,9 @@ private void addLabels( Node node, Label... labels )

private Node getNodeById(long id)
{
try (Transaction ignored = dbRule.beginTx())
try (Transaction ignored = db().beginTx())
{
return dbRule.getNodeById( id );
return db().getNodeById( id );
}
}

Expand Down
@@ -0,0 +1,50 @@
/*
* 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.kernel.impl.index.labelscan;

import org.junit.ClassRule;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.LabelScanStoreUpdateIT;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.kernel.impl.api.scan.NativeLabelScanStoreExtension;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.ImpermanentDatabaseRule;

import static org.neo4j.graphdb.factory.GraphDatabaseSettings.label_scan_store;

public class NativeLabelScanStoreUpdateIT extends LabelScanStoreUpdateIT
{
@ClassRule
public static final DatabaseRule dbRule = new ImpermanentDatabaseRule()
{
@Override
protected void configure( GraphDatabaseBuilder builder )
{
builder.setConfig( label_scan_store, NativeLabelScanStoreExtension.LABEL_SCAN_STORE_NAME );
}
};

@Override
protected GraphDatabaseService db()
{
return dbRule;
}
}
@@ -0,0 +1,48 @@
/*
* 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.graphdb;

import org.junit.ClassRule;

import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.kernel.api.impl.labelscan.LuceneLabelScanStoreExtension;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.ImpermanentDatabaseRule;

import static org.neo4j.graphdb.factory.GraphDatabaseSettings.label_scan_store;

public class LuceneLabelScanStoreUpdateIT extends LabelScanStoreUpdateIT
{
@ClassRule
public static final DatabaseRule dbRule = new ImpermanentDatabaseRule()
{
@Override
protected void configure( GraphDatabaseBuilder builder )
{
builder.setConfig( label_scan_store, LuceneLabelScanStoreExtension.LABEL_SCAN_STORE_NAME );
}
};

@Override
protected GraphDatabaseService db()
{
return dbRule;
}
}

0 comments on commit 5b3656b

Please sign in to comment.