001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.test.transactionisolation.lucene;
018:
019: import org.compass.core.CompassHits;
020: import org.compass.core.CompassSession;
021: import org.compass.core.CompassTransaction;
022: import org.compass.core.config.CompassEnvironment;
023: import org.compass.core.config.CompassSettings;
024: import org.compass.core.spi.InternalCompassSession;
025: import org.compass.core.spi.InternalResource;
026: import org.compass.core.test.AbstractTestCase;
027:
028: /**
029: *
030: * @author kimchy
031: *
032: */
033: public class LuceneTransactionIsolationTests extends AbstractTestCase {
034:
035: protected String[] getMappings() {
036: return new String[] { "transactionisolation/lucene/mapping.cpm.xml" };
037: }
038:
039: protected void addSettings(CompassSettings settings) {
040: super .addSettings(settings);
041: settings.setSetting(CompassEnvironment.Transaction.ISOLATION,
042: CompassEnvironment.Transaction.ISOLATION_LUCENE);
043: }
044:
045: public void testBatch() {
046: CompassSession session = openSession();
047: CompassTransaction tr = session.beginTransaction();
048:
049: Long id = new Long(1);
050: Cyclic1 cyclic1 = new Cyclic1();
051: cyclic1.setId(id);
052: cyclic1.setValue("cyclic1");
053:
054: Cyclic2 cyclic2 = new Cyclic2();
055: cyclic2.setId(id);
056: cyclic2.setValue("cyclic2");
057:
058: cyclic1.setCyclic2(cyclic2);
059: cyclic2.setCyclic1(cyclic1);
060:
061: session.create(cyclic2);
062: session.create(cyclic1);
063:
064: // verify they are not in the first level cache
065: InternalResource key = (InternalResource) getResourceFactory()
066: .createResource("cyclic1");
067: key.addProperty("id", id);
068: Object val = ((InternalCompassSession) session)
069: .getFirstLevelCache().get(key.resourceKey());
070: assertNull(val);
071: key = (InternalResource) getResourceFactory().createResource(
072: "cyclic2");
073: key.addProperty("id", id);
074: val = ((InternalCompassSession) session).getFirstLevelCache()
075: .get(key.resourceKey());
076: assertNull(val);
077:
078: tr.commit();
079:
080: tr = session.beginTransaction();
081:
082: CompassHits hits = session.find("value:cyclic1");
083: assertEquals(1, hits.length());
084: hits = session.find("value:cyclic2");
085: assertEquals(1, hits.length());
086:
087: cyclic2.setValue("updated");
088: session.save(cyclic2);
089: tr.commit();
090:
091: tr = session.beginTransaction();
092: hits = session.find("value:cyclic2");
093: assertEquals(0, hits.length());
094: hits = session.find("value:updated");
095: assertEquals(1, hits.length());
096: tr.commit();
097:
098: tr = session.beginTransaction();
099: cyclic2 = session.load(Cyclic2.class, 1);
100: assertNotNull(cyclic2);
101: tr.commit();
102:
103: tr = session.beginTransaction();
104: session.delete(cyclic2);
105: tr.commit();
106:
107: tr = session.beginTransaction();
108: cyclic2 = session.get(Cyclic2.class, 1);
109: assertNull(cyclic2);
110: tr.commit();
111: }
112: }
|