Skip to content

Commit

Permalink
Delegate the isTopLevel tx check to the TransactionalContext
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Feb 26, 2016
1 parent 661ed73 commit 6616bcc
Show file tree
Hide file tree
Showing 35 changed files with 172 additions and 125 deletions.
Expand Up @@ -34,7 +34,6 @@
import org.neo4j.bolt.v1.runtime.spi.RecordStream; import org.neo4j.bolt.v1.runtime.spi.RecordStream;
import org.neo4j.bolt.v1.runtime.spi.StatementRunner; import org.neo4j.bolt.v1.runtime.spi.StatementRunner;
import org.neo4j.cypher.SyntaxException; import org.neo4j.cypher.SyntaxException;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.TransactionFailureException; import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.Status;
Expand All @@ -58,7 +57,7 @@ public class StateMachineErrorTest
private GraphDatabaseFacade db = mock( GraphDatabaseFacade.class ); private GraphDatabaseFacade db = mock( GraphDatabaseFacade.class );
private ThreadToStatementContextBridge txBridge = mock( ThreadToStatementContextBridge.class ); private ThreadToStatementContextBridge txBridge = mock( ThreadToStatementContextBridge.class );
private StatementRunner runner = mock( StatementRunner.class ); private StatementRunner runner = mock( StatementRunner.class );
private Transaction tx = mock( TopLevelTransaction.class ); private TopLevelTransaction tx = mock( TopLevelTransaction.class );


@Before @Before
public void setup() public void setup()
Expand Down
Expand Up @@ -26,18 +26,19 @@
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.security.URLAccessValidationError; import org.neo4j.graphdb.security.URLAccessValidationError;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.kernel.GraphDatabaseQueryService; import org.neo4j.kernel.GraphDatabaseQueryService;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;


public class GraphDatabaseCypherService implements GraphDatabaseQueryService public class GraphDatabaseCypherService implements GraphDatabaseQueryService
{ {
private GraphDatabaseAPI graph; private GraphDatabaseFacade graph;


public GraphDatabaseCypherService( GraphDatabaseService graph ) public GraphDatabaseCypherService( GraphDatabaseService graph )
{ {
this.graph = (GraphDatabaseAPI) graph; this.graph = (GraphDatabaseFacade) graph;
} }


@Override @Override
Expand Down Expand Up @@ -71,9 +72,9 @@ public Relationship getRelationshipById( long id )
} }


@Override @Override
public Transaction beginTx() public InternalTransaction beginTransaction( KernelTransaction.Type type )
{ {
return graph.beginTx(); return graph.beginTransaction( type );
} }


@Override @Override
Expand All @@ -84,7 +85,7 @@ public URL validateURLAccess( URL url ) throws URLAccessValidationError


// This provides backwards compatibility to the older API for places that cannot (yet) stop using it. // This provides backwards compatibility to the older API for places that cannot (yet) stop using it.
// TODO: Remove this when possible (remove RULE, remove older compilers) // TODO: Remove this when possible (remove RULE, remove older compilers)
public GraphDatabaseAPI getGraphDatabaseService() public GraphDatabaseFacade getGraphDatabaseService()
{ {
return graph; return graph;
} }
Expand Down
Expand Up @@ -22,22 +22,22 @@ package org.neo4j.cypher.internal
import org.neo4j.cypher.internal.spi.ExtendedTransactionalContext import org.neo4j.cypher.internal.spi.ExtendedTransactionalContext
import org.neo4j.graphdb.{Lock, PropertyContainer, Transaction} import org.neo4j.graphdb.{Lock, PropertyContainer, Transaction}
import org.neo4j.kernel.GraphDatabaseQueryService import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api.{ReadOperations, Statement} import org.neo4j.kernel.api.{KernelTransaction, ReadOperations, Statement}
import org.neo4j.kernel.api.txstate.TxStateHolder import org.neo4j.kernel.api.txstate.TxStateHolder
import org.neo4j.kernel.impl.api.KernelStatement import org.neo4j.kernel.impl.api.KernelStatement
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge
import org.neo4j.kernel.impl.coreapi.InternalTransaction


object TransactionContextFactory { object TransactionContextFactory {
def open(graphDatabaseAPI: GraphDatabaseQueryService, txBridge: ThreadToStatementContextBridge): Neo4jTransactionContext = { def open(graph: GraphDatabaseQueryService, txBridge: ThreadToStatementContextBridge): Neo4jTransactionContext = {
val isTopLevelTx = !txBridge.hasTransaction val tx = graph.beginTransaction(KernelTransaction.Type.`implicit`)
val tx = graphDatabaseAPI.beginTx()
val statement = txBridge.get() val statement = txBridge.get()
Neo4jTransactionContext(graphDatabaseAPI, tx, isTopLevelTx, statement) Neo4jTransactionContext(graph, tx, statement)
} }
} }


// please construct this class through TransactionContextFactory, this is public only for tests // please construct this class through TransactionContextFactory, this is public only for tests
case class Neo4jTransactionContext(val graph: GraphDatabaseQueryService, initialTx: Transaction, val isTopLevelTx: Boolean, case class Neo4jTransactionContext(val graph: GraphDatabaseQueryService, initialTx: InternalTransaction,
initialStatement: Statement) extends ExtendedTransactionalContext { initialStatement: Statement) extends ExtendedTransactionalContext {
private var tx = initialTx private var tx = initialTx
private var open = true private var open = true
Expand Down Expand Up @@ -69,7 +69,7 @@ case class Neo4jTransactionContext(val graph: GraphDatabaseQueryService, initial
tx.success() tx.success()
tx.close() tx.close()


tx = graph.beginTx() tx = graph.beginTransaction(KernelTransaction.Type.`implicit`)
_statement = txBridge.get() _statement = txBridge.get()
} }


Expand All @@ -85,4 +85,6 @@ case class Neo4jTransactionContext(val graph: GraphDatabaseQueryService, initial
override def stateView: TxStateHolder = statement.asInstanceOf[KernelStatement] override def stateView: TxStateHolder = statement.asInstanceOf[KernelStatement]


override def acquireWriteLock(p: PropertyContainer): Lock = tx.acquireWriteLock(p) override def acquireWriteLock(p: PropertyContainer): Lock = tx.acquireWriteLock(p)

override def isTopLevelTx: Boolean = tx.transactionType() == KernelTransaction.Type.`implicit`
} }
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService; import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.query.QueryEngineProvider; import org.neo4j.kernel.impl.query.QueryEngineProvider;
import org.neo4j.kernel.impl.query.QuerySession; import org.neo4j.kernel.impl.query.QuerySession;
import org.neo4j.logging.NullLogProvider; import org.neo4j.logging.NullLogProvider;
Expand Down Expand Up @@ -82,7 +83,7 @@ public <T> Matcher<? super T> inTxS( final Matcher<T> inner )


private Node getNodeByIdInTx( int nodeId ) private Node getNodeByIdInTx( int nodeId )
{ {
try ( Transaction ignored = gdb.beginTx() ) try ( Transaction ignored = gdb.beginTransaction( KernelTransaction.Type.explicit ) )
{ {
return gdb.getNodeById( nodeId ); return gdb.getNodeById( nodeId );
} }
Expand Down
Expand Up @@ -64,7 +64,7 @@ public class ExecutionResultTest
@Before @Before
public void initializeExecutionEngine() throws Exception public void initializeExecutionEngine() throws Exception
{ {
engine = new ExecutionEngine( new GraphDatabaseCypherService( db ), NullLogProvider.getInstance() ); engine = new ExecutionEngine( new GraphDatabaseCypherService( db.getGraphDatabaseAPI() ), NullLogProvider.getInstance() );
} }


//TODO this test is not valid for compiled runtime as the transaction will be closed when the iterator was created //TODO this test is not valid for compiled runtime as the transaction will be closed when the iterator was created
Expand Down
Expand Up @@ -22,6 +22,7 @@ package org.neo4j.cypher
import java.io.{File, PrintWriter} import java.io.{File, PrintWriter}
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit


import jdk.nashorn.internal.runtime.ScriptRuntime
import org.neo4j.cypher.internal.ExecutionEngine import org.neo4j.cypher.internal.ExecutionEngine
import org.neo4j.cypher.internal.compiler.v3_0.CompilationPhaseTracer.CompilationPhase import org.neo4j.cypher.internal.compiler.v3_0.CompilationPhaseTracer.CompilationPhase
import org.neo4j.cypher.internal.compiler.v3_0.test_helpers.CreateTempFileTestSupport import org.neo4j.cypher.internal.compiler.v3_0.test_helpers.CreateTempFileTestSupport
Expand All @@ -32,6 +33,7 @@ import org.neo4j.graphdb._
import org.neo4j.graphdb.config.Setting import org.neo4j.graphdb.config.Setting
import org.neo4j.graphdb.factory.GraphDatabaseSettings import org.neo4j.graphdb.factory.GraphDatabaseSettings
import org.neo4j.io.fs.FileUtils import org.neo4j.io.fs.FileUtils
import org.neo4j.kernel.api.KernelTransaction.Type
import org.neo4j.kernel.{NeoStoreDataSource} import org.neo4j.kernel.{NeoStoreDataSource}
import org.neo4j.test.TestGraphDatabaseFactory import org.neo4j.test.TestGraphDatabaseFactory
import org.neo4j.kernel.NeoStoreDataSource import org.neo4j.kernel.NeoStoreDataSource
Expand Down Expand Up @@ -645,7 +647,7 @@ order by a.COL1""")


// Until we have a clean cut way where statement context is injected into cypher, // Until we have a clean cut way where statement context is injected into cypher,
// I don't know a non-hairy way to tell if this was done correctly, so here goes: // I don't know a non-hairy way to tell if this was done correctly, so here goes:
val tx = graph.beginTx() val tx = graph.beginTransaction( Type.explicit )
val isTopLevelTx = tx.getClass === classOf[TopLevelTransaction] val isTopLevelTx = tx.getClass === classOf[TopLevelTransaction]
tx.close() tx.close()


Expand Down
Expand Up @@ -147,14 +147,6 @@ trait GraphDatabaseTestSupport extends CypherTestSupport with GraphIcing {
} }
} }


def execStatement[T](f: (DataWriteOperations => T)): T = {
val tx = graph.beginTx
val result = f(statement.dataWriteOperations())
tx.success()
tx.close()
result
}

def nodeIds = nodes.map(_.getId).toArray def nodeIds = nodes.map(_.getId).toArray


val REL = RelationshipType.withName("REL") val REL = RelationshipType.withName("REL")
Expand Down
Expand Up @@ -22,6 +22,7 @@ package org.neo4j.cypher
import java.util import java.util


import org.neo4j.graphdb._ import org.neo4j.graphdb._
import org.neo4j.kernel.api.KernelTransaction
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge
import org.neo4j.kernel.impl.query.QueryEngineProvider import org.neo4j.kernel.impl.query.QueryEngineProvider
import org.scalatest.Assertions import org.scalatest.Assertions
Expand Down Expand Up @@ -395,7 +396,7 @@ class MutatingIntegrationTest extends ExecutionEngineFunSuite with Assertions wi
} }


test("failure_only_fails_inner_transaction") { test("failure_only_fails_inner_transaction") {
val tx = graph.beginTx() val tx = graph.beginTransaction( KernelTransaction.Type.explicit )
try { try {
executeWithRulePlanner("match (a) where id(a) = {id} set a.foo = 'bar' return a","id"->"0") executeWithRulePlanner("match (a) where id(a) = {id} set a.foo = 'bar' return a","id"->"0")
} catch { } catch {
Expand Down
Expand Up @@ -22,6 +22,7 @@ package org.neo4j.cypher.internal
import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.kernel.NeoStoreDataSource import org.neo4j.kernel.NeoStoreDataSource
import org.neo4j.kernel.api.KernelTransaction
import org.neo4j.test.TestGraphDatabaseFactory import org.neo4j.test.TestGraphDatabaseFactory
import org.scalatest.BeforeAndAfterAll import org.scalatest.BeforeAndAfterAll


Expand Down Expand Up @@ -57,7 +58,7 @@ class LastCommittedTxIdProviderTest extends CypherFunSuite with BeforeAndAfterAl
} }


private def createNode(): Unit = { private def createNode(): Unit = {
val tx = db.beginTx() val tx = db.beginTransaction( KernelTransaction.Type.explicit )
try { try {
db.createNode() db.createNode()
tx.success() tx.success()
Expand Down
Expand Up @@ -40,6 +40,7 @@ import org.neo4j.cypher.{ExecutionEngineFunSuite, NewPlannerTestSupport, QuerySt
import org.neo4j.graphdb.factory.GraphDatabaseFactory import org.neo4j.graphdb.factory.GraphDatabaseFactory
import org.neo4j.helpers.Clock import org.neo4j.helpers.Clock
import org.neo4j.kernel.GraphDatabaseQueryService import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.impl.coreapi.InternalTransaction
import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors}


import scala.xml.Elem import scala.xml.Elem
Expand Down Expand Up @@ -540,14 +541,14 @@ class CompilerComparisonTest extends ExecutionEngineFunSuite with QueryStatistic
private def runQueryWith(query: String, compiler: CypherCompiler, db: GraphDatabaseQueryService): (List[Map[String, Any]], InternalExecutionResult) = { private def runQueryWith(query: String, compiler: CypherCompiler, db: GraphDatabaseQueryService): (List[Map[String, Any]], InternalExecutionResult) = {
val (plan: ExecutionPlan, parameters) = db.withTx { val (plan: ExecutionPlan, parameters) = db.withTx {
tx => tx =>
val transactionalContext = new Neo4jTransactionContext(db, tx, true, db.statement) val transactionalContext = new Neo4jTransactionContext(db, tx, db.statement)
val planContext = new TransactionBoundPlanContext(transactionalContext) val planContext = new TransactionBoundPlanContext(transactionalContext)
compiler.planQuery(query, planContext, devNullLogger) compiler.planQuery(query, planContext, devNullLogger)
} }


db.withTx { db.withTx {
tx => tx =>
val transactionalContext = new Neo4jTransactionContext(db, tx, true, db.statement) val transactionalContext = new Neo4jTransactionContext(db, tx, db.statement)
val queryContext = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor) val queryContext = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor)
val result = plan.run(queryContext, ProfileMode, parameters) val result = plan.run(queryContext, ProfileMode, parameters)
(result.toList, result) (result.toList, result)
Expand Down
Expand Up @@ -22,15 +22,17 @@ package org.neo4j.cypher.internal.compiler.v3_0
import commands.expressions.Literal import commands.expressions.Literal
import org.neo4j.cypher.ExecutionEngineFunSuite import org.neo4j.cypher.ExecutionEngineFunSuite
import org.neo4j.cypher.internal.compiler.v3_0.mutation.CreateNode import org.neo4j.cypher.internal.compiler.v3_0.mutation.CreateNode
import org.neo4j.graphdb.Node import org.neo4j.graphdb.{Transaction, Node}
import org.neo4j.kernel.api.KernelTransaction


class CreateNodeActionTest extends ExecutionEngineFunSuite { class CreateNodeActionTest extends ExecutionEngineFunSuite {


test("demixed types are not ok") { test("demixed types are not ok") {
val action = CreateNode("id", Map("*" -> Literal(Map("name" -> "Andres", "age" -> 37))), Seq.empty) val action = CreateNode("id", Map("*" -> Literal(Map("name" -> "Andres", "age" -> 37))), Seq.empty)


val id = graph.inTx { val id = graph.inTx {
val vec = action.exec(ExecutionContext.empty, QueryStateHelper.queryStateFrom(graph, graph.beginTx())).toVector val tx = graph.beginTransaction( KernelTransaction.Type.explicit )
val vec = action.exec(ExecutionContext.empty, QueryStateHelper.queryStateFrom(graph, tx)).toVector
vec.head("id").asInstanceOf[Node].getId vec.head("id").asInstanceOf[Node].getId
} }


Expand Down
Expand Up @@ -21,6 +21,8 @@ package org.neo4j.cypher.internal.compiler.v3_0


import java.util import java.util


import org.neo4j.kernel.api.KernelTransaction

import collection.JavaConverters._ import collection.JavaConverters._
import org.neo4j.cypher.GraphDatabaseFunSuite import org.neo4j.cypher.GraphDatabaseFunSuite
import org.neo4j.cypher.internal.compiler.v3_0.commands.expressions.{Variable, ParameterExpression} import org.neo4j.cypher.internal.compiler.v3_0.commands.expressions.{Variable, ParameterExpression}
Expand All @@ -38,7 +40,7 @@ class CreateRelationshipTest extends GraphDatabaseFunSuite {
val bEndNode = RelationshipEndpoint(Variable("b"), Map(), Seq.empty) val bEndNode = RelationshipEndpoint(Variable("b"), Map(), Seq.empty)
val relCreator = new CreateRelationship("r", aEndNode, bEndNode, "RELTYPE", Map("*" -> ParameterExpression("props"))) val relCreator = new CreateRelationship("r", aEndNode, bEndNode, "RELTYPE", Map("*" -> ParameterExpression("props")))


val tx = graph.beginTx() val tx = graph.beginTransaction( KernelTransaction.Type.explicit )
try { try {
val state = QueryStateHelper.queryStateFrom(graph, tx, props) val state = QueryStateHelper.queryStateFrom(graph, tx, props)
val ctx = ExecutionContext.from("a" -> a, "b" -> b) val ctx = ExecutionContext.from("a" -> a, "b" -> b)
Expand Down
Expand Up @@ -28,12 +28,7 @@ import org.neo4j.cypher.internal.frontend.v3_0.SemanticDirection
import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite import org.neo4j.cypher.internal.frontend.v3_0.test_helpers.CypherFunSuite
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb._ import org.neo4j.graphdb._
import org.neo4j.graphdb.event.{KernelEventHandler, TransactionEventHandler} import org.neo4j.kernel.api.KernelTransaction
import org.neo4j.graphdb.index.IndexManager
import org.neo4j.graphdb.schema.Schema
import org.neo4j.graphdb.traversal.{BidirectionalTraversalDescription, TraversalDescription}
import org.neo4j.kernel.impl.store.StoreId
import org.neo4j.kernel.internal.GraphDatabaseAPI
import org.neo4j.test.TestGraphDatabaseFactory import org.neo4j.test.TestGraphDatabaseFactory


import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
Expand Down Expand Up @@ -72,13 +67,13 @@ class DoubleCheckCreateUniqueTest extends CypherFunSuite {
} }


private def withQueryState(f: QueryState => Unit) { private def withQueryState(f: QueryState => Unit) {
val tx = db.beginTx() val tx = db.beginTransaction( KernelTransaction.Type.explicit )
f(QueryStateHelper.queryStateFrom(db, tx)) f(QueryStateHelper.queryStateFrom(db, tx))
tx.close() tx.close()
} }


private def createNode(): Node = { private def createNode(): Node = {
val tx = db.beginTx() val tx = db.beginTransaction( KernelTransaction.Type.explicit )
try { try {
val n = db.createNode() val n = db.createNode()
tx.success() tx.success()
Expand Down
Expand Up @@ -29,26 +29,26 @@ import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer import org.mockito.stubbing.Answer
import org.neo4j.collection.primitive.PrimitiveLongIterator import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.neo4j.cypher._ import org.neo4j.cypher._
import org.neo4j.cypher.internal.{ExecutionResult, ExecutionEngine, ExecutionPlan}
import org.neo4j.cypher.internal.compiler.v3_0.commands.expressions.{Literal, Variable} import org.neo4j.cypher.internal.compiler.v3_0.commands.expressions.{Literal, Variable}
import org.neo4j.cypher.internal.compiler.v3_0.commands.predicates.{GreaterThan, True} import org.neo4j.cypher.internal.compiler.v3_0.commands.predicates.{GreaterThan, True}
import org.neo4j.cypher.internal.compiler.v3_0.helpers.{CountingIterator, Counter} import org.neo4j.cypher.internal.compiler.v3_0.helpers.{Counter, CountingIterator}
import org.neo4j.cypher.internal.compiler.v3_0.pipes._ import org.neo4j.cypher.internal.compiler.v3_0.pipes._
import org.neo4j.cypher.internal.compiler.v3_0.pipes.matching._ import org.neo4j.cypher.internal.compiler.v3_0.pipes.matching._
import org.neo4j.cypher.internal.compiler.v3_0.planDescription.Argument import org.neo4j.cypher.internal.compiler.v3_0.planDescription.Argument
import org.neo4j.cypher.internal.frontend.v3_0.SemanticDirection import org.neo4j.cypher.internal.frontend.v3_0.SemanticDirection
import org.neo4j.cypher.internal.frontend.v3_0.symbols.CTInteger import org.neo4j.cypher.internal.frontend.v3_0.symbols.CTInteger
import org.neo4j.cypher.internal.spi.v3_0.MonoDirectionalTraversalMatcher import org.neo4j.cypher.internal.spi.v3_0.MonoDirectionalTraversalMatcher
import org.neo4j.cypher.internal.{ExecutionEngine, ExecutionPlan, ExecutionResult}
import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService import org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService
import org.neo4j.graphdb._ import org.neo4j.graphdb._
import org.neo4j.kernel.api.{ReadOperations, Statement} import org.neo4j.kernel.api.{KernelTransaction, ReadOperations, Statement}
import org.neo4j.kernel.configuration.Config import org.neo4j.kernel.configuration.Config
import org.neo4j.kernel.impl.api.OperationsFacade import org.neo4j.kernel.impl.api.OperationsFacade
import org.neo4j.kernel.impl.core.{NodeManager, NodeProxy, ThreadToStatementContextBridge} import org.neo4j.kernel.impl.core.{NodeManager, NodeProxy, ThreadToStatementContextBridge}
import org.neo4j.kernel.impl.query.QueryEngineProvider import org.neo4j.kernel.impl.coreapi.InternalTransaction
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade
import org.neo4j.kernel.impl.query.QueryEngineProvider.embeddedSession import org.neo4j.kernel.impl.query.QueryEngineProvider.embeddedSession
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore import org.neo4j.kernel.impl.transaction.log.TransactionIdStore
import org.neo4j.kernel.internal.GraphDatabaseAPI


// TODO: this test is horribly broken, it relies on mocking the core API for verification, but the internals don't use the core API // TODO: this test is horribly broken, it relies on mocking the core API for verification, but the internals don't use the core API
class LazyTest extends ExecutionEngineFunSuite { class LazyTest extends ExecutionEngineFunSuite {
Expand Down Expand Up @@ -90,7 +90,7 @@ class LazyTest extends ExecutionEngineFunSuite {


test("traversal matcher is lazy") { test("traversal matcher is lazy") {
//Given: //Given:
val tx = graph.beginTx() val tx = graph.beginTransaction( KernelTransaction.Type.explicit )
val limiter = Counter().values.limit(2) { _ => fail("Limit reached!") } val limiter = Counter().values.limit(2) { _ => fail("Limit reached!") }
val monitoredNode = new MonitoredNode(aNode, limiter.tick) val monitoredNode = new MonitoredNode(aNode, limiter.tick)


Expand Down Expand Up @@ -190,8 +190,8 @@ class LazyTest extends ExecutionEngineFunSuite {


test("graph global queries are lazy") { test("graph global queries are lazy") {
//Given: //Given:
val fakeGraph = mock[GraphDatabaseAPI] val fakeGraph = mock[GraphDatabaseFacade]
val tx = mock[Transaction] val tx = mock[InternalTransaction]
val nodeManager = mock[NodeManager] val nodeManager = mock[NodeManager]
val dependencies = mock[DependencyResolver] val dependencies = mock[DependencyResolver]
val bridge = mock[ThreadToStatementContextBridge] val bridge = mock[ThreadToStatementContextBridge]
Expand All @@ -216,7 +216,7 @@ class LazyTest extends ExecutionEngineFunSuite {
when(dependencies.resolveDependency(classOf[TransactionIdStore])).thenReturn(idStore) when(dependencies.resolveDependency(classOf[TransactionIdStore])).thenReturn(idStore)
when(dependencies.resolveDependency(classOf[org.neo4j.kernel.monitoring.Monitors])).thenReturn(monitors) when(dependencies.resolveDependency(classOf[org.neo4j.kernel.monitoring.Monitors])).thenReturn(monitors)
when(dependencies.resolveDependency(classOf[Config])).thenReturn(config) when(dependencies.resolveDependency(classOf[Config])).thenReturn(config)
when(fakeGraph.beginTx()).thenReturn(tx) when(fakeGraph.beginTransaction(any(classOf[KernelTransaction.Type]))).thenReturn(tx)
val n0 = mock[Node] val n0 = mock[Node]
val n1 = mock[Node] val n1 = mock[Node]
val n2 = mock[Node] val n2 = mock[Node]
Expand All @@ -227,7 +227,7 @@ class LazyTest extends ExecutionEngineFunSuite {
val nodesIterator = List( n0, n1, n2, n3, n4, n5, n6 ).iterator val nodesIterator = List( n0, n1, n2, n3, n4, n5, n6 ).iterator
val allNodeIdsIterator = new PrimitiveLongIterator { val allNodeIdsIterator = new PrimitiveLongIterator {
override def hasNext = nodesIterator.hasNext override def hasNext = nodesIterator.hasNext
override def next() = nodesIterator.next().getId() override def next() = nodesIterator.next().getId
} }
when(fakeReadStatement.nodesGetAll).thenReturn(allNodeIdsIterator) when(fakeReadStatement.nodesGetAll).thenReturn(allNodeIdsIterator)


Expand All @@ -251,7 +251,7 @@ class LazyTest extends ExecutionEngineFunSuite {


test("traversalmatcherpipe is lazy") { test("traversalmatcherpipe is lazy") {
//Given: //Given:
val tx = graph.beginTx() val tx = graph.beginTransaction( KernelTransaction.Type.explicit )
val limiter = Counter().values.limit(2) { _ => fail("Limit reached") } val limiter = Counter().values.limit(2) { _ => fail("Limit reached") }
val traversalMatchPipe = createTraversalMatcherPipe(limiter) val traversalMatchPipe = createTraversalMatcherPipe(limiter)


Expand Down

0 comments on commit 6616bcc

Please sign in to comment.