~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/update/DirectUpdateHandlerOptimizeTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.update;
2
 
/**
3
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
4
 
 * contributor license agreements.  See the NOTICE file distributed with
5
 
 * this work for additional information regarding copyright ownership.
6
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
7
 
 * (the "License"); you may not use this file except in compliance with
8
 
 * the License.  You may obtain a copy of the License at
9
 
 *
10
 
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 
 *
12
 
 * Unless required by applicable law or agreed to in writing, software
13
 
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 
 * See the License for the specific language governing permissions and
16
 
 * limitations under the License.
17
 
 */
18
 
 
19
 
import org.apache.lucene.document.Document;
20
 
import org.apache.lucene.document.Field;
21
 
import org.apache.solr.core.SolrCore;
22
 
import org.apache.solr.util.AbstractSolrTestCase;
23
 
 
24
 
import java.io.File;
25
 
import java.io.FileFilter;
26
 
 
27
 
 
28
 
/**
29
 
 *
30
 
 *
31
 
 **/
32
 
public class DirectUpdateHandlerOptimizeTest extends AbstractSolrTestCase {
33
 
 
34
 
  @Override
35
 
  public String getSchemaFile() {
36
 
    return "schema12.xml";
37
 
  }
38
 
 
39
 
  @Override
40
 
  public String getSolrConfigFile() {
41
 
    return "solrconfig-duh-optimize.xml";
42
 
  }
43
 
 
44
 
 
45
 
  public void testOptimize() throws Exception {
46
 
    SolrCore core = h.getCore();
47
 
 
48
 
    UpdateHandler updater = core.getUpdateHandler();
49
 
    AddUpdateCommand cmd = new AddUpdateCommand();
50
 
    cmd.overwriteCommitted = true;
51
 
    cmd.overwritePending = true;
52
 
    cmd.allowDups = false;
53
 
    //add just under the merge factor, so no segments are merged
54
 
    //the merge factor is 100 and the maxBufferedDocs is 2, so there should be 50 segments
55
 
    for (int i = 0; i < 99; i++) {
56
 
      // Add a valid document
57
 
      cmd.doc = new Document();
58
 
      cmd.doc.add(new Field("id", "id_" + i, Field.Store.YES, Field.Index.NOT_ANALYZED));
59
 
      cmd.doc.add(new Field("subject", "subject_" + i, Field.Store.NO, Field.Index.ANALYZED));
60
 
      updater.addDoc(cmd);
61
 
    }
62
 
 
63
 
    CommitUpdateCommand cmtCmd = new CommitUpdateCommand(false);
64
 
    updater.commit(cmtCmd);
65
 
    updater.commit(cmtCmd);  // commit twice to give systems such as windows a chance to delete the old files
66
 
 
67
 
    String indexDir = core.getIndexDir();
68
 
    assertNumSegments(indexDir, 50);
69
 
 
70
 
    //now do an optimize
71
 
    cmtCmd = new CommitUpdateCommand(true);
72
 
    cmtCmd.maxOptimizeSegments = 25;
73
 
    updater.commit(cmtCmd);
74
 
    updater.commit(cmtCmd);
75
 
    assertNumSegments(indexDir, 25);
76
 
 
77
 
    cmtCmd.maxOptimizeSegments = -1;
78
 
    try {
79
 
      updater.commit(cmtCmd);
80
 
      assertTrue(false);
81
 
    } catch (IllegalArgumentException e) {
82
 
    }
83
 
    cmtCmd.maxOptimizeSegments = 1;
84
 
    updater.commit(cmtCmd);
85
 
    updater.commit(cmtCmd);
86
 
    assertNumSegments(indexDir, 1);
87
 
  }
88
 
 
89
 
  private void assertNumSegments(String indexDir, int numSegs) {
90
 
    File file = new File(indexDir);
91
 
    File[] segs = file.listFiles(new FileFilter() {
92
 
      public boolean accept(File file) {
93
 
        return file.getName().endsWith("cfs");
94
 
      }
95
 
    });
96
 
 
97
 
    //
98
 
    // TODO: we need a method that does not rely on physical inspection of the directory.
99
 
    //
100
 
    // assertTrue("Wrong number of segments: " + segs.length + " does not equal: " + numSegs, segs.length == numSegs);
101
 
  }
102
 
 
103
 
}