1
package org.apache.lucene.index;
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
11
* http://www.apache.org/licenses/LICENSE-2.0
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.
20
import org.apache.lucene.analysis.MockAnalyzer;
21
import org.apache.lucene.analysis.WhitespaceAnalyzer;
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;
29
public class TestRollback extends LuceneTestCase {
32
public void testRollbackIntegrityWithBufferFlush() throws Exception {
33
Directory dir = newDirectory();
34
RandomIndexWriter rw = new RandomIndexWriter(random, dir);
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));
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));
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);
56
IndexReader r = IndexReader.open(dir, true);
57
assertEquals("index should contain same number of docs post rollback", 5, r.numDocs());