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

« back to all changes in this revision

Viewing changes to lucene/backwards/src/test/org/apache/lucene/index/TestRollback.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.lucene.index;
2
 
 
3
 
/**
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
import org.apache.lucene.analysis.MockAnalyzer;
21
 
import org.apache.lucene.analysis.WhitespaceAnalyzer;
22
 
 
23
 
import org.apache.lucene.document.Document;
24
 
import org.apache.lucene.document.Field.Index;
25
 
import org.apache.lucene.document.Field.Store;
26
 
import org.apache.lucene.store.Directory;
27
 
import org.apache.lucene.util.LuceneTestCase;
28
 
 
29
 
public class TestRollback extends LuceneTestCase {
30
 
 
31
 
  // LUCENE-2536
32
 
  public void testRollbackIntegrityWithBufferFlush() throws Exception {
33
 
    Directory dir = newDirectory();
34
 
    RandomIndexWriter rw = new RandomIndexWriter(random, dir);
35
 
 
36
 
    for (int i = 0; i < 5; i++) {
37
 
      Document doc = new Document();
38
 
      doc.add(newField("pk", Integer.toString(i), Store.YES, Index.ANALYZED_NO_NORMS));
39
 
      rw.addDocument(doc);
40
 
    }
41
 
    rw.close();
42
 
 
43
 
    // If buffer size is small enough to cause a flush, errors ensue...
44
 
    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMaxBufferedDocs(2).setOpenMode(IndexWriterConfig.OpenMode.APPEND));
45
 
 
46
 
    Term pkTerm = new Term("pk", "");
47
 
    for (int i = 0; i < 3; i++) {
48
 
      Document doc = new Document();
49
 
      String value = Integer.toString(i);
50
 
      doc.add(newField("pk", value, Store.YES, Index.ANALYZED_NO_NORMS));
51
 
      doc.add(newField("text", "foo", Store.YES, Index.ANALYZED_NO_NORMS));
52
 
      w.updateDocument(pkTerm.createTerm(value), doc);
53
 
    }
54
 
    w.rollback();
55
 
 
56
 
    IndexReader r = IndexReader.open(dir, true);
57
 
    assertEquals("index should contain same number of docs post rollback", 5, r.numDocs());
58
 
    r.close();
59
 
    dir.close();
60
 
  }
61
 
}