-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in index suffix and contains queries with in-tx modified nodes
- Loading branch information
Showing
6 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
...el-api/src/test/java/org/neo4j/internal/kernel/api/NodeIndexTransactionStateTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "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.junit.Test; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.neo4j.collection.primitive.Primitive; | ||
import org.neo4j.collection.primitive.PrimitiveLongSet; | ||
import org.neo4j.graphdb.GraphDatabaseService; | ||
import org.neo4j.graphdb.Label; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.values.storable.Values; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
import static org.neo4j.graphdb.Label.label; | ||
|
||
public abstract class NodeIndexTransactionStateTestBase<G extends KernelAPIWriteTestSupport> | ||
extends KernelAPIWriteTestBase<G> | ||
{ | ||
@Test | ||
public void shouldPerformStringSuffixSearch() throws Exception | ||
{ | ||
// given | ||
PrimitiveLongSet expected = Primitive.longSet(); | ||
try ( Transaction tx = session.beginTransaction() ) | ||
{ | ||
expected.add( nodeWithProp( tx, "1suff" ) ); | ||
nodeWithProp( tx, "pluff" ); | ||
tx.success(); | ||
} | ||
|
||
createIndex(); | ||
|
||
// when | ||
try ( Transaction tx = session.beginTransaction() ) | ||
{ | ||
int label = tx.tokenRead().nodeLabel( "Node" ); | ||
int prop = tx.tokenRead().propertyKey( "prop" ); | ||
expected.add( nodeWithProp( tx, "2suff" ) ); | ||
nodeWithProp( tx, "skruff" ); | ||
CapableIndexReference index = tx.schemaRead().index( label, prop ); | ||
try ( NodeValueIndexCursor nodes = cursors.allocateNodeValueIndexCursor() ) | ||
{ | ||
tx.dataRead().nodeIndexSeek( index, nodes, IndexOrder.NONE, IndexQuery.stringSuffix( prop, "suff" ) ); | ||
PrimitiveLongSet found = Primitive.longSet(); | ||
while ( nodes.next() ) | ||
{ | ||
found.add( nodes.nodeReference() ); | ||
} | ||
|
||
assertThat( found, equalTo( expected ) ); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldPerformStringContainsSearch() throws Exception | ||
{ | ||
// given | ||
PrimitiveLongSet expected = Primitive.longSet(); | ||
try ( Transaction tx = session.beginTransaction() ) | ||
{ | ||
expected.add( nodeWithProp( tx, "gnomebat" ) ); | ||
nodeWithProp( tx, "fishwombat" ); | ||
tx.success(); | ||
} | ||
|
||
createIndex(); | ||
|
||
// when | ||
try ( Transaction tx = session.beginTransaction() ) | ||
{ | ||
int label = tx.tokenRead().nodeLabel( "Node" ); | ||
int prop = tx.tokenRead().propertyKey( "prop" ); | ||
expected.add( nodeWithProp( tx, "homeopatic" ) ); | ||
nodeWithProp( tx, "telephonecompany" ); | ||
CapableIndexReference index = tx.schemaRead().index( label, prop ); | ||
try ( NodeValueIndexCursor nodes = cursors.allocateNodeValueIndexCursor() ) | ||
{ | ||
tx.dataRead().nodeIndexSeek( index, nodes, IndexOrder.NONE, IndexQuery.stringContains( prop, "me" ) ); | ||
PrimitiveLongSet found = Primitive.longSet(); | ||
while ( nodes.next() ) | ||
{ | ||
found.add( nodes.nodeReference() ); | ||
} | ||
|
||
assertThat( found, equalTo( expected ) ); | ||
} | ||
} | ||
} | ||
|
||
private long nodeWithProp( Transaction tx, Object value ) throws Exception | ||
{ | ||
Write write = tx.dataWrite(); | ||
long node = write.nodeCreate(); | ||
write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) ); | ||
write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), Values.of( value ) ); | ||
return node; | ||
} | ||
|
||
private void createIndex() | ||
{ | ||
try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) | ||
{ | ||
graphDb.schema().indexFor( Label.label( "Node" ) ).on( "prop" ).create(); | ||
tx.success(); | ||
} | ||
|
||
try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) | ||
{ | ||
graphDb.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...nity/kernel/src/test/java/org/neo4j/kernel/impl/newapi/NodeIndexTransactionStateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "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.newapi; | ||
|
||
import org.neo4j.internal.kernel.api.NodeIndexTransactionStateTestBase; | ||
|
||
public class NodeIndexTransactionStateTest extends NodeIndexTransactionStateTestBase<WriteTestSupport> | ||
{ | ||
@Override | ||
public WriteTestSupport newTestSupport() | ||
{ | ||
return new WriteTestSupport(); | ||
} | ||
} |