Skip to content

Commit

Permalink
Fix auto-indexing tests after stricter transactional API requirements…
Browse files Browse the repository at this point in the history
… were introduced.
  • Loading branch information
chrisvest committed Aug 9, 2018
1 parent a222a17 commit 30b0926
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
Expand Up @@ -99,13 +99,13 @@ public void stopDb()
@Test
public void testNodeAutoIndexFromAPISanity()
{
newTransaction();
AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer();
autoIndexer.startAutoIndexingProperty( "test_uuid" );
autoIndexer.setEnabled( true );
assertEquals( 1, autoIndexer.getAutoIndexedProperties().size() );
assertTrue( autoIndexer.getAutoIndexedProperties().contains(
"test_uuid" ) );
newTransaction();

Node node1 = graphDb.createNode();
node1.setProperty( "test_uuid", "node1" );
Expand All @@ -125,6 +125,7 @@ public void testNodeAutoIndexFromAPISanity()
@Test
public void testAutoIndexesReportReadOnly()
{
newTransaction();
AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer();
try ( Transaction tx = graphDb.beginTx() )
{
Expand All @@ -143,12 +144,12 @@ public void testAutoIndexesReportReadOnly()
@Test
public void testChangesAreVisibleInTransaction()
{
newTransaction();

AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer();
autoIndexer.startAutoIndexingProperty( "nodeProp" );
autoIndexer.setEnabled( true );

newTransaction();

Node node1 = graphDb.createNode();
node1.setProperty( "nodeProp", "nodePropValue" );
node1.setProperty( "nodePropNonIndexable", "valueWhatever" );
Expand Down Expand Up @@ -180,11 +181,11 @@ public void testChangesAreVisibleInTransaction()
@Test
public void testRelationshipAutoIndexFromAPISanity()
{
newTransaction();
final String propNameToIndex = "test";
AutoIndexer<Relationship> autoIndexer = graphDb.index().getRelationshipAutoIndexer();
autoIndexer.startAutoIndexingProperty( propNameToIndex );
autoIndexer.setEnabled( true );
newTransaction();

Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Expand Down Expand Up @@ -221,6 +222,7 @@ public void testConfigAndAPICompatibility()
config.put( GraphDatabaseSettings.relationship_auto_indexing.name(), "true" );
startDb();

newTransaction();
assertTrue( graphDb.index().getNodeAutoIndexer().isEnabled() );
assertTrue( graphDb.index().getRelationshipAutoIndexer().isEnabled() );

Expand Down Expand Up @@ -248,11 +250,10 @@ public void testSmallGraphWithNonIndexableProps()
config.put( GraphDatabaseSettings.relationship_auto_indexing.name(), "true" );
startDb();

newTransaction();
assertTrue( graphDb.index().getNodeAutoIndexer().isEnabled() );
assertTrue( graphDb.index().getRelationshipAutoIndexer().isEnabled() );

newTransaction();

// Build the graph, a 3-cycle
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Expand Down Expand Up @@ -356,8 +357,8 @@ public void testDefaultIsOff()
@Test
public void testDefaultIfOffIsForEverything()
{
graphDb.index().getNodeAutoIndexer().setEnabled( true );
newTransaction();
graphDb.index().getNodeAutoIndexer().setEnabled( true );
Node node1 = graphDb.createNode();
node1.setProperty( "testProp", "node1" );
node1.setProperty( "testProp1", "node1" );
Expand All @@ -384,9 +385,9 @@ public void testDefaultIsOffIfExplicit()
config.put( GraphDatabaseSettings.relationship_auto_indexing.name(), "false" );
startDb();

newTransaction();
AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer();
autoIndexer.startAutoIndexingProperty( "testProp" );
newTransaction();

Node node1 = graphDb.createNode();
node1.setProperty( "nodeProp1", "node1" );
Expand Down Expand Up @@ -441,12 +442,12 @@ public void testStartStopAutoIndexing()
// Now only node properties named propName should be indexed.
startDb();

newTransaction();
AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer();
assertTrue( autoIndexer.isEnabled() );

autoIndexer.setEnabled( false );
assertFalse( autoIndexer.isEnabled() );
newTransaction();

Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Expand All @@ -466,10 +467,10 @@ public void testStartStopAutoIndexing()
@Test
public void testStopMonitoringProperty()
{
newTransaction();
AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer();
autoIndexer.setEnabled( true );
autoIndexer.startAutoIndexingProperty( "propName" );
newTransaction();
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
node1.setProperty( "propName", "node" );
Expand Down Expand Up @@ -503,15 +504,14 @@ public void testStopMonitoringProperty()
public void testGettingAutoIndexByNameReturnsSomethingReadOnly()
{
// Create the node and relationship auto-indexes
newTransaction();
graphDb.index().getNodeAutoIndexer().setEnabled( true );
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty(
"nodeProp" );
graphDb.index().getRelationshipAutoIndexer().setEnabled( true );
graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty(
"relProp" );

newTransaction();

Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Relationship rel = node1.createRelationshipTo( node2,
Expand Down Expand Up @@ -561,11 +561,9 @@ public void testRemoveUnloadedHeavyProperty()
* Checks a bug where removing non-cached heavy properties
* would cause NPE in auto indexer.
*/
graphDb.index().getNodeAutoIndexer().setEnabled( true );
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty(
"nodeProp" );

newTransaction();
graphDb.index().getNodeAutoIndexer().setEnabled( true );
graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty( "nodeProp" );

Node node1 = graphDb.createNode();
// Large array, needed for making sure this is a heavy property
Expand All @@ -586,12 +584,11 @@ public void testRemoveUnloadedHeavyProperty()
@Test
public void testRemoveRelationshipRemovesDocument()
{
newTransaction();
AutoIndexer<Relationship> autoIndexer = graphDb.index().getRelationshipAutoIndexer();
autoIndexer.startAutoIndexingProperty( "foo" );
autoIndexer.setEnabled( true );

newTransaction();

Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Relationship rel = node1.createRelationshipTo( node2, RelationshipType.withName( "foo" ) );
Expand Down Expand Up @@ -621,12 +618,11 @@ public void testRemoveRelationshipRemovesDocument()
@Test
public void testDeletingNodeRemovesItFromAutoIndex()
{
newTransaction();
AutoIndexer<Node> nodeAutoIndexer = graphDb.index().getNodeAutoIndexer();
nodeAutoIndexer.startAutoIndexingProperty( "foo" );
nodeAutoIndexer.setEnabled( true );

newTransaction();

Node node1 = graphDb.createNode();
node1.setProperty( "foo", "bar" );

Expand Down Expand Up @@ -655,11 +651,11 @@ public void shouldOnlyDeleteAffectedKeyWhenRemovingPropertyFromNode()
String key2 = "bar";
String value1 = "bip";
String value2 = "bop";
newTransaction();
AutoIndexer<Node> nodeAutoIndexer = graphDb.index().getNodeAutoIndexer();
nodeAutoIndexer.startAutoIndexingProperty( key1 );
nodeAutoIndexer.startAutoIndexingProperty( key2 );
nodeAutoIndexer.setEnabled( true );
newTransaction();
Node node = graphDb.createNode();
node.setProperty( key1, value1 );
node.setProperty( key2, value2 );
Expand Down
Expand Up @@ -21,6 +21,7 @@

import java.util.Iterator;

import org.junit.Before;
import org.junit.Test;

import org.neo4j.graphdb.Entity;
Expand All @@ -34,14 +35,23 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

public class PathProxyTest
{
private EmbeddedProxySPI proxySPI;

@Before
public void setUp() throws Exception
{
proxySPI = mock( EmbeddedProxySPI.class );
}

@Test
public void shouldIterateThroughNodes()
{
// given
Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );

Iterator<Node> iterator = path.nodes().iterator();
Node node;
Expand All @@ -63,7 +73,7 @@ public void shouldIterateThroughNodes()
public void shouldIterateThroughNodesInReverse()
{
// given
Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );

Iterator<Node> iterator = path.reverseNodes().iterator();
Node node;
Expand All @@ -85,7 +95,7 @@ public void shouldIterateThroughNodesInReverse()
public void shouldIterateThroughRelationships()
{
// given
Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );

Iterator<Relationship> iterator = path.relationships().iterator();
Relationship relationship;
Expand All @@ -108,7 +118,7 @@ public void shouldIterateThroughRelationships()
public void shouldIterateThroughRelationshipsInReverse()
{
// given
Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );

Iterator<Relationship> iterator = path.reverseRelationships().iterator();
Relationship relationship;
Expand All @@ -131,7 +141,7 @@ public void shouldIterateThroughRelationshipsInReverse()
public void shouldIterateAlternatingNodesAndRelationships()
{
// given
Path path = new PathProxy( null, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );

Iterator<PropertyContainer> iterator = path.iterator();
PropertyContainer entity;
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.graphdb.ResourceIterable;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.server.rest.domain.JsonHelper;
import org.neo4j.server.rest.domain.JsonParseException;
import org.neo4j.server.rest.web.RestfulGraphDatabase;
Expand Down Expand Up @@ -305,7 +306,12 @@ public void listAutoIndexingPropertiesForNodes() throws JsonParseException
int initialPropertiesSize = getAutoIndexedPropertiesForType( "node" ).size();

String propName = "some-property" + System.currentTimeMillis();
server().getDatabase().getGraph().index().getNodeAutoIndexer().startAutoIndexingProperty( propName );
GraphDatabaseFacade db = server().getDatabase().getGraph();
try ( Transaction tx = db.beginTx() )
{
db.index().getNodeAutoIndexer().startAutoIndexingProperty( propName );
tx.success();
}

List<String> properties = getAutoIndexedPropertiesForType( "node" );

Expand Down

0 comments on commit 30b0926

Please sign in to comment.