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.
21
import java.util.concurrent.ExecutorService;
23
import org.apache.lucene.search.IndexSearcher;
24
import org.apache.lucene.store.MockDirectoryWrapper;
27
// - mix in forceMerge, addIndexes
28
// - randomoly mix in non-congruent docs
30
public class TestNRTThreads extends ThreadedIndexingAndSearchingTestCase {
33
protected void doSearching(ExecutorService es, long stopTime) throws Exception {
35
boolean anyOpenDelFiles = false;
37
IndexReader r = IndexReader.open(writer, true);
39
while (System.currentTimeMillis() < stopTime && !failed.get()) {
40
if (random.nextBoolean()) {
42
System.out.println("TEST: now reopen r=" + r);
44
final IndexReader r2 = IndexReader.openIfChanged(r);
51
System.out.println("TEST: now close reader=" + r);
55
final Set<String> openDeletedFiles = ((MockDirectoryWrapper) dir).getOpenDeletedFiles();
56
if (openDeletedFiles.size() > 0) {
57
System.out.println("OBD files: " + openDeletedFiles);
59
anyOpenDelFiles |= openDeletedFiles.size() > 0;
60
//assertEquals("open but deleted: " + openDeletedFiles, 0, openDeletedFiles.size());
62
System.out.println("TEST: now open");
64
r = IndexReader.open(writer, true);
67
System.out.println("TEST: got new reader=" + r);
69
//System.out.println("numDocs=" + r.numDocs() + "
70
//openDelFileCount=" + dir.openDeleteFileCount());
72
if (r.numDocs() > 0) {
73
fixedSearcher = new IndexSearcher(r, es);
74
smokeTestSearcher(fixedSearcher);
75
runSearchThreads(System.currentTimeMillis() + 500);
80
//System.out.println("numDocs=" + r.numDocs() + " openDelFileCount=" + dir.openDeleteFileCount());
81
final Set<String> openDeletedFiles = ((MockDirectoryWrapper) dir).getOpenDeletedFiles();
82
if (openDeletedFiles.size() > 0) {
83
System.out.println("OBD files: " + openDeletedFiles);
85
anyOpenDelFiles |= openDeletedFiles.size() > 0;
87
assertFalse("saw non-zero open-but-deleted count", anyOpenDelFiles);
90
private IndexSearcher fixedSearcher;
92
protected IndexSearcher getCurrentSearcher() throws Exception {
97
protected void releaseSearcher(IndexSearcher s) throws Exception {
98
if (s != fixedSearcher) {
100
s.getIndexReader().close();
106
protected IndexSearcher getFinalSearcher() throws Exception {
107
final IndexReader r2;
108
if (random.nextBoolean()) {
109
r2 = writer.getReader();
112
r2 = IndexReader.open(dir);
114
return newSearcher(r2);
117
public void testNRTThreads() throws Exception {
118
runTest("TestNRTThreads");