Skip to content

Instantly share code, notes, and snippets.

@jasonmay
Last active December 15, 2015 03:09
Show Gist options
  • Save jasonmay/5192101 to your computer and use it in GitHub Desktop.
Save jasonmay/5192101 to your computer and use it in GitHub Desktop.
object Universe extends App {
val proc = new RequestProcessor()
val service_proc = new thrift.LocRequestService.Processor(proc)
val serverTransport: TServerTransport = new TServerSocket(MY_PORT);
val server: TServer = new TSimpleServer(new TServer.Args(serverTransport).processor(service_proc));
// ...
server.serve();
}
}
// ...
object TestThrift extends App {
import collection.JavaConversions._
def apply() = {
val transport: TTransport = new TSocket("localhost", MY_PORT);
transport.open();
val protocol: TProtocol = new TBinaryProtocol(transport);
val client: thrift.LocRequestService.Client = new thrift.LocRequestService.Client(protocol)
// Prepare the "test" request
val req: thrift.LocReadRequest = new thrift.LocReadRequest()
val myid = "start:church"
req.id = Set(myid)
req.props = mutable.Map(
thrift.LocProp.PROP -> setAsJavaSet(Set("title", "description")),
thrift.LocProp.EXIT -> setAsJavaSet(Set("n"))
)
// Invoke the "test" request
val res: thrift.LocReadResponse = client.readRequest(req)
Option(res.locs.get(myid)) map { loc =>
println(loc.props.get("title"))
println(loc.props.get("description"))
println()
println("North exit: " + loc.exits.get(thrift.ExitProp.NORTH))
if (loc.exits.get(thrift.ExitProp.SOUTH) != null) {
println("Failed to exclude south exit!")
}
} getOrElse { println("Location not found!") }
transport.close();
}
}
map <leader>su :silent let __run=system("(svc -d ~/.services/neptune/universe; sleep 1; svc -o ~/.services/neptune/universe) 2>&1 > /dev/null")<cr>:redraw!<cr>
map <leader>st :silent let __run=system("(svc -d ~/.services/neptune/test; sleep 1; svc -o ~/.services/neptune/test) 2>&1 > /dev/null")<cr>:redraw!<cr>
# in ~/.services/neptune/test/run
exec sbt 'run-main org.jarsonmar.neptune.TestThrift'
# in ~/.services/neptune/universe/run
exec sbt 'run-main org.jarsonmar.neptune.Universe'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment