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.subindexhash;
018:
019: import org.apache.lucene.index.LuceneSubIndexInfo;
020: import org.compass.core.CompassSession;
021: import org.compass.core.CompassTransaction;
022: import org.compass.core.Resource;
023: import org.compass.core.test.AbstractTestCase;
024:
025: /**
026: * @author kimchy
027: */
028: public class RsemModuloTests extends AbstractTestCase {
029:
030: protected String[] getMappings() {
031: return new String[] { "subindexhash/rsem-modulo.cpm.xml" };
032: }
033:
034: public void testSingleResourceA() 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: Resource r = getCompass().getResourceFactory().createResource(
065: "a");
066: r.addProperty("id", new Long(1));
067: r.addProperty("value", "value1");
068: session.save(r);
069:
070: r = getCompass().getResourceFactory().createResource("a");
071: r.addProperty("id", new Long(2));
072: r.addProperty("value", "value2");
073: session.save(r);
074:
075: r = session.loadResource("a", new Long(1));
076: assertEquals("value1", r.getValue("value"));
077: r = session.loadResource("a", new Long(2));
078: assertEquals("value2", r.getValue("value"));
079:
080: tr.commit();
081:
082: tr = session.beginTransaction();
083: r = session.loadResource("a", new Long(1));
084: assertEquals("value1", r.getValue("value"));
085: r = session.loadResource("a", new Long(2));
086: assertEquals("value2", r.getValue("value"));
087: tr.commit();
088:
089: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_0",
090: session);
091: assertEquals(1, subIndexInfo.size());
092: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_1",
093: session);
094: assertEquals(1, subIndexInfo.size());
095:
096: session.close();
097: }
098:
099: public void testMultiObjectsToSameModulo() throws Exception {
100: CompassSession session = openSession();
101:
102: LuceneSubIndexInfo subIndexInfo = LuceneSubIndexInfo
103: .getIndexInfo("index_0", session);
104: assertEquals(0, subIndexInfo.size());
105: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_1",
106: session);
107: assertEquals(0, subIndexInfo.size());
108: try {
109: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_2",
110: session);
111: if (subIndexInfo != null) {
112: fail();
113: }
114: } catch (Exception e) {
115: // all is well
116: }
117: try {
118: subIndexInfo = LuceneSubIndexInfo
119: .getIndexInfo("a", session);
120: if (subIndexInfo != null) {
121: fail();
122: }
123: } catch (Exception e) {
124: // all is well
125: }
126:
127: CompassTransaction tr = session.beginTransaction();
128:
129: Resource r = getCompass().getResourceFactory().createResource(
130: "a");
131: r.addProperty("id", new Long(1));
132: r.addProperty("value", "value1");
133: session.save(r);
134:
135: r = getCompass().getResourceFactory().createResource("a");
136: r.addProperty("id", new Long(2));
137: r.addProperty("value", "value2");
138: session.save(r);
139:
140: r = getCompass().getResourceFactory().createResource("b");
141: r.addProperty("id", new Long(1));
142: r.addProperty("value", "valueb1");
143: session.save(r);
144:
145: r = getCompass().getResourceFactory().createResource("b");
146: r.addProperty("id", new Long(2));
147: r.addProperty("value", "valueb2");
148: session.save(r);
149:
150: r = session.loadResource("a", new Long(1));
151: assertEquals("value1", r.getValue("value"));
152: r = session.loadResource("a", new Long(2));
153: assertEquals("value2", r.getValue("value"));
154:
155: r = session.loadResource("b", new Long(1));
156: assertEquals("valueb1", r.getValue("value"));
157: r = session.loadResource("b", new Long(2));
158: assertEquals("valueb2", r.getValue("value"));
159:
160: tr.commit();
161:
162: tr = session.beginTransaction();
163:
164: r = session.loadResource("a", new Long(1));
165: assertEquals("value1", r.getValue("value"));
166: r = session.loadResource("a", new Long(2));
167: assertEquals("value2", r.getValue("value"));
168:
169: r = session.loadResource("b", new Long(1));
170: assertEquals("valueb1", r.getValue("value"));
171: r = session.loadResource("b", new Long(2));
172: assertEquals("valueb2", r.getValue("value"));
173:
174: tr.commit();
175:
176: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_0",
177: session);
178: assertEquals(1, subIndexInfo.size());
179: assertEquals(2, subIndexInfo.info(0).docCount());
180: subIndexInfo = LuceneSubIndexInfo.getIndexInfo("index_1",
181: session);
182: assertEquals(1, subIndexInfo.size());
183: assertEquals(2, subIndexInfo.info(0).docCount());
184:
185: session.close();
186: }
187: }
|