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.optimizer;
018:
019: import java.io.IOException;
020:
021: import org.apache.lucene.index.LuceneSubIndexInfo;
022: import org.compass.core.CompassSession;
023: import org.compass.core.CompassTransaction;
024: import org.compass.core.config.CompassSettings;
025: import org.compass.core.lucene.LuceneEnvironment;
026: import org.compass.core.lucene.engine.optimizer.AdaptiveOptimizer;
027:
028: public class AdaptiveOptimizerTests extends AbstractOptimizerTests {
029:
030: protected void addSettings(CompassSettings settings) {
031: super .addSettings(settings);
032: settings.setSetting(LuceneEnvironment.Optimizer.TYPE,
033: AdaptiveOptimizer.class.getName());
034: settings.setBooleanSetting(
035: LuceneEnvironment.Optimizer.SCHEDULE, false);
036: settings.setSetting(
037: LuceneEnvironment.Optimizer.Adaptive.MERGE_FACTOR, "3");
038: settings
039: .setIntSetting(
040: LuceneEnvironment.SearchEngineIndex.CACHE_INTERVAL_INVALIDATION,
041: 0);
042: }
043:
044: public void testOptimizerWithIndexCache() throws Exception {
045:
046: addData(0, 1);
047: addData(1, 2);
048: addData(2, 3);
049: addData(3, 4);
050: addData(4, 5);
051: addData(5, 6);
052: addData(6, 7);
053: addData(7, 8);
054:
055: assertData(0, 8);
056:
057: getCompass().getSearchEngineOptimizer().optimize();
058:
059: CompassSession session = openSession();
060: LuceneSubIndexInfo infos = LuceneSubIndexInfo.getIndexInfo("a",
061: session);
062: assertEquals(3, infos.size());
063: session.close();
064:
065: assertData(0, 8);
066: }
067:
068: public void testOptimizerMergeFactorSingleAdds() throws IOException {
069: addData(0, 1);
070:
071: addData(1, 2);
072:
073: addData(2, 3);
074:
075: getCompass().getSearchEngineOptimizer().optimize();
076:
077: CompassSession session = openSession();
078: LuceneSubIndexInfo infos = LuceneSubIndexInfo.getIndexInfo("a",
079: session);
080: assertEquals(3, infos.size());
081: session.close();
082:
083: session = openSession();
084: CompassTransaction tr = session.beginTransaction();
085: A a = session.load(A.class, (long) 0);
086: assertNotNull(a);
087: tr.commit();
088: session.close();
089:
090: }
091:
092: public void testOptimizerWithBigFirstSegment() throws IOException {
093: addData(0, 20);
094: addData(20, 21);
095: addData(21, 22);
096: getCompass().getSearchEngineOptimizer().optimize();
097: CompassSession session = openSession();
098: LuceneSubIndexInfo infos = LuceneSubIndexInfo.getIndexInfo("a",
099: session);
100: session.close();
101: assertEquals(3, infos.size());
102: assertEquals(20, infos.info(0).docCount());
103: assertEquals(1, infos.info(1).docCount());
104:
105: session = openSession();
106: CompassTransaction tr = session.beginTransaction();
107: A a = (A) session.load(A.class, new Long(0));
108: assertNotNull(a);
109: a = (A) session.load(A.class, new Long(21));
110: assertNotNull(a);
111: tr.commit();
112: session.close();
113: }
114:
115: public void testCamelCaseSegmentsLeftWithTwoSegments()
116: throws IOException {
117: addData(0, 10);
118: addData(10, 11);
119: addData(11, 15);
120: getCompass().getSearchEngineOptimizer().optimize();
121: CompassSession session = openSession();
122: LuceneSubIndexInfo infos = LuceneSubIndexInfo.getIndexInfo("a",
123: session);
124: session.close();
125: assertEquals(3, infos.size());
126: assertEquals(10, infos.info(0).docCount());
127: assertEquals(1, infos.info(1).docCount());
128: assertEquals(4, infos.info(2).docCount());
129:
130: session = openSession();
131: CompassTransaction tr = session.beginTransaction();
132: A a = session.load(A.class, 0);
133: assertNotNull(a);
134: a = session.load(A.class, 14);
135: assertNotNull(a);
136: tr.commit();
137: session.close();
138: }
139:
140: public void testCamelCaseSegmentsLeftWithOneSegment()
141: throws IOException {
142: addData(0, 10);
143: addData(10, 11);
144: addData(11, 25);
145: getCompass().getSearchEngineOptimizer().optimize();
146: CompassSession session = openSession();
147: LuceneSubIndexInfo infos = LuceneSubIndexInfo.getIndexInfo("a",
148: session);
149: session.close();
150: assertEquals(3, infos.size());
151: assertEquals(10, infos.info(0).docCount());
152:
153: session = openSession();
154: CompassTransaction tr = session.beginTransaction();
155: A a = (A) session.load(A.class, new Long(0));
156: assertNotNull(a);
157: a = (A) session.load(A.class, new Long(24));
158: assertNotNull(a);
159: tr.commit();
160: session.close();
161: }
162: }
|