PageRenderTime 35ms CodeModel.GetById 17ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

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