From 92be452f9288508e1ed6791fe92b8fbce6682a55 Mon Sep 17 00:00:00 2001 From: Craig Taverner Date: Tue, 29 Aug 2017 15:06:41 +0200 Subject: [PATCH] Added new procedures to the procedure resources statement closing test --- .../builtinprocs/ProcedureResourcesIT.java | 178 ++++++++++++------ 1 file changed, 123 insertions(+), 55 deletions(-) diff --git a/enterprise/neo4j-enterprise/src/test/java/org/neo4j/kernel/builtinprocs/ProcedureResourcesIT.java b/enterprise/neo4j-enterprise/src/test/java/org/neo4j/kernel/builtinprocs/ProcedureResourcesIT.java index 02a178f8395c0..0c0ffcf709e3d 100644 --- a/enterprise/neo4j-enterprise/src/test/java/org/neo4j/kernel/builtinprocs/ProcedureResourcesIT.java +++ b/enterprise/neo4j-enterprise/src/test/java/org/neo4j/kernel/builtinprocs/ProcedureResourcesIT.java @@ -24,10 +24,8 @@ import org.junit.Test; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.StringJoiner; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -68,17 +66,14 @@ public void tearDown() throws InterruptedException @Test public void allProcedures() throws Exception { - // given - Map> allProceduresWithParameters = allProceduresWithParameters(); - // when createLegacyIndex(); createIndex(); - for ( Map.Entry> procedureWithParams : allProceduresWithParameters.entrySet() ) + for(ProcedureSignature procedure : db.getDependencyResolver().resolveDependency( Procedures.class ).getAllProcedures()) { // then initialData(); - verifyProcedureCloseAllAcquiredKernelStatements( procedureWithParams.getKey(), procedureWithParams.getValue() ); + verifyProcedureCloseAllAcquiredKernelStatements( procedureDataFor( procedure ) ); clearDb(); } } @@ -99,13 +94,12 @@ private void initialData() } } - private void verifyProcedureCloseAllAcquiredKernelStatements( String procedureName, List parameters ) - throws ExecutionException, InterruptedException + private void verifyProcedureCloseAllAcquiredKernelStatements( ProcedureData proc ) throws ExecutionException, InterruptedException { - String failureMessage = "Failed on procedure " + procedureName; + String failureMessage = "Failed on procedure " + proc.name; try ( Transaction outer = db.beginTx() ) { - String procedureQuery = buildProcedureQuery( procedureName, parameters ); + String procedureQuery = proc.buildProcedureQuery(); exhaust( db.execute( procedureQuery ) ).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" ); @@ -152,16 +146,6 @@ private void createLegacyIndex() } } - private String buildProcedureQuery( String procedureName, List parameters ) - { - StringJoiner stringJoiner = new StringJoiner( ",", "CALL " + procedureName + "(", ")" ); - for ( Object parameter : parameters ) - { - stringJoiner.add( parameter.toString() ); - } - return stringJoiner.toString(); - } - private void clearDb() { try ( Transaction tx = db.beginTx() ) @@ -171,79 +155,163 @@ private void clearDb() } } - private Map> allProceduresWithParameters() + private static class ProcedureData { - Set allProcedures = db.getDependencyResolver().resolveDependency( Procedures.class ).getAllProcedures(); - Map> allProceduresWithParameters = new HashMap<>(); - for ( ProcedureSignature procedure : allProcedures ) + private final String name; + private final List params = new ArrayList<>(); + private String setupQuery = null; + private String postQuery = null; + + private ProcedureData( ProcedureSignature procedure ) + { + this.name = procedure.name().toString(); + } + + private void withParam( Object param ) { - List params = paramsFor( procedure ); - allProceduresWithParameters.put( procedure.name().toString(), params ); + this.params.add( param ); + } + + 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 paramsFor( ProcedureSignature procedure ) + private ProcedureData procedureDataFor( ProcedureSignature procedure ) { - List parameters = new ArrayList<>(); - switch ( procedure.name().toString() ) + ProcedureData proc = new ProcedureData( procedure ); + switch ( proc.name ) { case "db.createProperty": - parameters.add( "'propKey'" ); + proc.withParam( "'propKey'" ); break; case "db.resampleIndex": - parameters.add( "'" + indexDefinition + "'" ); + proc.withParam( "'" + indexDefinition + "'" ); break; case "db.createRelationshipType": - parameters.add( "'RelType'" ); + proc.withParam( "'RelType'" ); break; case "dbms.queryJmx": - parameters.add( "'*:*'" ); + proc.withParam( "'*:*'" ); break; case "db.awaitIndex": - parameters.add( "'" + indexDefinition + "'" ); - parameters.add( 100 ); + proc.withParam( "'" + indexDefinition + "'" ); + proc.withParam( 100 ); break; case "db.createLabel": - parameters.add( "'OtherLabel'" ); + proc.withParam( "'OtherLabel'" ); break; case "dbms.killQuery": - parameters.add( "'query-1234'" ); + proc.withParam( "'query-1234'" ); break; case "dbms.killQueries": - parameters.add( "['query-1234']" ); + proc.withParam( "['query-1234']" ); break; case "dbms.setTXMetaData": - parameters.add( "{realUser:'MyMan'}" ); + proc.withParam( "{realUser:'MyMan'}" ); break; case "dbms.listActiveLocks": - parameters.add( "'query-1234'" ); + proc.withParam( "'query-1234'" ); break; case "db.nodeManualIndexSeek": - parameters.add( "'" + legacyIndexName + "'" ); - parameters.add( "'noKey'" ); - parameters.add( "'noValue'" ); + proc.withParam( "'" + legacyIndexName + "'" ); + proc.withParam( "'noKey'" ); + proc.withParam( "'noValue'" ); break; case "db.nodeManualIndexSearch": - parameters.add( "'" + legacyIndexName + "'" ); - parameters.add( "'noKey:foo*'" ); + proc.withParam( "'" + legacyIndexName + "'" ); + proc.withParam( "'noKey:foo*'" ); break; case "db.relationshipManualIndexSearch": - parameters.add( "'" + relLegacyIndexName + "'" ); - parameters.add( "'noKey:foo*'" ); + proc.withParam( "'" + relLegacyIndexName + "'" ); + proc.withParam( "'noKey:foo*'" ); break; case "db.relationshipManualIndexSeek": - parameters.add( "'" + relLegacyIndexName + "'" ); - parameters.add( "'noKey'" ); - parameters.add( "'noValue'" ); + proc.withParam( "'" + relLegacyIndexName + "'" ); + proc.withParam( "'noKey'" ); + 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; case "dbms.setConfigValue": - parameters.add( "'dbms.logs.query.enabled'" ); - parameters.add( "'false'" ); + proc.withParam( "'dbms.logs.query.enabled'" ); + proc.withParam( "'false'" ); break; default: } - return parameters; + return proc; } private void executeInOtherThread( String query ) throws ExecutionException, InterruptedException