001: package org.apache.lucene.index;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: import java.io.File;
021: import java.io.FileNotFoundException;
022: import java.io.IOException;
023: import org.apache.lucene.util.LuceneTestCase;
024: import org.apache.lucene.index.IndexWriter;
025:
026: /**
027: * This tests the patch for issue #LUCENE-715 (IndexWriter does not
028: * release its write lock when trying to open an index which does not yet
029: * exist).
030: *
031: * @author mbogosian
032: * @version $Id$
033: */
034:
035: public class TestIndexWriterLockRelease extends LuceneTestCase {
036: private java.io.File __test_dir;
037:
038: public void setUp() throws Exception {
039: super .setUp();
040: if (this .__test_dir == null) {
041: String tmp_dir = System
042: .getProperty("java.io.tmpdir", "tmp");
043: this .__test_dir = new File(tmp_dir, "testIndexWriter");
044:
045: if (this .__test_dir.exists()) {
046: throw new IOException("test directory \""
047: + this .__test_dir.getPath()
048: + "\" already exists (please remove by hand)");
049: }
050:
051: if (!this .__test_dir.mkdirs()
052: && !this .__test_dir.isDirectory()) {
053: throw new IOException(
054: "unable to create test directory \""
055: + this .__test_dir.getPath() + "\"");
056: }
057: }
058: }
059:
060: public void tearDown() throws Exception {
061: super .tearDown();
062: if (this .__test_dir != null) {
063: File[] files = this .__test_dir.listFiles();
064:
065: for (int i = 0; i < files.length; ++i) {
066: if (!files[i].delete()) {
067: throw new IOException(
068: "unable to remove file in test directory \""
069: + this .__test_dir.getPath()
070: + "\" (please remove by hand)");
071: }
072: }
073:
074: if (!this .__test_dir.delete()) {
075: throw new IOException(
076: "unable to remove test directory \""
077: + this .__test_dir.getPath()
078: + "\" (please remove by hand)");
079: }
080: }
081: }
082:
083: public void testIndexWriterLockRelease() throws IOException {
084: IndexWriter im;
085:
086: try {
087: im = new IndexWriter(
088: this .__test_dir,
089: new org.apache.lucene.analysis.standard.StandardAnalyzer(),
090: false);
091: } catch (FileNotFoundException e) {
092: try {
093: im = new IndexWriter(
094: this .__test_dir,
095: new org.apache.lucene.analysis.standard.StandardAnalyzer(),
096: false);
097: } catch (FileNotFoundException e1) {
098: }
099: }
100: }
101: }
|