/tests/com/google/appengine/datanucleus/jdo/Issue179Test.java

http://datanucleus-appengine.googlecode.com/ · Java · 70 lines · 44 code · 7 blank · 19 comment · 0 complexity · f27ea3274c715a6c3a1f65b50c3d8e7e MD5 · raw file

  1. /**********************************************************************
  2. Copyright (c) 2011 Google Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. **********************************************************************/
  13. package com.google.appengine.datanucleus.jdo;
  14. import org.datanucleus.util.NucleusLogger;
  15. import com.google.appengine.datanucleus.test.jdo.Issue179Child;
  16. import com.google.appengine.datanucleus.test.jdo.Issue179Parent;
  17. public class Issue179Test extends JDOTestCase {
  18. public void testListRemoveByIndex() {
  19. Issue179Parent p = new Issue179Parent();
  20. p.setName("First Parent");
  21. Issue179Child c1 = new Issue179Child();
  22. c1.setName("Child 1");
  23. p.getChildren().add(c1);
  24. Issue179Child c2 = new Issue179Child();
  25. c2.setName("Child 2");
  26. p.getChildren().add(c2);
  27. Issue179Child c3 = new Issue179Child();
  28. c3.setName("Child 3");
  29. p.getChildren().add(c3);
  30. // Persist parent with 3 children
  31. Object id = null;
  32. beginTxn();
  33. pm.makePersistent(p);
  34. commitTxn();
  35. id = pm.getObjectId(p);
  36. pm.close();
  37. // Remove one-by-one in a transaction
  38. // This highlights a problem that once the first is deleted the datastore doesn't know about that deletion (til commit)
  39. pm = pmf.getPersistenceManager();
  40. NucleusLogger.GENERAL.debug(">> tx.begin");
  41. beginTxn();
  42. NucleusLogger.GENERAL.debug(">> pm.getObjectById(parent)");
  43. Issue179Parent p1 = (Issue179Parent)pm.getObjectById(id);
  44. NucleusLogger.GENERAL.debug(">> parent.children.remove(0)");
  45. p1.getChildren().remove(0);
  46. NucleusLogger.GENERAL.debug(">> parent.children.remove(0)");
  47. p1.getChildren().remove(0);
  48. NucleusLogger.GENERAL.debug(">> parent.children.remove(0)");
  49. p1.getChildren().remove(0);
  50. NucleusLogger.GENERAL.debug(">> tx.commit");
  51. commitTxn();
  52. pm.close();
  53. // The child list in the parent is actually correct here, just the query of the child objects with a parent is wrong
  54. pm = pmf.getPersistenceManager();
  55. beginTxn();
  56. Issue179Parent p2 = (Issue179Parent)pm.getObjectById(id);
  57. assertEquals(0, p2.getChildren().size());
  58. commitTxn();
  59. }
  60. }