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.AggressiveOptimizer;
027:
028: /**
029: * @author kimchy
030: */
031: public class AggressiveOptimizerTests extends AbstractOptimizerTests {
032:
033: protected void addSettings(CompassSettings settings) {
034: super .addSettings(settings);
035: settings.setSetting(LuceneEnvironment.Optimizer.TYPE,
036: AggressiveOptimizer.class.getName());
037: settings.setBooleanSetting(
038: LuceneEnvironment.Optimizer.SCHEDULE, false);
039: settings.setSetting(
040: LuceneEnvironment.Optimizer.Aggressive.MERGE_FACTOR,
041: "3");
042: settings
043: .setIntSetting(
044: LuceneEnvironment.SearchEngineIndex.CACHE_INTERVAL_INVALIDATION,
045: -1);
046: }
047:
048: public void testOptimizer() throws IOException {
049:
050: addData(0, 1);
051:
052: CompassSession session = openSession();
053: LuceneSubIndexInfo infos = LuceneSubIndexInfo.getIndexInfo("a",
054: session);
055: assertEquals(1, infos.size());
056: session.close();
057:
058: addData(1, 2);
059:
060: session = openSession();
061: infos = LuceneSubIndexInfo.getIndexInfo("a", session);
062: assertEquals(2, infos.size());
063: session.close();
064:
065: addData(2, 3);
066:
067: getCompass().getSearchEngineOptimizer().optimize();
068:
069: session = openSession();
070: infos = LuceneSubIndexInfo.getIndexInfo("a", session);
071: assertEquals(1, infos.size());
072: session.close();
073:
074: session = openSession();
075: CompassTransaction tr = session.beginTransaction();
076:
077: A a = session.load(A.class, new Long(2));
078: assertNotNull(a);
079:
080: tr.commit();
081: session.close();
082: }
083:
084: public void testOptimizerWithIndexCache() throws Exception {
085:
086: addData(0, 1);
087: assertData(0, 1);
088: addData(1, 2);
089: addData(2, 3);
090: addData(3, 4);
091: addData(4, 5);
092: addData(5, 6);
093: addData(6, 7);
094: assertData(6, 7);
095: addData(7, 8);
096: assertData(0, 8);
097:
098: getCompass().getSearchEngineOptimizer().optimize();
099:
100: CompassSession session = openSession();
101: LuceneSubIndexInfo infos = LuceneSubIndexInfo.getIndexInfo("a",
102: session);
103: assertEquals(1, infos.size());
104: LuceneSubIndexInfo.LuceneSegmentInfo segmentInfo = infos
105: .info(0);
106: assertEquals("_8", segmentInfo.name());
107: session.close();
108:
109: assertData(0, 8);
110: }
111: }
|