From 96ca2f820a26a03dee7a58a045a00a29024c87b7 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 18 Dec 2018 12:54:23 +0100 Subject: [PATCH] Avoid changing the `db.awaitIndex` and `db.resampleIndex` behaviours, and instead add a new `db.index.fulltext.awaitIndex` procedure for awaiting indexes by name. The reason for this is that fears were expressed about the change to the `db.awaitIndex` procedure being an incompatible change. --- .../impl/fulltext/FulltextProceduresTest.java | 2 +- .../integrationtest/BuiltInProceduresIT.java | 9 +-- .../api/impl/fulltext/FulltextProcedures.java | 23 +++++++ .../builtinprocs/BuiltInProcedures.java | 6 +- .../kernel/builtinprocs/IndexProcedures.java | 15 +++-- .../kernel/builtinprocs/IndexSpecifier.java | 21 +++++-- .../builtinprocs/AwaitIndexProcedureTest.java | 24 +++++--- .../builtinprocs/BuiltInProceduresTest.java | 6 +- .../builtinprocs/IndexSpecifierTest.java | 60 ++++++++++++------- 9 files changed, 114 insertions(+), 52 deletions(-) diff --git a/community/community-it/index-it/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextProceduresTest.java b/community/community-it/index-it/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextProceduresTest.java index a89fed184730..2ffe754670c7 100644 --- a/community/community-it/index-it/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextProceduresTest.java +++ b/community/community-it/index-it/src/test/java/org/neo4j/kernel/api/impl/fulltext/FulltextProceduresTest.java @@ -100,7 +100,7 @@ public class FulltextProceduresTest private static final String DB_INDEXES = "CALL db.indexes"; private static final String DROP = "CALL db.index.fulltext.drop(\"%s\")"; private static final String LIST_AVAILABLE_ANALYZERS = "CALL db.index.fulltext.listAvailableAnalyzers()"; - private static final String DB_AWAIT_INDEX = "CALL db.awaitIndex(\"%s\")"; + private static final String DB_AWAIT_INDEX = "CALL db.index.fulltext.awaitIndex(\"%s\")"; static final String QUERY_NODES = "CALL db.index.fulltext.queryNodes(\"%s\", \"%s\")"; static final String QUERY_RELS = "CALL db.index.fulltext.queryRelationships(\"%s\", \"%s\")"; static final String AWAIT_REFRESH = "CALL db.index.fulltext.awaitEventuallyConsistentIndexRefresh()"; diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java index 0129623987cc..9899d11a992c 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/impl/api/integrationtest/BuiltInProceduresIT.java @@ -137,13 +137,11 @@ public void listProcedures() throws Throwable "failureMessage :: STRING?)", "List all indexes in the database.", "READ" ), proc( "db.awaitIndex", "(index :: STRING?, timeOutSeconds = 300 :: INTEGER?) :: VOID", - "Wait for an index to come online (for example: CALL db.awaitIndex(\":Person(name)\"), " + - "or CALL db.awaitIndex(\"index_name\")).", "READ" ), + "Wait for an index to come online (for example: CALL db.awaitIndex(\":Person(name)\")).", "READ" ), proc( "db.awaitIndexes", "(timeOutSeconds = 300 :: INTEGER?) :: VOID", "Wait for all indexes to come online (for example: CALL db.awaitIndexes(\"500\")).", "READ" ), proc( "db.resampleIndex", "(index :: STRING?) :: VOID", - "Schedule resampling of an index (for example: CALL db.resampleIndex(\":Person(name)\"), " + - "or CALL db.resampleIndex(\"index_name\")).", "READ" ), + "Schedule resampling of an index (for example: CALL db.resampleIndex(\":Person(name)\")).", "READ" ), proc( "db.resampleOutdatedIndexes", "() :: VOID", "Schedule resampling of all outdated indexes.", "READ" ), proc( "db.propertyKeys", "() :: (propertyKey :: STRING?)", "List all property keys in the database.", "READ" ), proc( "db.labels", "() :: (label :: STRING?)", "List all labels in the database.", "READ" ), @@ -229,6 +227,9 @@ public void listProcedures() throws Throwable "YIELD index, providerName, status", "SCHEMA" ), proc( "db.index.fulltext.awaitEventuallyConsistentIndexRefresh", "() :: VOID", "Wait for the updates from recently committed transactions to be applied to any eventually-consistent fulltext indexes.", "READ" ), + proc( "db.index.fulltext.awaitIndex", "(index :: STRING?, timeOutSeconds = 300 :: INTEGER?) :: VOID", + "Similar to db.awaitIndex(index, timeout), except instead of an index pattern, the index is specified by name. " + + "The name can be quoted by backticks, if necessary.", "READ" ), proc( "db.index.fulltext.createNodeIndex", "(indexName :: STRING?, labels :: LIST? OF STRING?, propertyNames :: LIST? OF STRING?, " + "config = {} :: MAP?) :: VOID", startsWith( "Create a node fulltext index for the given labels and properties." ), "SCHEMA" ), proc( "db.index.fulltext.createRelationshipIndex", diff --git a/community/fulltext-index/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProcedures.java b/community/fulltext-index/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProcedures.java index 197cdd8fa98c..03b0ede842ce 100644 --- a/community/fulltext-index/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProcedures.java +++ b/community/fulltext-index/src/main/java/org/neo4j/kernel/api/impl/fulltext/FulltextProcedures.java @@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Stream; +import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.NotFoundException; @@ -39,11 +40,14 @@ import org.neo4j.graphdb.schema.Schema; import org.neo4j.internal.kernel.api.IndexReference; import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException; +import org.neo4j.internal.kernel.api.exceptions.ProcedureException; import org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException; import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.schema.SchemaDescriptor; import org.neo4j.kernel.api.KernelTransaction; +import org.neo4j.kernel.builtinprocs.IndexProcedures; import org.neo4j.kernel.impl.api.KernelTransactionImplementation; +import org.neo4j.kernel.impl.api.index.IndexingService; import org.neo4j.procedure.Context; import org.neo4j.procedure.Description; import org.neo4j.procedure.Name; @@ -73,6 +77,9 @@ public class FulltextProcedures @Context public GraphDatabaseService db; + @Context + public DependencyResolver resolver; + @Context public FulltextAdapter accessor; @@ -90,6 +97,22 @@ public void awaitRefresh() accessor.awaitRefresh(); } + @Description( "Similar to db.awaitIndex(index, timeout), except instead of an index pattern, the index is specified by name. " + + "The name can be quoted by backticks, if necessary." ) + @Procedure( name = "db.index.fulltext.awaitIndex", mode = READ ) + public void awaitIndex( @Name( "index" ) String index, @Name( value = "timeOutSeconds", defaultValue = "300" ) long timeout ) throws ProcedureException + { + try ( IndexProcedures indexProcedures = indexProcedures() ) + { + indexProcedures.awaitIndexByName( index, timeout, TimeUnit.SECONDS ); + } + } + + private IndexProcedures indexProcedures() + { + return new IndexProcedures( tx, resolver.resolveDependency( IndexingService.class ) ); + } + @Description( "Create a node fulltext index for the given labels and properties. " + "The optional 'config' map parameter can be used to supply settings to the index. " + "Note: index specific settings are currently experimental, and might not replicated correctly in a cluster, or during backup. " + diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java index fc6c1dc5cd52..4ac5de82e8a9 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/BuiltInProcedures.java @@ -169,7 +169,7 @@ public Stream listIndexes() throws ProcedureException } } - @Description( "Wait for an index to come online (for example: CALL db.awaitIndex(\":Person(name)\"), or CALL db.awaitIndex(\"index_name\"))." ) + @Description( "Wait for an index to come online (for example: CALL db.awaitIndex(\":Person(name)\"))." ) @Procedure( name = "db.awaitIndex", mode = READ ) public void awaitIndex( @Name( "index" ) String index, @Name( value = "timeOutSeconds", defaultValue = "300" ) long timeout ) @@ -177,7 +177,7 @@ public void awaitIndex( @Name( "index" ) String index, { try ( IndexProcedures indexProcedures = indexProcedures() ) { - indexProcedures.awaitIndex( index, timeout, TimeUnit.SECONDS ); + indexProcedures.awaitIndexByPattern( index, timeout, TimeUnit.SECONDS ); } } @@ -188,7 +188,7 @@ public void awaitIndexes( @Name( value = "timeOutSeconds", defaultValue = "300" graphDatabaseAPI.schema().awaitIndexesOnline( timeout, TimeUnit.SECONDS ); } - @Description( "Schedule resampling of an index (for example: CALL db.resampleIndex(\":Person(name)\"), or CALL db.resampleIndex(\"index_name\"))." ) + @Description( "Schedule resampling of an index (for example: CALL db.resampleIndex(\":Person(name)\"))." ) @Procedure( name = "db.resampleIndex", mode = READ ) public void resampleIndex( @Name( "index" ) String index ) throws ProcedureException { diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java index e4787269ca87..60fe8714fd68 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexProcedures.java @@ -57,16 +57,23 @@ public IndexProcedures( KernelTransaction tx, IndexingService indexingService ) this.indexingService = indexingService; } - public void awaitIndex( String indexSpecification, long timeout, TimeUnit timeoutUnits ) + public void awaitIndexByPattern( String indexPattern, long timeout, TimeUnit timeoutUnits ) throws ProcedureException { - IndexSpecifier specifier = IndexSpecifier.patternOrName( indexSpecification ); + IndexSpecifier specifier = IndexSpecifier.byPattern( indexPattern ); + waitUntilOnline( getIndex( specifier ), specifier, timeout, timeoutUnits ); + } + + public void awaitIndexByName( String indexName, long timeout, TimeUnit timeoutUnits ) + throws ProcedureException + { + IndexSpecifier specifier = IndexSpecifier.byName( indexName ); waitUntilOnline( getIndex( specifier ), specifier, timeout, timeoutUnits ); } public void resampleIndex( String indexSpecification ) throws ProcedureException { - IndexSpecifier specifier = IndexSpecifier.patternOrName( indexSpecification ); + IndexSpecifier specifier = IndexSpecifier.byPattern( indexSpecification ); try { triggerSampling( getIndex( specifier ) ); @@ -102,7 +109,7 @@ private Stream createIndex( String indexSpeci IndexCreator indexCreator ) throws ProcedureException { assertProviderNameNotNull( providerName ); - IndexSpecifier index = IndexSpecifier.pattern( indexSpecification ); + IndexSpecifier index = IndexSpecifier.byPattern( indexSpecification ); int labelId = getOrCreateLabelId( index.label() ); int[] propertyKeyIds = getOrCreatePropertyIds( index.properties() ); try diff --git a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexSpecifier.java b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexSpecifier.java index 5548f88c0d78..24451e1f5161 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexSpecifier.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/builtinprocs/IndexSpecifier.java @@ -59,17 +59,22 @@ public class IndexSpecifier private final String[] properties; private final String name; - public static IndexSpecifier patternOrName( String specification ) + public static IndexSpecifier byPatternOrName( String specification ) { - return parse( specification, true ); + return parse( specification, true, true ); } - public static IndexSpecifier pattern( String specification ) + public static IndexSpecifier byPattern( String specification ) { - return parse( specification, false ); + return parse( specification, false, true ); } - private static IndexSpecifier parse( String specification, boolean allowIndexNameSpecs ) + public static IndexSpecifier byName( String specification ) + { + return parse( specification, true, false ); + } + + private static IndexSpecifier parse( String specification, boolean allowIndexNameSpecs, boolean allowIndexPatternSpecs ) { Matcher matcher = PATTERN_START_INDEX_NAME_OR_LABEL.matcher( specification ); if ( !matcher.find() ) @@ -93,6 +98,12 @@ private static IndexSpecifier parse( String specification, boolean allowIndexNam throw new IllegalArgumentException( "Invalid characters following index name: '" + specification + "'" ); } + if ( !allowIndexPatternSpecs ) + { + throw new IllegalArgumentException( "Cannot parse index specification: '" + specification + + "' - it looks like an index pattern, but an index name was expected." ); + } + String label = either( matcher.group( GROUP_LABEL ), matcher.group( GROUP_QUOTED_LABEL ) ); if ( label == null ) { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java index 4c32d4d6a77f..6830c60ebc92 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/AwaitIndexProcedureTest.java @@ -89,7 +89,7 @@ public void shouldThrowAnExceptionIfTheLabelDoesntExist() try { - procedure.awaitIndex( ":NonExistentLabel(prop)", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByPattern( ":NonExistentLabel(prop)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) @@ -105,7 +105,7 @@ public void shouldThrowAnExceptionIfThePropertyKeyDoesntExist() try { - procedure.awaitIndex( ":Label(nonExistentProperty)", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByPattern( ":Label(nonExistentProperty)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) @@ -122,7 +122,7 @@ public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws ProcedureExce when( schemaRead.index( anyInt(), any() ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( ONLINE ); - procedure.awaitIndex( ":Person(name)", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); verify( schemaRead ).index( descriptor.getLabelId(), descriptor.getPropertyId() ); } @@ -135,7 +135,7 @@ public void shouldLookUpTheIndexByIndexName() throws ProcedureException, IndexNo when( schemaRead.indexGetForName( "my index" ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( ONLINE ); - procedure.awaitIndex( "`my index`", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByName( "`my index`", TIMEOUT, TIME_UNIT ); verify( schemaRead ).indexGetForName( "my index" ); } @@ -151,7 +151,7 @@ public void shouldThrowAnExceptionIfTheIndexHasFailed() throws IndexNotFoundKern try { - procedure.awaitIndex( ":Person(name)", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) @@ -170,7 +170,7 @@ public void shouldThrowAnExceptionIfTheIndexDoesNotExist() try { - procedure.awaitIndex( ":Person(name)", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) @@ -179,6 +179,12 @@ public void shouldThrowAnExceptionIfTheIndexDoesNotExist() } } + @Test( expected = IllegalArgumentException.class ) + public void shouldThrowAnExceptionIfGivenAnIndexName() throws ProcedureException + { + procedure.awaitIndexByPattern( "`some index`", TIMEOUT, TIME_UNIT ); + } + @Test public void shouldThrowAnExceptionIfTheIndexWithGivenNameDoesNotExist() { @@ -188,7 +194,7 @@ public void shouldThrowAnExceptionIfTheIndexWithGivenNameDoesNotExist() try { - procedure.awaitIndex( "`some index`", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByName( "`some index`", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) @@ -212,7 +218,7 @@ public void shouldBlockUntilTheIndexIsOnline() throws IndexNotFoundKernelExcepti { try { - procedure.awaitIndex( ":Person(name)", TIMEOUT, TIME_UNIT ); + procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); } catch ( ProcedureException e ) { @@ -242,7 +248,7 @@ public void shouldTimeoutIfTheIndexTakesTooLongToComeOnline() throws Interrupted try { // We wait here, because we expect timeout - procedure.awaitIndex( ":Person(name)", 0, TIME_UNIT ); + procedure.awaitIndexByPattern( ":Person(name)", 0, TIME_UNIT ); } catch ( ProcedureException e ) { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java index e017926ed33f..4af598a39185 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/BuiltInProceduresTest.java @@ -265,8 +265,7 @@ public void shouldListCorrectBuiltinProcedures() throws Throwable "dbms.listConfig(searchString = :: STRING?) :: (name :: STRING?, description :: STRING?, value :: STRING?, dynamic :: BOOLEAN?)", "List the currently active config of Neo4j.", "DBMS" ), record( "db.awaitIndex", "db.awaitIndex(index :: STRING?, timeOutSeconds = 300 :: INTEGER?) :: VOID", - "Wait for an index to come online (for example: CALL db.awaitIndex(\":Person(name)\"), " + - "or CALL db.awaitIndex(\"index_name\")).", "READ" ), + "Wait for an index to come online (for example: CALL db.awaitIndex(\":Person(name)\")).", "READ" ), record( "db.awaitIndexes", "db.awaitIndexes(timeOutSeconds = 300 :: INTEGER?) :: VOID", "Wait for all indexes to come online (for example: CALL db.awaitIndexes(\"500\")).", "READ" ), record( "db.constraints", "db.constraints() :: (description :: STRING?)", @@ -281,8 +280,7 @@ public void shouldListCorrectBuiltinProcedures() throws Throwable record( "db.relationshipTypes", "db.relationshipTypes() :: (relationshipType :: STRING?)", "List all relationship types in the database.", "READ" ), record( "db.resampleIndex", "db.resampleIndex(index :: STRING?) :: VOID", - "Schedule resampling of an index (for example: CALL db.resampleIndex(\":Person(name)\"), " + - "or CALL db.resampleIndex(\"index_name\")).", "READ" ), + "Schedule resampling of an index (for example: CALL db.resampleIndex(\":Person(name)\")).", "READ" ), record( "db.resampleOutdatedIndexes", "db.resampleOutdatedIndexes() :: VOID", "Schedule resampling of all outdated indexes.", "READ" ), record( "db.schema", diff --git a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/IndexSpecifierTest.java b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/IndexSpecifierTest.java index ab508639b523..a1be2f5eae4e 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/IndexSpecifierTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/builtinprocs/IndexSpecifierTest.java @@ -33,39 +33,39 @@ public class IndexSpecifierTest @Test public void shouldFormatAsCanonicalRepresentation() { - assertThat( IndexSpecifier.patternOrName( ":Person(name)" ).toString(), is( ":Person(name)" ) ); - assertThat( IndexSpecifier.pattern( ":Person(name)" ).toString(), is( ":Person(name)" ) ); + assertThat( IndexSpecifier.byPatternOrName( ":Person(name)" ).toString(), is( ":Person(name)" ) ); + assertThat( IndexSpecifier.byPattern( ":Person(name)" ).toString(), is( ":Person(name)" ) ); } @Test public void shouldParseASimpleLabel() { - assertThat( IndexSpecifier.patternOrName( ":Person_23(name)" ).label(), is( "Person_23" ) ); - assertThat( IndexSpecifier.pattern( ":Person_23(name)" ).label(), is( "Person_23" ) ); + assertThat( IndexSpecifier.byPatternOrName( ":Person_23(name)" ).label(), is( "Person_23" ) ); + assertThat( IndexSpecifier.byPattern( ":Person_23(name)" ).label(), is( "Person_23" ) ); } @Test public void shouldParseASimpleProperty() { - assertThat( IndexSpecifier.patternOrName( ":Person(a_Name_123)" ).properties(), is( arrayContaining( "a_Name_123" ) ) ); - assertThat( IndexSpecifier.pattern( ":Person(a_Name_123)" ).properties(), is( arrayContaining( "a_Name_123" ) ) ); + assertThat( IndexSpecifier.byPatternOrName( ":Person(a_Name_123)" ).properties(), is( arrayContaining( "a_Name_123" ) ) ); + assertThat( IndexSpecifier.byPattern( ":Person(a_Name_123)" ).properties(), is( arrayContaining( "a_Name_123" ) ) ); } @Test public void shouldParseTwoProperties() { - assertThat( IndexSpecifier.patternOrName( ":Person(name, lastName)" ).properties(), + assertThat( IndexSpecifier.byPatternOrName( ":Person(name, lastName)" ).properties(), is( arrayContaining( "name", "lastName" ) ) ); - assertThat( IndexSpecifier.pattern( ":Person(name, lastName)" ).properties(), + assertThat( IndexSpecifier.byPattern( ":Person(name, lastName)" ).properties(), is( arrayContaining( "name", "lastName" ) ) ); } @Test public void shouldParseManyProperties() { - assertThat( IndexSpecifier.patternOrName( ":Person(1, 2, 3, 4, 5, 6)" ).properties(), + assertThat( IndexSpecifier.byPatternOrName( ":Person(1, 2, 3, 4, 5, 6)" ).properties(), is( arrayContaining( "1", "2", "3", "4", "5", "6" ) ) ); - assertThat( IndexSpecifier.pattern( ":Person(1, 2, 3, 4, 5, 6)" ).properties(), + assertThat( IndexSpecifier.byPattern( ":Person(1, 2, 3, 4, 5, 6)" ).properties(), is( arrayContaining( "1", "2", "3", "4", "5", "6" ) ) ); } @@ -73,41 +73,46 @@ public void shouldParseManyProperties() public void shouldParseManyPropertiesWithWhitespace() { String specification = ":Person( 1 , 2 ,3 ,4 )"; - assertThat( IndexSpecifier.patternOrName( specification ).properties(), + assertThat( IndexSpecifier.byPatternOrName( specification ).properties(), is( arrayContaining( "1", "2", "3", "4" ) ) ); - assertThat( IndexSpecifier.pattern( specification ).properties(), + assertThat( IndexSpecifier.byPattern( specification ).properties(), is( arrayContaining( "1", "2", "3", "4" ) ) ); } @Test public void shouldParseOddProperties() { - assertThat( IndexSpecifier.patternOrName( ": Person(1, 2lskgj_LKHGS, `3sdlkhs, df``sas;g`, 4, ` 5 `, 6)" ).properties(), + assertThat( IndexSpecifier.byPatternOrName( ": Person(1, 2lskgj_LKHGS, `3sdlkhs, df``sas;g`, 4, ` 5 `, 6)" ).properties(), is( arrayContaining( "1", "2lskgj_LKHGS", "3sdlkhs, df``sas;g", "4", " 5 ", "6" ) ) ); - assertThat( IndexSpecifier.pattern( ": Person(1, 2lskgj_LKHGS, `3sdlkhs, df``sas;g`, 4, ` 5 `, 6)" ).properties(), + assertThat( IndexSpecifier.byPattern( ": Person(1, 2lskgj_LKHGS, `3sdlkhs, df``sas;g`, 4, ` 5 `, 6)" ).properties(), is( arrayContaining( "1", "2lskgj_LKHGS", "3sdlkhs, df``sas;g", "4", " 5 ", "6" ) ) ); } @Test public void shouldParseANastyLabel() { - assertThat( IndexSpecifier.patternOrName( ":`:(!\"£$%^&*( )`(name)" ).label(), is( ":(!\"£$%^&*( )" ) ); - assertThat( IndexSpecifier.pattern( ":`:(!\"£$%^&*( )`(name)" ).label(), is( ":(!\"£$%^&*( )" ) ); + assertThat( IndexSpecifier.byPatternOrName( ":`:(!\"£$%^&*( )`(name)" ).label(), is( ":(!\"£$%^&*( )" ) ); + assertThat( IndexSpecifier.byPattern( ":`:(!\"£$%^&*( )`(name)" ).label(), is( ":(!\"£$%^&*( )" ) ); } @Test public void shouldParseANastyProperty() { - assertThat( IndexSpecifier.patternOrName( ":Person(`(:!\"£$%^&*( )`)" ).properties(), + assertThat( IndexSpecifier.byPatternOrName( ":Person(`(:!\"£$%^&*( )`)" ).properties(), is( arrayContaining( "(:!\"£$%^&*( )" ) ) ); - assertThat( IndexSpecifier.pattern( ":Person(`(:!\"£$%^&*( )`)" ).properties(), + assertThat( IndexSpecifier.byPattern( ":Person(`(:!\"£$%^&*( )`)" ).properties(), is( arrayContaining( "(:!\"£$%^&*( )" ) ) ); } @Test public void specifiersThatDoNotBeginWithColonAreIndexNames() { - IndexSpecifier spec = IndexSpecifier.patternOrName( "my_index" ); + IndexSpecifier spec = IndexSpecifier.byPatternOrName( "my_index" ); + assertThat( spec.name(), is( "my_index" ) ); + assertNull( spec.label() ); + assertNull( spec.properties() ); + + spec = IndexSpecifier.byName( "my_index" ); assertThat( spec.name(), is( "my_index" ) ); assertNull( spec.label() ); assertNull( spec.properties() ); @@ -116,7 +121,7 @@ public void specifiersThatDoNotBeginWithColonAreIndexNames() @Test public void patternSpecifiersHaveNoName() { - IndexSpecifier spec = IndexSpecifier.pattern( ":Person(name)" ); + IndexSpecifier spec = IndexSpecifier.byPattern( ":Person(name)" ); assertNotNull( spec.label() ); assertNotNull( spec.properties() ); assertNull( spec.name() ); @@ -127,16 +132,27 @@ public void shouldProduceAReasonableErrorIfTheSpecificationCantBeParsed() { try { - IndexSpecifier.patternOrName( "just some rubbish" ); + IndexSpecifier.byPatternOrName( "just some rubbish" ); + fail( "expected exception" ); + } + catch ( IllegalArgumentException e ) + { + //expected + } + + try + { + IndexSpecifier.byPattern( "rubbish" ); fail( "expected exception" ); } catch ( IllegalArgumentException e ) { //expected } + try { - IndexSpecifier.pattern( "rubbish" ); + IndexSpecifier.byName( ":Person(name)" ); fail( "expected exception" ); } catch ( IllegalArgumentException e )