Monday, 15 July 2013

java - Sharing Memcached between Jetty Instances -



java - Sharing Memcached between Jetty Instances -

i'm writing integration tests against google app engine project running on local jetty instance.

before running tests, spawn new instance of gae web service @ http://localhost:8083. on startup, web service creates memcached instance write info to. we're using google guice, done binding looks this:

bind(asyncmemcacheservice.class).toinstance(memcacheservicefactory.getasyncmemcacheservice()); bind(memcacheservice.class).toinstance(memcacheservicefactory.getmemcacheservice());

once web service , running, start integration tests. crucially, started on separate jetty instance creates own memcached bindings.

i've written integration test looks following:

@test(groups = "integration") private void dosometest() { //set precondition test string id = "myintegerobject"; this.memcached.putsomeobject(id, 0); seek { //call endpoint relies on set value string url = "http://localhost:8083/api/increment/" + id; this.http.post(url); } grab (exception e) { e.printstacktrace(); assert.fail("test failed. see inner exception details.", e); } //verify hitting url had desired effect assert.assertequals(this.memcached.getsomeobject(id), 1); }

this test fails on assert.assertequals(...); line, because web service , integration test writing different instances of memcached.

is there way set system-wide memcached instance web service, unit tests, , integration tests share?

would remote api work here? while it's intended allow connect production appspot.com app, can utilize connect local dev_appserver:

new remoteapioptions().server("localhost", 8083).credentials("test@example.com", "");

any api calls create utilize remote api access other instance. note, remote api not restricted datastore api docs suggests. memcache works in same way.

i created example eclipse project both 'hello world' app engine app, can deploy or run locally, , trivial testclient.java, utilize remote api perform remote memcache get() , put() calls:

$ java client.testclient localhost 8083 test@example.com pass foo bar new remoteapioptions() .server("localhost", 8083) .credentials("test@example.com", "pass") mc.get("foo") -> null mc.put("foo", "bar") mc.get("foo") -> bar

java google-app-engine memcached jetty guice

No comments:

Post a Comment