001: /*
002: * TestIncrementalFlushesDeletes.java
003: *
004: * Created on October 12, 2006, 11:38 AM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: /*
011: * Licensed to the Apache Software Foundation (ASF) under one
012: * or more contributor license agreements. See the NOTICE file
013: * distributed with this work for additional information
014: * regarding copyright ownership. The ASF licenses this file
015: * to you under the Apache License, Version 2.0 (the
016: * "License"); you may not use this file except in compliance
017: * with the License. You may obtain a copy of the License at
018: *
019: * http://www.apache.org/licenses/LICENSE-2.0
020: *
021: * Unless required by applicable law or agreed to in writing,
022: * software distributed under the License is distributed on an
023: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
024: * KIND, either express or implied. See the License for the
025: * specific language governing permissions and limitations
026: * under the License.
027: */
028: package org.apache.openjpa.persistence.kernel;
029:
030: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
031:
032: import org.apache.openjpa.kernel.OpenJPAStateManager;
033: import org.apache.openjpa.kernel.PCState;
034: import org.apache.openjpa.persistence.OpenJPAEntityManager;
035:
036: public class TestIncrementalFlushesDeletes extends BaseKernelTest {
037:
038: private OpenJPAEntityManager pm;
039: private Object oid;
040: private RuntimeTest1 a;
041:
042: public TestIncrementalFlushesDeletes(String str) {
043: super (str);
044: }
045:
046: /**
047: * Creates a new instance of TestIncrementalFlushesDeletes
048: */
049: public TestIncrementalFlushesDeletes() {
050: }
051:
052: public void setUp() {
053: deleteAll(RuntimeTest1.class);
054:
055: pm = getPM(true, false);
056: startTx(pm);
057: a = new RuntimeTest1("foo", 10);
058: pm.persist(a);
059: oid = pm.getObjectId(a);
060: }
061:
062: public void tearDown() throws Exception {
063: endTx(pm);
064:
065: OpenJPAEntityManager newPm = getPM();
066: try {
067: Object o = newPm.find(RuntimeTest1.class, oid);
068: if (o != null) {
069: fail("should not be able to load deleted object");
070: }
071: } catch (Exception e) {
072: // expected case
073: }
074:
075: endEm(newPm);
076: endEm(pm);
077:
078: super .tearDown();
079: }
080:
081: private void assertState(PCState state, boolean flushed) {
082: OpenJPAStateManager sm = getStateManager(a, pm);
083: assertNotNull(sm);
084: assertEquals(flushed, sm.isFlushed());
085: assertEquals(state, sm.getPCState());
086: }
087:
088: /**
089: * PNew => PNewDeleted
090: */
091: public void testNewDeleted() {
092: pm.remove(a);
093: assertState(PCState.PNEWDELETED, false);
094: }
095:
096: /**
097: * PNew => PNewDeleted => PNewDeletedFlushed
098: */
099: public void testNewDeletedFlushed() {
100: pm.remove(a);
101: assertState(PCState.PNEWDELETED, false);
102: pm.flush();
103: assertState(PCState.PNEWDELETED, true);
104: }
105:
106: /**
107: * PNew => PNewFlushed => PNewFlushedDeleted
108: */
109: public void testNewFlushedDeleted() {
110: pm.flush();
111: assertState(PCState.PNEW, true);
112: pm.remove(a);
113: assertState(PCState.PNEWFLUSHEDDELETED, true);
114: }
115:
116: /**
117: * PNew => PNewFlushed => PNewFlushedDeleted => PNewFlushedDeletedFlushed
118: */
119: public void testNewFlushedDeletedFlushed() {
120: pm.flush();
121: assertState(PCState.PNEW, true);
122: pm.remove(a);
123: assertState(PCState.PNEWFLUSHEDDELETED, true);
124: pm.flush();
125: assertState(PCState.PNEWFLUSHEDDELETEDFLUSHED, true);
126: }
127:
128: /*
129: * ### some remaining test deletes:
130: * PDirty => PDeleted => PDeletedFlushed
131: * PDirty => (change and flush) PDirty => PDeleted => PDeletedFlushed
132: * PClean => PDeleted => PDeletedFlushed
133: * Hollow => PDeleted => PDeletedFlushed
134: */
135: }
|