From 564f87012da48fdcc70dddcbedd8aacfb0806c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Finn=C3=A9?= Date: Wed, 19 Sep 2018 13:44:46 +0200 Subject: [PATCH] IndexValuesValidationTest tests specific limit for btree provider --- .../schema/IndexValuesValidationTest.java | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/community/neo4j/src/test/java/schema/IndexValuesValidationTest.java b/community/neo4j/src/test/java/schema/IndexValuesValidationTest.java index 5f16ad31ca651..cf29b6220ccd9 100644 --- a/community/neo4j/src/test/java/schema/IndexValuesValidationTest.java +++ b/community/neo4j/src/test/java/schema/IndexValuesValidationTest.java @@ -23,7 +23,6 @@ import org.apache.lucene.index.IndexWriter; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -36,15 +35,21 @@ import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.factory.GraphDatabaseFactory; +import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.schema.IndexDefinition; import org.neo4j.test.extension.Inject; import org.neo4j.test.extension.TestDirectoryExtension; import org.neo4j.test.rule.TestDirectory; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.neo4j.graphdb.factory.GraphDatabaseSettings.default_schema_provider; +import static org.neo4j.helpers.collection.MapUtil.stringMap; +import static org.neo4j.index.internal.gbptree.TreeNodeDynamicSize.keyValueSizeCapFromPageSize; +import static org.neo4j.io.pagecache.PageCache.PAGE_SIZE; @ExtendWith( TestDirectoryExtension.class ) class IndexValuesValidationTest @@ -54,10 +59,12 @@ class IndexValuesValidationTest private GraphDatabaseService database; - @BeforeEach - void setUp() + void setUp( String... settings ) { - database = new GraphDatabaseFactory().newEmbeddedDatabase( directory.storeDir() ); + database = new GraphDatabaseFactory() + .newEmbeddedDatabaseBuilder( directory.storeDir() ) + .setConfig( stringMap( settings ) ) + .newGraphDatabase(); } @AfterEach @@ -67,8 +74,9 @@ void tearDown() } @Test - void validateIndexedNodeProperties() + void validateIndexedNodePropertiesInLucene() { + setUp( default_schema_provider.name(), GraphDatabaseSettings.SchemaIndex.NATIVE10.providerIdentifier() ); Label label = Label.label( "indexedNodePropertiesTestLabel" ); String propertyName = "indexedNodePropertyName"; @@ -91,9 +99,37 @@ void validateIndexedNodeProperties() assertThat( argumentException.getMessage(), equalTo( "Property value size is too large for index. Please see index documentation for limitations." ) ); } + @Test + void validateIndexedNodePropertiesInNativeBtree() + { + setUp(); + Label label = Label.label( "indexedNodePropertiesTestLabel" ); + String propertyName = "indexedNodePropertyName"; + + createIndex( label, propertyName ); + + try ( Transaction ignored = database.beginTx() ) + { + database.schema().awaitIndexesOnline( 5, TimeUnit.MINUTES ); + } + + IllegalArgumentException argumentException = assertThrows( IllegalArgumentException.class, () -> + { + try ( Transaction transaction = database.beginTx() ) + { + Node node = database.createNode( label ); + node.setProperty( propertyName, StringUtils.repeat( "a", keyValueSizeCapFromPageSize( PAGE_SIZE ) + 1 ) ); + transaction.success(); + } + } ); + assertThat( argumentException.getMessage(), + containsString( "is too large to index into this particular index. Please see index documentation for limitations." ) ); + } + @Test void validateNodePropertiesOnPopulation() { + setUp(); Label label = Label.label( "populationTestNodeLabel" ); String propertyName = "populationTestPropertyName"; @@ -126,6 +162,7 @@ void validateNodePropertiesOnPopulation() @Test void validateExplicitIndexedNodeProperties() { + setUp(); Label label = Label.label( "explicitIndexedNodePropertiesTestLabel" ); String propertyName = "explicitIndexedNodeProperties"; String explicitIndexedNodeIndex = "explicitIndexedNodeIndex"; @@ -155,6 +192,7 @@ void validateExplicitIndexedNodeProperties() @Test void validateExplicitIndexedRelationshipProperties() { + setUp(); Label label = Label.label( "explicitIndexedRelationshipPropertiesTestLabel" ); String propertyName = "explicitIndexedRelationshipProperties"; String explicitIndexedRelationshipIndex = "explicitIndexedRelationshipIndex";