GetExtension() public static method

Utility method to return a file's extension.
public static GetExtension ( string name ) : string
name string
return string
        public virtual void TestBasic()
        {
            HashSet <string> fileExtensions = new HashSet <string>();

            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_EXTENSION);
            fileExtensions.Add(Lucene40StoredFieldsWriter.FIELDS_INDEX_EXTENSION);

            MockDirectoryWrapper primaryDir = new MockDirectoryWrapper(Random(), new RAMDirectory());

            primaryDir.CheckIndexOnClose = false; // only part of an index
            MockDirectoryWrapper secondaryDir = new MockDirectoryWrapper(Random(), new RAMDirectory());

            secondaryDir.CheckIndexOnClose = false; // only part of an index

            FileSwitchDirectory fsd = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
            // for now we wire Lucene40Codec because we rely upon its specific impl
            bool oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;

            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
            IndexWriter writer = new IndexWriter(fsd, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetMergePolicy(NewLogMergePolicy(false)).SetCodec(Codec.ForName("Lucene40")).SetUseCompoundFile(false));

            TestIndexWriterReader.CreateIndexNoClose(true, "ram", writer);
            IndexReader reader = DirectoryReader.Open(writer, true);

            Assert.AreEqual(100, reader.MaxDoc);
            writer.Commit();
            // we should see only fdx,fdt files here
            string[] files = primaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsTrue(fileExtensions.Contains(ext));
            }
            files = secondaryDir.ListAll();
            Assert.IsTrue(files.Length > 0);
            // we should not see fdx,fdt files here
            for (int x = 0; x < files.Length; x++)
            {
                string ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsFalse(fileExtensions.Contains(ext));
            }
            reader.Dispose();
            writer.Dispose();

            files = fsd.ListAll();
            for (int i = 0; i < files.Length; i++)
            {
                Assert.IsNotNull(files[i]);
            }
            fsd.Dispose();
            OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
        }
Exemplo n.º 2
0
        public virtual void  TestBasic()
        {
            HashSet <string> fileExtensions = new HashSet <string>();

            fileExtensions.Add("fdt");
            fileExtensions.Add("fdx");

            Directory    primaryDir   = new MockRAMDirectory();
            RAMDirectory secondaryDir = new MockRAMDirectory();

            FileSwitchDirectory fsd    = new FileSwitchDirectory(fileExtensions, primaryDir, secondaryDir, true);
            IndexWriter         writer = new IndexWriter(fsd, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED, null);

            writer.UseCompoundFile = false;
            TestIndexWriterReader.CreateIndexNoClose(true, "ram", writer);
            IndexReader reader = writer.GetReader(null);

            Assert.AreEqual(100, reader.MaxDoc);
            writer.Commit(null);
            // we should see only fdx,fdt files here
            System.String[] files = primaryDir.ListAll(null);
            Assert.IsTrue(files.Length > 0);
            for (int x = 0; x < files.Length; x++)
            {
                System.String ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsTrue(fileExtensions.Contains(ext));
            }
            files = secondaryDir.ListAll(null);
            Assert.IsTrue(files.Length > 0);
            // we should not see fdx,fdt files here
            for (int x = 0; x < files.Length; x++)
            {
                System.String ext = FileSwitchDirectory.GetExtension(files[x]);
                Assert.IsFalse(fileExtensions.Contains(ext));
            }
            reader.Close();
            writer.Close();

            files = fsd.ListAll(null);
            for (int i = 0; i < files.Length; i++)
            {
                Assert.IsNotNull(files[i]);
            }
            fsd.Close();
        }