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.io.FileNotFoundException;
22
import java.io.IOException;
23
import org.apache.lucene.util.LuceneTestCase;
24
import org.apache.lucene.analysis.standard.StandardAnalyzer;
25
import org.apache.lucene.util._TestUtil;
26
import org.apache.lucene.index.IndexWriter;
27
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
28
import org.apache.lucene.store.Directory;
31
* This tests the patch for issue #LUCENE-715 (IndexWriter does not
32
* release its write lock when trying to open an index which does not yet
36
public class TestIndexWriterLockRelease extends LuceneTestCase {
37
private java.io.File __test_dir;
40
public void setUp() throws Exception {
42
if (this.__test_dir == null) {
43
this.__test_dir = _TestUtil.getTempDir("testIndexWriter");
45
if (this.__test_dir.exists()) {
46
throw new IOException("test directory \"" + this.__test_dir.getPath() + "\" already exists (please remove by hand)");
49
if (!this.__test_dir.mkdirs()
50
&& !this.__test_dir.isDirectory()) {
51
throw new IOException("unable to create test directory \"" + this.__test_dir.getPath() + "\"");
57
public void tearDown() throws Exception {
58
if (this.__test_dir != null) {
59
File[] files = this.__test_dir.listFiles();
64
if (!files[i].delete()) {
65
throw new IOException("unable to remove file in test directory \"" + this.__test_dir.getPath() + "\" (please remove by hand)");
69
if (!this.__test_dir.delete()) {
70
throw new IOException("unable to remove test directory \"" + this.__test_dir.getPath() + "\" (please remove by hand)");
76
public void testIndexWriterLockRelease() throws IOException {
77
Directory dir = newFSDirectory(this.__test_dir);
79
new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
80
new StandardAnalyzer(TEST_VERSION_CURRENT))
81
.setOpenMode(OpenMode.APPEND));
82
} catch (FileNotFoundException e) {
84
new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,
85
new StandardAnalyzer(TEST_VERSION_CURRENT))
86
.setOpenMode(OpenMode.APPEND));
87
} catch (FileNotFoundException e1) {