AT EXIT behavior
alesj Sep 4, 2014 9:34 AMI'm trying to run some concurrency tx tests for GAE TCK.
With GAE you're only allowed that one tx handles same entity group.
(think of entity group as a table, for now)
I have this rules:
@BMRules({
@BMRule(
name = "entry",
targetClass = "com.google.appengine.tck.byteman.support.ConcurrentTxServlet",
targetMethod = "putEntity",
targetLocation = "AT EXIT",
action = "waitFor(\"cleanup\")"),
@BMRule(
name = "exit",
targetClass = "com.google.appengine.tck.byteman.support.ConcurrentTxServlet",
targetMethod = "cleanup",
action = "signalWake(\"cleanup\", true)"),
}
)
and this is the relevant code.
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String entityGroup = req.getParameter("eg");
String counter = req.getParameter("c");
Entity entity = new Entity(entityGroup);
entity.setProperty("foo", RANDOM.nextInt());
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
final Transaction tx = ds.beginTransaction();
try {
putEntity(ds, entity);
tx.commit();
resp.getWriter().write("OK" + counter);
} catch (Exception e) {
tx.rollback();
resp.getWriter().write("ERROR" + counter + ":" + e.getClass());
} finally {
cleanup(counter);
}
}
private void putEntity(DatastoreService ds, Entity entity) throws IOException {
ds.put(entity);
}
private void cleanup(String counter) {
log("Counter = " + counter);
}
So, I expect the first rule to block first thread,
until a second thread arrives and fails - due to dup tx on same entity group.
And the in the 2nd rule, the failed thread should signal to the first blocked thread that it can now proceed.
The question is -- is this OK / gonna work?
Or will 1st rule's "AT EXIT" also catch 2nd failing thread and make it wait -- probably forever.
Or how to do this?
Thanks.