Skip to content

Commit

Permalink
Fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Mar 21, 2016
1 parent c257843 commit bcdda5d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
Expand Up @@ -327,6 +327,6 @@ class StandaloneProcedureCallAcceptanceTest extends ProcedureCallAcceptanceTest

// Then
result.toList should equal(
List(Map("description" -> "INDEX ON :A(prop)", "state" -> "ONLINE", "unique" -> false)))
List(Map("description" -> "INDEX ON :A(prop)", "state" -> "online", "type" -> "node_label_property")))
}
}
Expand Up @@ -44,12 +44,33 @@

public class ListIndexesProcedure extends CallableProcedure.BasicProcedure
{

//When we have decided on what to call different indexes
//this should probably be moved to some more central place
public enum IndexType
{
NODE_LABEL_PROPERTY( "node_label_property" ),
NODE_UNIQUE_PROPERTY( "node_unique_property" );

private final String typeName;

IndexType( String typeName )
{
this.typeName = typeName;
}

public String typeName()
{
return typeName;
}
}

protected ListIndexesProcedure(ProcedureName procedureName)
{
super( procedureSignature( procedureName )
.out( "description", Neo4jTypes.NTString )
.out( "state", Neo4jTypes.NTString )
.out( "unique", Neo4jTypes.NTBoolean )
.out( "type", Neo4jTypes.NTString )
.build() );
}

Expand All @@ -67,17 +88,21 @@ public RawIterator<Object[],ProcedureException> apply( Context ctx, Object[] inp
indexes.addAll( uniqueIndexes );
indexes.sort( (a,b) -> a.userDescription(tokens).compareTo( b.userDescription(tokens) ) );

return format( indexes, statement, tokens, uniqueIndexes::contains );
return format( indexes, statement, tokens, (descriptor) -> {
if (uniqueIndexes.contains( descriptor )) return IndexType.NODE_UNIQUE_PROPERTY;
else return IndexType.NODE_LABEL_PROPERTY;
} );
}

private RawIterator<Object[],ProcedureException> format(List<IndexDescriptor> indexes,
Statement statement, TokenNameLookup tokens, Function<IndexDescriptor, Boolean> unqiue)
Statement statement, TokenNameLookup tokens, Function<IndexDescriptor, IndexType> type)
{
return map( ( index ) -> {
try
{
return new Object[]{"INDEX ON " + index.userDescription( tokens ),
statement.readOperations().indexGetState( index ).toString(), unqiue.apply( index )};
statement.readOperations().indexGetState( index ).toString().toLowerCase(),
type.apply( index ).typeName()};
}
catch ( IndexNotFoundKernelException e )
{
Expand Down
Expand Up @@ -31,13 +31,13 @@
import java.util.Map;

import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.api.dbms.DbmsOperations;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.ReadOperations;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint;
import org.neo4j.kernel.api.constraints.PropertyConstraint;
import org.neo4j.kernel.api.constraints.UniquenessConstraint;
import org.neo4j.kernel.api.dbms.DbmsOperations;
import org.neo4j.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.index.IndexDescriptor;
import org.neo4j.kernel.api.index.InternalIndexState;
Expand All @@ -46,8 +46,8 @@
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.storageengine.api.Token;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyIterator;
import static java.util.Collections.singletonList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
Expand All @@ -57,6 +57,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.neo4j.kernel.api.proc.CallableProcedure.Context.KERNEL_TRANSACTION;
import static org.neo4j.kernel.builtinprocs.ListIndexesProcedure.IndexType.NODE_LABEL_PROPERTY;
import static org.neo4j.kernel.builtinprocs.ListIndexesProcedure.IndexType.NODE_UNIQUE_PROPERTY;

public class BuiltInProceduresTest
{
Expand Down Expand Up @@ -84,7 +86,7 @@ public void shouldListAllIndexes() throws Throwable

List<Object[]> call = call( "db.indexes" );
assertThat( call,
contains( record( "INDEX ON :User(name)", "ONLINE", false ) ) );
contains( record( "INDEX ON :User(name)", "online", NODE_LABEL_PROPERTY.typeName() ) ) );
}

@Test
Expand All @@ -95,7 +97,7 @@ public void shouldListAllUniqueIndexes() throws Throwable

// When/Then
assertThat( call( "db.indexes" ),
contains( record( "INDEX ON :User(name)", "ONLINE", true ) ) );
contains( record( "INDEX ON :User(name)", "online", NODE_UNIQUE_PROPERTY.typeName() ) ) );
}

@Test
Expand Down Expand Up @@ -157,7 +159,7 @@ public void shouldListCorrectBuiltinProcedures() throws Throwable
// When/Then
assertThat( call( "sys.procedures" ), contains(
record( "db.constraints", "db.constraints() :: (description :: STRING?)" ),
record( "db.indexes", "db.indexes() :: (description :: STRING?, state :: STRING?, unique :: BOOLEAN?)" ),
record( "db.indexes", "db.indexes() :: (description :: STRING?, state :: STRING?, type :: STRING?)" ),
record( "db.labels", "db.labels() :: (label :: STRING?)" ),
record( "db.propertyKeys", "db.propertyKeys() :: (propertyKey :: STRING?)" ),
record( "db.relationshipTypes", "db.relationshipTypes() :: (relationshipType :: STRING?)" ),
Expand All @@ -172,7 +174,7 @@ public void shouldListSystemComponents() throws Throwable
{
// When/Then
assertThat( call( "sys.components" ), contains(
record( "Neo4j Kernel", asList( "1.3.37" ) )
record( "Neo4j Kernel", singletonList( "1.3.37" ) )
) );
}

Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.kernel.api.SchemaWriteOperations;
import org.neo4j.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.security.AccessMode;
import org.neo4j.kernel.builtinprocs.ListIndexesProcedure;
import org.neo4j.server.security.auth.AuthSubject;

import static java.util.concurrent.TimeUnit.SECONDS;
Expand Down Expand Up @@ -156,7 +157,7 @@ public void listProcedures() throws Throwable
// Then
assertThat( asList( stream ), containsInAnyOrder(
equalTo( new Object[]{"db.constraints", "db.constraints() :: (description :: STRING?)"} ),
equalTo( new Object[]{"db.indexes", "db.indexes() :: (description :: STRING?, state :: STRING?, unique :: BOOLEAN?)"} ),
equalTo( new Object[]{"db.indexes", "db.indexes() :: (description :: STRING?, state :: STRING?, type :: STRING?)"} ),
equalTo( new Object[]{"db.propertyKeys", "db.propertyKeys() :: (propertyKey :: STRING?)"}),
equalTo( new Object[]{"db.labels", "db.labels() :: (label :: STRING?)"} ),
equalTo( new Object[]{"sys.procedures", "sys.procedures() :: (name :: STRING?, signature :: STRING?)"} ),
Expand Down Expand Up @@ -248,8 +249,10 @@ public void listAllIndexes() throws Throwable
readOperationsInNewTransaction().procedureCallRead( procedureName( "db", "indexes" ), new Object[0] );

// Then
assertThat( stream.next(), equalTo( new Object[]{"INDEX ON :Age(foo)", "ONLINE", true} ) );
assertThat( stream.next(), equalTo( new Object[]{"INDEX ON :Person(foo)", "ONLINE", false} ) );
assertThat( stream.next(), equalTo( new Object[]{"INDEX ON :Age(foo)", "online",
ListIndexesProcedure.IndexType.NODE_UNIQUE_PROPERTY.typeName()} ) );
assertThat( stream.next(), equalTo( new Object[]{"INDEX ON :Person(foo)", "online",
ListIndexesProcedure.IndexType.NODE_LABEL_PROPERTY.typeName()} ) );
}

@Test
Expand Down

0 comments on commit bcdda5d

Please sign in to comment.