Permalink
Browse files

Fixes problem when the Cypher parser is run concurrently

  • Loading branch information...
1 parent c07b712 commit c7cea947584124533c69ea191eb5c69c31f30667 @systay committed Sep 20, 2012
@@ -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)
@@ -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)

0 comments on commit c7cea94

Please sign in to comment.