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.annotations.test.subindexhash;
018:
019: import org.apache.lucene.index.LuceneSubIndexInfo;
020: import org.compass.annotations.test.AbstractAnnotationsTestCase;
021: import org.compass.core.CompassSession;
022: import org.compass.core.CompassTransaction;
023: import org.compass.core.config.CompassConfiguration;
024:
025: /**
026: * @author kimchy
027: */
028: public class SubIndexHashTests extends AbstractAnnotationsTestCase {
029:
030: protected void addExtraConf(CompassConfiguration conf) {
031: conf.addClass(A.class).addClass(B.class);
032: }
033:
034: public void testSingleModuloA() throws Exception {
035: CompassSession session = openSession();
036:
037: LuceneSubIndexInfo subIndexInfo = LuceneSubIndexInfo
038: .getIndexInfo("index_0", session);
039: assertEquals(0, subIndexInfo.size());
040: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_1",
041: session);
042: assertEquals(0, subIndexInfo.size());
043: try {
044: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_2",
045: session);
046: if (subIndexInfo != null) {
047: fail();
048: }
049: } catch (Exception e) {
050: // all is well
051: }
052: try {
053: subIndexInfo = LuceneSubIndexInfo
054: .getIndexInfo("a", session);
055: if (subIndexInfo != null) {
056: fail();
057: }
058: } catch (Exception e) {
059: // all is well
060: }
061:
062: CompassTransaction tr = session.beginTransaction();
063:
064: A a = new A();
065: a.id = 1;
066: a.value = "value1";
067: session.save(a);
068:
069: a = new A();
070: a.id = 2;
071: a.value = "value2";
072: session.save(a);
073:
074: a = (A) session.load(A.class, 1);
075: assertEquals("value1", a.value);
076: a = (A) session.load(A.class, 2);
077: assertEquals("value2", a.value);
078:
079: tr.commit();
080:
081: tr = session.beginTransaction();
082: a = (A) session.load(A.class, 1);
083: assertEquals("value1", a.value);
084: a = (A) session.load(A.class, 2);
085: assertEquals("value2", a.value);
086: tr.commit();
087:
088: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_0",
089: session);
090: assertEquals(1, subIndexInfo.size());
091: assertEquals(1, subIndexInfo.info(0).docCount());
092: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_1",
093: session);
094: assertEquals(1, subIndexInfo.size());
095: assertEquals(1, subIndexInfo.info(0).docCount());
096:
097: session.close();
098: }
099:
100: }
|