Skip to content

Commit

Permalink
Moved ReflectiveProcedureCallAcceptanceTest to correct project
Browse files Browse the repository at this point in the history
Now it should actually be used in test runs
  • Loading branch information
SaschaPeukert committed Mar 21, 2018
1 parent 60d4280 commit 93efcec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
Expand Up @@ -5,17 +5,17 @@
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.cypher.acceptance;

Expand Down Expand Up @@ -54,13 +54,13 @@ public static class SimulateFailureOnCloseException extends SimulateFailureBaseE

public static class Counters
{
public int closeCountTestResourceProcedure = 0;
public int closeCountTestFailingResourceProcedure = 0;
public int closeCountTestOnCloseFailingResourceProcedure = 0;
public int closeCountTestResourceProcedure;
public int closeCountTestFailingResourceProcedure;
public int closeCountTestOnCloseFailingResourceProcedure;

public int openCountTestResourceProcedure = 0;
public int openCountTestFailingResourceProcedure = 0;
public int openCountTestOnCloseFailingResourceProcedure = 0;
public int openCountTestResourceProcedure;
public int openCountTestFailingResourceProcedure;
public int openCountTestOnCloseFailingResourceProcedure;

public int liveCountTestResourceProcedure()
{
Expand Down Expand Up @@ -107,9 +107,8 @@ public Output( Long value )
@Description( "Returns a stream of integers from 1 to the given argument" )
public Stream<Output> testResourceProcedure( @Name( value = "resultCount", defaultValue = "4" ) long resultCount ) throws Exception
{
Stream<Output> stream = Stream.iterate( 1L, (i) -> i + 1 ).limit( resultCount ).map( Output::new );
stream.onClose( () ->
{
Stream<Output> stream = Stream.iterate( 1L, i -> i + 1 ).limit( resultCount ).map( Output::new );
stream.onClose( () -> {
counters.closeCountTestResourceProcedure++;
} );
counters.openCountTestResourceProcedure++;
Expand Down Expand Up @@ -137,13 +136,12 @@ public Output next()
{
throw new SimulateFailureException();
}
return new Output(step++);
return new Output( step++ );
}
};
Iterable<Output> failingIterable = () -> failingIterator;
Stream<Output> stream = StreamSupport.stream(failingIterable.spliterator(), false);
stream.onClose( () ->
{
Stream<Output> stream = StreamSupport.stream( failingIterable.spliterator(), false );
stream.onClose( () -> {
counters.closeCountTestFailingResourceProcedure++;
} );
counters.openCountTestFailingResourceProcedure++;
Expand All @@ -154,9 +152,8 @@ public Output next()
@Description( "Returns a stream of integers from 1 to the given argument. Throws an exception on close." )
public Stream<Output> testOnCloseFailingResourceProcedure( @Name( value = "resultCount", defaultValue = "4" ) long resultCount ) throws Exception
{
Stream<Output> stream = Stream.iterate( 1L, (i) -> i + 1 ).limit( resultCount ).map( Output::new );
stream.onClose( () ->
{
Stream<Output> stream = Stream.iterate( 1L, i -> i + 1 ).limit( resultCount ).map( Output::new );
stream.onClose( () -> {
counters.closeCountTestOnCloseFailingResourceProcedure++;
throw new SimulateFailureOnCloseException();
} );
Expand Down
Expand Up @@ -5,29 +5,29 @@
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.cypher.acceptance

import java.io.PrintWriter

import org.apache.commons.lang3.exception.ExceptionUtils
import org.neo4j.cypher._
import org.neo4j.cypher.internal.compiler.v3_1.test_helpers.CreateTempFileTestSupport
import org.neo4j.cypher.internal.runtime.CreateTempFileTestSupport
import org.neo4j.graphdb.{QueryExecutionException, TransactionFailureException}
import org.neo4j.internal.cypher.acceptance.TestResourceProcedure.{SimulateFailureException, SimulateFailureOnCloseException}
import org.neo4j.kernel.api.KernelTransaction
import org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED
import org.neo4j.internal.cypher.acceptance.TestResourceProcedure._
import org.neo4j.internal.kernel.api.Transaction
import org.neo4j.internal.kernel.api.security.LoginContext
import org.neo4j.kernel.impl.proc.Procedures

import scala.collection.mutable.ArrayBuffer
Expand All @@ -53,7 +53,7 @@ class ReflectiveProcedureCallAcceptanceTest extends ExecutionEngineFunSuite with
private def setUpProcedures(): TestResourceProcedure.Counters = {
val procedures = graph.getDependencyResolver.resolveDependency(classOf[Procedures])
val counters = new TestResourceProcedure.Counters
procedures.registerComponent(classOf[TestResourceProcedure.Counters], TestResourceProcedure.countersProvider(counters))
procedures.registerComponent(classOf[TestResourceProcedure.Counters], TestResourceProcedure.countersProvider(counters), true)

procedures.registerProcedure(classOf[TestResourceProcedure])
procedures.registerFunction(classOf[TestResourceProcedure])
Expand Down Expand Up @@ -87,7 +87,7 @@ class ReflectiveProcedureCallAcceptanceTest extends ExecutionEngineFunSuite with
test("should close resources on mid-stream transaction close") {
val counters = setUpProcedures()

val tx = graph.beginTransaction(KernelTransaction.Type.`implicit`, AUTH_DISABLED)
val tx = graph.beginTransaction(Transaction.Type.`implicit`, LoginContext.AUTH_DISABLED)
val result = graph.execute(defaultQuery)

// Pull one row and then close the transaction
Expand Down Expand Up @@ -115,7 +115,7 @@ class ReflectiveProcedureCallAcceptanceTest extends ExecutionEngineFunSuite with
test("should not leave any resources open on transaction close before pulling on the result") {
val counters = setUpProcedures()

val tx = graph.beginTransaction(KernelTransaction.Type.`implicit`, AUTH_DISABLED)
val tx = graph.beginTransaction(Transaction.Type.`implicit`, LoginContext.AUTH_DISABLED)
val result = graph.execute(defaultQuery)

// Close the transaction directly without pulling the result
Expand All @@ -130,7 +130,7 @@ class ReflectiveProcedureCallAcceptanceTest extends ExecutionEngineFunSuite with
val counters = setUpProcedures()
val numberOfRows = 100

val tx = graph.beginTransaction(KernelTransaction.Type.`implicit`, AUTH_DISABLED)
val tx = graph.beginTransaction(Transaction.Type.`implicit`, LoginContext.AUTH_DISABLED)
val result = graph.execute(s"UNWIND range(1,$numberOfRows) as i CALL org.neo4j.test.testResourceProcedure(1) YIELD value RETURN value")

// Pull one row and then close the transaction
Expand Down

0 comments on commit 93efcec

Please sign in to comment.