Skip to content

Commit

Permalink
Fixes problem when the Cypher parser is run concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
systay committed Sep 20, 2012
1 parent c07b712 commit c7cea94
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cypher/src/main/scala/org/neo4j/cypher/CypherParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CypherParser(version: String) {
val v19 = new internal.parser.v1_9.CypherParserImpl

@throws(classOf[SyntaxException])
def parse(queryText: String): Query = {
def parse(queryText: String): Query = synchronized {

val (v, q) = queryText match {
case hasVersionDefined(v1, q1) => (v1, q1)
Expand Down
33 changes: 33 additions & 0 deletions cypher/src/test/scala/org/neo4j/cypher/CypherParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,39 @@ foreach(x in [1,2,3] :
))
}

@Ignore("slow test") @Test def multi_thread_parsing() {
val q = """start root=node(0) return x"""
val parser = new CypherParser()

val runners = (1 to 10).toList.map(x => {
run(() => parser.parse(q))
})

val threads = runners.map(new Thread(_))
threads.foreach(_.start())
threads.foreach(_.join())

runners.foreach(_.report())
}

private def run(f: () => Unit) =
new Runnable() {
var error: Option[Throwable] = None

def run() {
try {
(1 until 500).foreach(x => f())
} catch {
case e: Throwable => error = Some(e)
}
}

def report() {
error.foreach(e => throw e)
}
}


def test_1_9(query: String, expectedQuery: Query) {
testQuery(None, query, expectedQuery)
testQuery(None, query + ";", expectedQuery)
Expand Down

0 comments on commit c7cea94

Please sign in to comment.