Skip to content

Commit

Permalink
Fixups after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Nov 25, 2017
1 parent 1e2cc56 commit ff03b0f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
Expand Up @@ -21,7 +21,6 @@


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


import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;


import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
Expand Down Expand Up @@ -57,7 +56,7 @@ public void shouldRemoveNodeFromExplicitIndex() throws Exception
// Then // Then
try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() )
{ {
IndexHits<Node> hits = graphDb.index().forNodes( INDEX_NAME ).get( KEY, "this is it" ); IndexHits<Node> hits = graphDb.index().forNodes( INDEX_NAME ).get( KEY, VALUE );
assertFalse( hits.hasNext() ); assertFalse( hits.hasNext() );
hits.close(); hits.close();
ctx.success(); ctx.success();
Expand Down Expand Up @@ -88,7 +87,7 @@ public void shouldHandleRemoveNodeFromExplicitIndexTwice() throws Exception
// Then // Then
try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() )
{ {
IndexHits<Node> hits = graphDb.index().forNodes( INDEX_NAME ).get( KEY, "this is it" ); IndexHits<Node> hits = graphDb.index().forNodes( INDEX_NAME ).get( KEY, VALUE );
assertFalse( hits.hasNext() ); assertFalse( hits.hasNext() );
hits.close(); hits.close();
ctx.success(); ctx.success();
Expand Down Expand Up @@ -144,6 +143,37 @@ public void shouldCreateExplicitIndex() throws Exception
} }
} }


@Test
public void shouldCreateExplicitIndexTwice() throws Exception
{
// Given
HashMap<String,String> config = new HashMap<>();
config.put( "type", "exact" );
config.put( "provider", "lucene" );

try ( Transaction tx = session.beginTransaction() )
{
ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config );
tx.success();
}

// When
try ( Transaction tx = session.beginTransaction() )
{
ExplicitIndexWrite indexWrite = tx.indexWrite();
indexWrite.nodeExplicitIndexCreateLazily( INDEX_NAME, config );
tx.success();
}

// Then
try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() )
{
assertTrue( graphDb.index().existsForNodes( INDEX_NAME ) );
ctx.success();
}
}

private long addNodeToExplicitIndex() private long addNodeToExplicitIndex()
{ {
long nodeId; long nodeId;
Expand Down
Expand Up @@ -133,7 +133,7 @@ public void shouldAddLabelNode() throws Exception
final String labelName = "Town"; final String labelName = "Town";
try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() )
{ {
node = graphDb.createNode( label( labelName ) ).getId(); node = graphDb.createNode().getId();
ctx.success(); ctx.success();
} }


Expand Down
Expand Up @@ -159,7 +159,6 @@ public KernelTransactions( StatementLocksFactory statementLocksFactory,
this.clock = clock; this.clock = clock;
blockNewTransactions(); blockNewTransactions();
this.cursors = cursors; this.cursors = cursors;

} }


public Supplier<ExplicitIndexTransactionState> explicitIndexTxStateSupplier() public Supplier<ExplicitIndexTransactionState> explicitIndexTxStateSupplier()
Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.neo4j.internal.kernel.api.CapableIndexReference; import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.IndexOrder; import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.internal.kernel.api.IndexQuery; import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.internal.kernel.api.NodeExplicitIndexCursor;
import org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor; import org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor;
import org.neo4j.internal.kernel.api.Scan; import org.neo4j.internal.kernel.api.Scan;
import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.KernelException;
Expand Down Expand Up @@ -297,26 +296,26 @@ public final void graphProperties( org.neo4j.internal.kernel.api.PropertyCursor


@Override @Override
public final void nodeExplicitIndexLookup( public final void nodeExplicitIndexLookup(
NodeExplicitIndexCursor cursor, String index, String key, Value value ) throws KernelException org.neo4j.internal.kernel.api.NodeExplicitIndexCursor cursor, String index, String key, Value value ) throws KernelException
{ {
((org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor).setRead( this ); ((NodeExplicitIndexCursor) cursor).setRead( this );
explicitIndex( (org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).get( key, value.asObject() ) ); explicitIndex( (org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).get( key, value.asObject() ) );
} }


@Override @Override
public final void nodeExplicitIndexQuery( public final void nodeExplicitIndexQuery(
NodeExplicitIndexCursor cursor, String index, Object query ) throws KernelException org.neo4j.internal.kernel.api.NodeExplicitIndexCursor cursor, String index, Object query ) throws KernelException
{ {
((org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor).setRead( this ); ((NodeExplicitIndexCursor) cursor).setRead( this );
explicitIndex( (org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).query( explicitIndex( (org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).query(
query instanceof Value ? ((Value) query).asObject() : query ) ); query instanceof Value ? ((Value) query).asObject() : query ) );
} }


@Override @Override
public final void nodeExplicitIndexQuery( public final void nodeExplicitIndexQuery(
NodeExplicitIndexCursor cursor, String index, String key, Object query ) throws KernelException org.neo4j.internal.kernel.api.NodeExplicitIndexCursor cursor, String index, String key, Object query ) throws KernelException
{ {
((org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor).setRead( this ); ((NodeExplicitIndexCursor) cursor).setRead( this );
explicitIndex( (org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).query( explicitIndex( (org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).query(
key, query instanceof Value ? ((Value) query).asObject() : query ) ); key, query instanceof Value ? ((Value) query).asObject() : query ) );
} }
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.neo4j.internal.kernel.api.CapableIndexReference; import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.io.pagecache.PageCursor; import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.ExplicitIndex; import org.neo4j.kernel.api.ExplicitIndex;
import org.neo4j.kernel.api.txstate.TxStateHolder;
import org.neo4j.kernel.impl.store.DynamicRecordAllocator; import org.neo4j.kernel.impl.store.DynamicRecordAllocator;
import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.PropertyStore;
import org.neo4j.kernel.impl.store.RecordCursor; import org.neo4j.kernel.impl.store.RecordCursor;
Expand All @@ -45,6 +46,8 @@
import org.neo4j.values.storable.TextValue; import org.neo4j.values.storable.TextValue;
import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Value;


import static org.mockito.Mockito.mock;

public class MockStore extends Read implements TestRule public class MockStore extends Read implements TestRule
{ {
private static final DynamicRecordAllocator NO_DYNAMIC_RECORDS = new DynamicRecordAllocator() private static final DynamicRecordAllocator NO_DYNAMIC_RECORDS = new DynamicRecordAllocator()
Expand All @@ -64,7 +67,7 @@ public DynamicRecord nextRecord()


MockStore( Cursors cursors ) MockStore( Cursors cursors )
{ {
super( cursors, null );//TODO fake txstateholder? super( cursors, mock( TxStateHolder.class ) );
} }


@Override @Override
Expand Down

0 comments on commit ff03b0f

Please sign in to comment.