1 package org.apache.lucene.store;
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 java.io.IOException;
21 import java.util.HashSet;
24 import org.apache.lucene.analysis.MockAnalyzer;
25 import org.apache.lucene.index.IndexFileNames;
26 import org.apache.lucene.index.IndexReader;
27 import org.apache.lucene.index.IndexWriter;
28 import org.apache.lucene.index.IndexWriterConfig;
29 import org.apache.lucene.index.TestIndexWriterReader;
30 import org.apache.lucene.util.LuceneTestCase;
32 public class TestFileSwitchDirectory extends LuceneTestCase {
34 * Test if writing doc stores to disk and everything else to ram works.
37 public void testBasic() throws IOException {
38 Set<String> fileExtensions = new HashSet<String>();
39 fileExtensions.add(IndexFileNames.FIELDS_EXTENSION);
40 fileExtensions.add(IndexFileNames.FIELDS_INDEX_EXTENSION);
42 MockDirectoryWrapper primaryDir = new MockDirectoryWrapper(random, new RAMDirectory());
43 primaryDir.setCheckIndexOnClose(false); // only part of an index
44 MockDirectoryWrapper secondaryDir = new MockDirectoryWrapper(random, new RAMDirectory());
45 secondaryDir.setCheckIndexOnClose(false); // only part of an index
47 FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
48 IndexWriter writer = new IndexWriter(
50 new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).
51 setMergePolicy(newLogMergePolicy(false))
53 TestIndexWriterReader.createIndexNoClose(true, "ram", writer);
54 IndexReader reader = IndexReader.open(writer, true);
55 assertEquals(100, reader.maxDoc());
57 // we should see only fdx,fdt files here
58 String[] files = primaryDir.listAll();
59 assertTrue(files.length > 0);
60 for (int x=0; x < files.length; x++) {
61 String ext = FileSwitchDirectory.getExtension(files[x]);
62 assertTrue(fileExtensions.contains(ext));
64 files = secondaryDir.listAll();
65 assertTrue(files.length > 0);
66 // we should not see fdx,fdt files here
67 for (int x=0; x < files.length; x++) {
68 String ext = FileSwitchDirectory.getExtension(files[x]);
69 assertFalse(fileExtensions.contains(ext));
74 files = fsd.listAll();
75 for(int i=0;i<files.length;i++) {
76 assertNotNull(files[i]);