Skip to content

Commit

Permalink
Added new procedures to the procedure resources statement closing test
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner committed Aug 29, 2017
1 parent 21bc267 commit 92be452
Showing 1 changed file with 123 additions and 55 deletions.
Expand Up @@ -24,10 +24,8 @@
import org.junit.Test; import org.junit.Test;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -68,17 +66,14 @@ public void tearDown() throws InterruptedException
@Test @Test
public void allProcedures() throws Exception public void allProcedures() throws Exception
{ {
// given
Map<String,List<Object>> allProceduresWithParameters = allProceduresWithParameters();

// when // when
createLegacyIndex(); createLegacyIndex();
createIndex(); createIndex();
for ( Map.Entry<String,List<Object>> procedureWithParams : allProceduresWithParameters.entrySet() ) for(ProcedureSignature procedure : db.getDependencyResolver().resolveDependency( Procedures.class ).getAllProcedures())
{ {
// then // then
initialData(); initialData();
verifyProcedureCloseAllAcquiredKernelStatements( procedureWithParams.getKey(), procedureWithParams.getValue() ); verifyProcedureCloseAllAcquiredKernelStatements( procedureDataFor( procedure ) );
clearDb(); clearDb();
} }
} }
Expand All @@ -99,13 +94,12 @@ private void initialData()
} }
} }


private void verifyProcedureCloseAllAcquiredKernelStatements( String procedureName, List<Object> parameters ) private void verifyProcedureCloseAllAcquiredKernelStatements( ProcedureData proc ) throws ExecutionException, InterruptedException
throws ExecutionException, InterruptedException
{ {
String failureMessage = "Failed on procedure " + procedureName; String failureMessage = "Failed on procedure " + proc.name;
try ( Transaction outer = db.beginTx() ) try ( Transaction outer = db.beginTx() )
{ {
String procedureQuery = buildProcedureQuery( procedureName, parameters ); String procedureQuery = proc.buildProcedureQuery();
exhaust( db.execute( procedureQuery ) ).close(); exhaust( db.execute( procedureQuery ) ).close();
exhaust( db.execute( "MATCH (mo:Label) WHERE mo.prop = 'n/a' RETURN mo" ) ).close(); exhaust( db.execute( "MATCH (mo:Label) WHERE mo.prop = 'n/a' RETURN mo" ) ).close();
executeInOtherThread( "CREATE(mo:Label) SET mo.prop = 'val' RETURN mo" ); executeInOtherThread( "CREATE(mo:Label) SET mo.prop = 'val' RETURN mo" );
Expand Down Expand Up @@ -152,16 +146,6 @@ private void createLegacyIndex()
} }
} }


private String buildProcedureQuery( String procedureName, List<Object> parameters )
{
StringJoiner stringJoiner = new StringJoiner( ",", "CALL " + procedureName + "(", ")" );
for ( Object parameter : parameters )
{
stringJoiner.add( parameter.toString() );
}
return stringJoiner.toString();
}

private void clearDb() private void clearDb()
{ {
try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
Expand All @@ -171,79 +155,163 @@ private void clearDb()
} }
} }


private Map<String,List<Object>> allProceduresWithParameters() private static class ProcedureData
{ {
Set<ProcedureSignature> allProcedures = db.getDependencyResolver().resolveDependency( Procedures.class ).getAllProcedures(); private final String name;
Map<String,List<Object>> allProceduresWithParameters = new HashMap<>(); private final List<Object> params = new ArrayList<>();
for ( ProcedureSignature procedure : allProcedures ) private String setupQuery = null;
private String postQuery = null;

private ProcedureData( ProcedureSignature procedure )
{
this.name = procedure.name().toString();
}

private void withParam( Object param )
{ {
List<Object> params = paramsFor( procedure ); this.params.add( param );
allProceduresWithParameters.put( procedure.name().toString(), params ); }

private void withSetup( String setupQuery, String postQuery )
{
this.setupQuery = setupQuery;
this.postQuery = postQuery;
}

private String buildProcedureQuery()
{
StringJoiner stringJoiner = new StringJoiner( ",", "CALL " + name + "(", ")" );
for ( Object parameter : params )
{
stringJoiner.add( parameter.toString() );
}
if ( setupQuery != null && postQuery != null )
{
return setupQuery + " " + stringJoiner.toString() + " " + postQuery;
}
else
{
return stringJoiner.toString();
}
} }
return allProceduresWithParameters;
} }


private List<Object> paramsFor( ProcedureSignature procedure ) private ProcedureData procedureDataFor( ProcedureSignature procedure )
{ {
List<Object> parameters = new ArrayList<>(); ProcedureData proc = new ProcedureData( procedure );
switch ( procedure.name().toString() ) switch ( proc.name )
{ {
case "db.createProperty": case "db.createProperty":
parameters.add( "'propKey'" ); proc.withParam( "'propKey'" );
break; break;
case "db.resampleIndex": case "db.resampleIndex":
parameters.add( "'" + indexDefinition + "'" ); proc.withParam( "'" + indexDefinition + "'" );
break; break;
case "db.createRelationshipType": case "db.createRelationshipType":
parameters.add( "'RelType'" ); proc.withParam( "'RelType'" );
break; break;
case "dbms.queryJmx": case "dbms.queryJmx":
parameters.add( "'*:*'" ); proc.withParam( "'*:*'" );
break; break;
case "db.awaitIndex": case "db.awaitIndex":
parameters.add( "'" + indexDefinition + "'" ); proc.withParam( "'" + indexDefinition + "'" );
parameters.add( 100 ); proc.withParam( 100 );
break; break;
case "db.createLabel": case "db.createLabel":
parameters.add( "'OtherLabel'" ); proc.withParam( "'OtherLabel'" );
break; break;
case "dbms.killQuery": case "dbms.killQuery":
parameters.add( "'query-1234'" ); proc.withParam( "'query-1234'" );
break; break;
case "dbms.killQueries": case "dbms.killQueries":
parameters.add( "['query-1234']" ); proc.withParam( "['query-1234']" );
break; break;
case "dbms.setTXMetaData": case "dbms.setTXMetaData":
parameters.add( "{realUser:'MyMan'}" ); proc.withParam( "{realUser:'MyMan'}" );
break; break;
case "dbms.listActiveLocks": case "dbms.listActiveLocks":
parameters.add( "'query-1234'" ); proc.withParam( "'query-1234'" );
break; break;
case "db.nodeManualIndexSeek": case "db.nodeManualIndexSeek":
parameters.add( "'" + legacyIndexName + "'" ); proc.withParam( "'" + legacyIndexName + "'" );
parameters.add( "'noKey'" ); proc.withParam( "'noKey'" );
parameters.add( "'noValue'" ); proc.withParam( "'noValue'" );
break; break;
case "db.nodeManualIndexSearch": case "db.nodeManualIndexSearch":
parameters.add( "'" + legacyIndexName + "'" ); proc.withParam( "'" + legacyIndexName + "'" );
parameters.add( "'noKey:foo*'" ); proc.withParam( "'noKey:foo*'" );
break; break;
case "db.relationshipManualIndexSearch": case "db.relationshipManualIndexSearch":
parameters.add( "'" + relLegacyIndexName + "'" ); proc.withParam( "'" + relLegacyIndexName + "'" );
parameters.add( "'noKey:foo*'" ); proc.withParam( "'noKey:foo*'" );
break; break;
case "db.relationshipManualIndexSeek": case "db.relationshipManualIndexSeek":
parameters.add( "'" + relLegacyIndexName + "'" ); proc.withParam( "'" + relLegacyIndexName + "'" );
parameters.add( "'noKey'" ); proc.withParam( "'noKey'" );
parameters.add( "'noValue'" ); proc.withParam( "'noValue'" );
break;
case "db.nodeAutoIndexSeek":
proc.withParam( "'noKey'" );
proc.withParam( "'noValue'" );
break;
case "db.nodeAutoIndexSearch":
proc.withParam( "'noKey:foo*'" );
break;
case "db.relationshipAutoIndexSearch":
proc.withParam( "'noKey:foo*'" );
break;
case "db.relationshipAutoIndexSeek":
proc.withParam( "'noKey'" );
proc.withParam( "'noValue'" );
break;
case "db.nodeManualIndexExists":
proc.withParam( "'" + legacyIndexName + "'" );
break;
case "db.relationshipManualIndexExists":
proc.withParam( "'" + legacyIndexName + "'" );
break;
case "db.nodeManualIndex":
proc.withParam( "'" + legacyIndexName + "'" );
break;
case "db.relationshipManualIndex":
proc.withParam( "'" + legacyIndexName + "'" );
break;
case "db.nodeManualIndexAdd":
proc.withParam( "'" + legacyIndexName + "'" );
proc.withParam( "n" );
proc.withParam( "'prop'" );
proc.withParam( "'value'");
proc.withSetup( "OPTIONAL MATCH (n) WITH n LIMIT 1", "YIELD success RETURN success" );
break;
case "db.relationshipManualIndexAdd":
proc.withParam( "'" + legacyIndexName + "'" );
proc.withParam( "r" );
proc.withParam( "'prop'" );
proc.withParam( "'value'");
proc.withSetup( "OPTIONAL MATCH ()-[r]->() WITH r LIMIT 1", "YIELD success RETURN success" );
break;
case "db.nodeManualIndexRemove":
proc.withParam( "'" + legacyIndexName + "'" );
proc.withParam( "n" );
proc.withParam( "'prop'" );
proc.withSetup( "OPTIONAL MATCH (n) WITH n LIMIT 1", "YIELD success RETURN success" );
break;
case "db.relationshipManualIndexRemove":
proc.withParam( "'" + legacyIndexName + "'" );
proc.withParam( "r" );
proc.withParam( "'prop'" );
proc.withSetup( "OPTIONAL MATCH ()-[r]->() WITH r LIMIT 1", "YIELD success RETURN success" );
break;
case "db.manualIndexDrop":
proc.withParam( "'" + legacyIndexName + "'" );
break; break;
case "dbms.setConfigValue": case "dbms.setConfigValue":
parameters.add( "'dbms.logs.query.enabled'" ); proc.withParam( "'dbms.logs.query.enabled'" );
parameters.add( "'false'" ); proc.withParam( "'false'" );
break; break;
default: default:
} }
return parameters; return proc;
} }


private void executeInOtherThread( String query ) throws ExecutionException, InterruptedException private void executeInOtherThread( String query ) throws ExecutionException, InterruptedException
Expand Down

0 comments on commit 92be452

Please sign in to comment.