Index: lucene/src/test/org/apache/lucene/index/LIALockTest.java =================================================================== --- lucene/src/test/org/apache/lucene/index/LIALockTest.java (revision 0) +++ lucene/src/test/org/apache/lucene/index/LIALockTest.java (revision 0) @@ -0,0 +1,73 @@ +package org.apache.lucene.index; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.analysis.SimpleAnalyzer; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; + +import java.io.IOException; +import java.io.File; + +// From chapter 2 +public class LIALockTest extends LuceneTestCase { + + private Directory dir; + private File indexDir; + + @Override + public void setUp() throws Exception { + super.setUp(); + indexDir = _TestUtil.getTempDir("index"); + dir = FSDirectory.open(indexDir); + } + + @Override + public void tearDown() throws Exception { + dir.close(); + super.tearDown(); + } + + public void testWriteLock() throws IOException { + + IndexWriter writer1 = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, + new SimpleAnalyzer(TEST_VERSION_CURRENT))); + IndexWriter writer2 = null; + try { + writer2 = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, + new SimpleAnalyzer(TEST_VERSION_CURRENT))); + fail("We should never reach this point"); + } + catch (LockObtainFailedException e) { + // e.printStackTrace(); // #A + } + finally { + writer1.close(); + assertNull(writer2); + _TestUtil.rmDir(indexDir); + } + } +} + +/* +#A Expected exception: only one IndexWriter allowed at once +*/ Property changes on: lucene\src\test\org\apache\lucene\index\LIALockTest.java ___________________________________________________________________ Added: svn:eol-style + native