Google AppEngine + Local JUnit Tests + Jersey framework + Embedded Jetty
- by xamde
I use Google Appengine for Java (GAE/J).
On top, I use the Jersey REST-framework.
Now i want to run local JUnit tests. The test
sets up the local GAE development environment ( http://code.google.com/appengine/docs/java/tools/localunittesting.html ),
launches an embedded Jetty server,
and then fires requests to the server via HTTP and checks responses.
Unfortunately, the Jersey/Jetty combo spawns new threads. GAE expects only one thread to run.
In the end, I end up having either no datstore inside the Jersey-resources or multiple, having different datastore.
As a workaround I initialise the GAE local env only once, put it in a static variable and inside the GAE resource I add many checks (This threads has no dev env? Re-use the static one). And these checks should of course only run inside JUnit tests.. (which I asked before: "How can I find out if code is running inside a JUnit test or not?" - I'm not allowed to post the link directly here :-|)