Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
koans compile in a seperate process with communication via rabbitmq
- Loading branch information
Showing
7 changed files
with
127 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,9 +1,10 @@ | |||
logs | /logs | ||
project/project | /project/project | ||
project/target | /project/target | ||
target | /target | ||
tmp | /tmp | ||
.history | /.history | ||
dist | /dist | ||
.idea | /.idea | ||
*.iml | /*.iml | ||
/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
import com.rabbitmq.client.AMQP.BasicProperties | |||
import com.rabbitmq.client.{GetResponse, Channel, ConnectionFactory} | |||
import messaging.MessageBus | |||
import play.api.GlobalSettings | |||
|
|||
import play.api.Application | |||
|
|||
object Global extends GlobalSettings { | |||
|
|||
override def onStart(app: Application) { | |||
|
|||
app.configuration.getString("rabbitmq.uri") map { uri => | |||
MessageBus.setup(uri) | |||
} getOrElse { | |||
sys.error("No rabbitmq.uri specified") | |||
} | |||
|
|||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
package koanrunner | |||
|
|||
import messaging.MessageBus | |||
import util.Properties | |||
import com.rabbitmq.client.StringRpcServer | |||
import support.KoanSuite | |||
import com.twitter.util.Eval | |||
import org.scalatest.{Filter, Tracker, Stopper} | |||
import com.codahale.jerkson.Json | |||
|
|||
import scala.collection.mutable.Map | |||
|
|||
object KoanRunner extends App { | |||
|
|||
Properties.envOrNone("RABBITMQ_URL") map { uri => | |||
|
|||
MessageBus.setup(uri) | |||
|
|||
val server: StringRpcServer = new StringRpcServer(MessageBus.channel, MessageBus.queueName) { | |||
override def handleStringCall(request: String) = { | |||
println("received: " + request) | |||
|
|||
val suite = Eval[KoanSuite](request) | |||
|
|||
val results = Map[String, TestResult]() | |||
|
|||
suite.run(None, new KoanReporter(results), new Stopper {}, Filter(), scala.collection.immutable.Map[String, Any](), None, new Tracker) | |||
|
|||
val json = Json.generate(results) | |||
println("returning: " + json) | |||
json | |||
} | |||
} | |||
|
|||
server.mainloop() | |||
|
|||
} getOrElse { | |||
sys.error("RABBITMQ_URL environment variable not found") | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
package messaging | |||
|
|||
import com.rabbitmq.client.AMQP.BasicProperties | |||
import com.rabbitmq.client.{RpcClient, ConnectionFactory, StringRpcServer, Channel} | |||
|
|||
|
|||
object MessageBus { | |||
|
|||
val exchangeName: String = "koan-exchange" | |||
val routingKey: String = "koan-routing-key" | |||
val exchangeType: String = "direct" | |||
val timeout = 20000 | |||
|
|||
var channel: Channel = _ | |||
var queueName: String = _ | |||
|
|||
def setup(uri: String) { | |||
val factory = new ConnectionFactory() | |||
factory.setUri(uri) | |||
|
|||
val conn = factory.newConnection() | |||
channel = conn.createChannel() | |||
channel.exchangeDeclare(exchangeName, exchangeType, true) | |||
queueName = channel.queueDeclare().getQueue | |||
channel.queueBind(queueName, exchangeName, routingKey) | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c6b408e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, James!