java - Inconsistent Transaction behavior in Appengine Local Datastore? -


the appengine docs transactions in datastore: http://code.google.com/appengine/docs/java/datastore/transactions.html#isolation_and_consistency

in transaction, reads reflect current, consistent state of  datastore @ time transaction started. not include previous puts , deletes inside transaction. queries , gets inside transaction guaranteed see single, consistent snapshot of datastore of beginning of transaction. 

with in mind, have created following 2 unit tests test (against local datastore). expecte both of tests below pass. however, "test1" passes, whereas "test2" fails. difference commit of tx1 in "test1".

is bug in local datastore, misunderstanding of gae docs, or bug in unit tests? or else?

thanks!

@test(expected = entitynotfoundexception.class) public void test1() throws entitynotfoundexception {     datastoreservice datastore = datastoreservicefactory.getdatastoreservice();      // create 2 transactions...     transaction txn1 = datastore.begintransaction();     transaction txn2 = datastore.begintransaction();      try {         key entitywithstringkey = keyfactory.createkey("testentity", "test");         entity entitywithstring = new entity(entitywithstringkey);         datastore.put(txn1, entitywithstring);          entitywithstring = datastore.get(txn2, entitywithstringkey);         // above should throw entitynotfoundexception         assertnull(entitywithstring);     }     {         if (txn1.isactive()) {         txn1.rollback();     }      if (txn2.isactive()) {             txn2.rollback();     } }   @test(expected = entitynotfoundexception.class) public void test2() throws entitynotfoundexception {     datastoreservice datastore = datastoreservicefactory.getdatastoreservice();      // create 2 transactions...     transaction txn1 = datastore.begintransaction();     transaction txn2 = datastore.begintransaction();      key entitywithstringkey = keyfactory.createkey("testentity", "test");      try {         entity entitywithstring = new entity(entitywithstringkey);         datastore.put(txn1, entitywithstring);         txn1.commit();     } {      if (txn1.isactive()) {         txn1.rollback();     }     }      try {         entity entitywithstring = datastore.get(txn2, entitywithstringkey);         assertnull(entitywithstring);         // above should throw entitynotfoundexception     }      {         if (txn2.isactive()) {             txn2.rollback();         }     } } 

i suspect transaction doesn't begin when when call datastore.begintransaction - begins when transaction first hits database - optimal way minimize locks on database side.

in test 2, can try putting in additional get() on txn2, before txn1.commit(). second get() (where txn2 get) should return null.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -