Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mpollmeier committed Jun 14, 2021
1 parent 27a6c3b commit d9014e5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class EmbeddedAmmonite(predef: String = "") {
* */
def queryAsync(q: String)(observer: QueryResult => Unit): UUID = {
val uuid = UUID.randomUUID()
// println(s"adding job to queue: ${q}")
jobQueue.add(Job(uuid, q, observer))
uuid
}
Expand All @@ -80,10 +79,8 @@ class EmbeddedAmmonite(predef: String = "") {
var result: QueryResult = null
queryAsync(q) { r =>
result = r
// println("EmbeddedAmmonite.query: mutex.release")
mutex.release()
}
// println("EmbeddedAmmonite.query: mutex.acquire")
mutex.acquire()
result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class UserRunnable(queue: BlockingQueue[Job], writer: PrintWriter, reader: Buffe
}

private def sendQueryToAmmonite(job: Job): Unit = {
println(s"sendQueryToAmmonite: ${job.query.trim} =========")
writer.println(job.query.trim)
writer.println(s""""END: ${job.uuid}"""")
writer.println(s"""throw new RuntimeException("END: ${job.uuid}")""")
Expand All @@ -52,12 +51,7 @@ class UserRunnable(queue: BlockingQueue[Job], writer: PrintWriter, reader: Buffe

private def stdOutUpToMarker(): Option[String] = {
var currentOutput: String = ""
println("UserRunnable: reader.readLine()")
var line = reader.readLine()
println(s"line=${line.toCharArray.toSeq.map(_.toInt)}") // magic echo seq...
// val substr = line.substring(magicEchoSeq.size)
// println(substr.toCharArray.toSeq.map(_.toInt))
// println(substr.map(_.toChar))
while (line != null) {
if (!line.startsWith(magicEchoSeq) && !line.isEmpty) {
val uuid = uuidFromLine(line)
Expand All @@ -73,7 +67,6 @@ class UserRunnable(queue: BlockingQueue[Job], writer: PrintWriter, reader: Buffe
}

private def uuidFromLine(line: String): Iterator[UUID] = {
// println(s"uuidFromLine: ${line.toCharArray.toSeq.map(_.toInt)}")
endMarker.findAllIn(line).matchData.flatMap { m =>
Try { UUID.fromString(m.group(1)) }.toOption
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@ class CPGQLServerTests extends AnyWordSpec with Matchers {
ujson.read(getResponse.bytes)
}

"foo1" in Fixture() { host =>
val webSocketTextMsg = scala.concurrent.Promise[String]()
cask.util.WsClient.connect(s"$host/connect") {
case cask.Ws.Text(msg) => webSocketTextMsg.success(msg)
}
val wsMsg = Await.result(webSocketTextMsg.future, DefaultPromiseAwaitTimeout)
wsMsg shouldBe "connected"
}

// copy of "allow posting a simple query without any websocket connections established" in Fixture() { host =>
"foo2" in Fixture() { host =>
val postQueryResponse = postQuery(host, "1")
postQueryResponse.obj.keySet should contain("success")
val UUIDResponse = postQueryResponse("uuid").str
UUIDResponse should not be empty
postQueryResponse("success").bool shouldBe true
}


"CPGQLServer" should {

"allow websocket connections to the `/connect` endpoint" in Fixture() { host =>
Expand Down Expand Up @@ -228,23 +209,11 @@ object Fixture {
.setHandler(ammServer.defaultHandler)
.build
server.start()
// val res =
// try {
// f(httpEndpoint)
// } finally {
// server.stop()
// println("XXXX0")
// val res0 = ammonite.shutdown()
// println("XXXX1")
// res0
// }
// println("XXXX2")
// res
val res = f(httpEndpoint)
Thread.sleep(1000)
server.stop()
Thread.sleep(1000)
ammonite.shutdown()
val res =
try { f(httpEndpoint) } finally {
server.stop()
ammonite.shutdown()
}
res
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EmbeddedAmmoniteTests extends AnyWordSpec with Matchers {
"execute a command synchronously" in {
val shell = new EmbeddedAmmonite()
shell.start()
val result = shell.query("def foo() = {1} \n foo()")
val result = shell.query("def foo() = {\n1\n}\n foo()")
result.out shouldBe
"""defined function foo
|res1: Int = 1
Expand Down

0 comments on commit d9014e5

Please sign in to comment.