Ejemplo n.º 1
0
        public virtual void  TestRAMDirectoryNoLocking()
        {
            Directory dir = new RAMDirectory();

            dir.SetLockFactory(NoLockFactory.GetNoLockFactory());

            Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(dir.GetLockFactory()), "RAMDirectory.setLockFactory did not take");

            IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);

            // Create a 2nd IndexWriter.  This is normally not allowed but it should run through since we're not
            // using any locks:
            IndexWriter writer2 = null;

            try
            {
                writer2 = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
            }
            catch (System.Exception e)
            {
                System.Console.Out.WriteLine(e.StackTrace);
                Assert.Fail("Should not have hit an IOException with no locking");
            }

            writer.Close();
            if (writer2 != null)
            {
                writer2.Close();
            }
        }
Ejemplo n.º 2
0
        public virtual void TestRAMDirectoryNoLocking()
        {
            MockDirectoryWrapper dir = new MockDirectoryWrapper(Random(), new RAMDirectory());

            dir.SetLockFactory(NoLockFactory.GetNoLockFactory());
            dir.WrapLockFactory = false; // we are gonna explicitly test we get this back
            Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(dir.LockFactory), "RAMDirectory.setLockFactory did not take");

            IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));

            writer.Commit(); // required so the second open succeed
            // Create a 2nd IndexWriter.  this is normally not allowed but it should run through since we're not
            // using any locks:
            IndexWriter writer2 = null;

            try
            {
                writer2 = new IndexWriter(dir, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(OpenMode.APPEND));
            }
            catch (Exception e)
            {
                Console.Out.Write(e.StackTrace);
                Assert.Fail("Should not have hit an IOException with no locking");
            }

            writer.Dispose();
            if (writer2 != null)
            {
                writer2.Dispose();
            }
        }
Ejemplo n.º 3
0
        // permit subclassing

        private void  Init(System.IO.FileInfo path, LockFactory lockFactory)
        {
            // Set up lockFactory with cascaded defaults: if an instance was passed in,
            // use that; else if locks are disabled, use NoLockFactory; else if the
            // system property Lucene.Net.Store.FSDirectoryLockFactoryClass is set,
            // instantiate that; else, use SimpleFSLockFactory:

            directory = path;

            bool doClearLockID = false;

            if (lockFactory == null)
            {
                if (disableLocks)
                {
                    // Locks are disabled:
                    lockFactory = NoLockFactory.GetNoLockFactory();
                }
                else
                {
                    // Our default lock is SimpleFSLockFactory;
                    // default lockDir is our index directory:
                    lockFactory   = new SimpleFSLockFactory(path);
                    doClearLockID = true;
                }
            }

            SetLockFactory(lockFactory);

            if (doClearLockID)
            {
                // Clear the prefix because write.lock will be
                // stored in our directory:
                lockFactory.SetLockPrefix(null);
            }
        }
Ejemplo n.º 4
0
 public MockFSDirectory(System.IO.FileInfo path, System.Random rand)
 {
     this.rand   = rand;
     lockFactory = new NoLockFactory();
     dir         = new SimpleFSDirectory(path, null);
 }
Ejemplo n.º 5
0
        /* will move to ctor, when reflection is removed in 3.0 */
        private void  Init(System.IO.DirectoryInfo path, LockFactory lockFactory)
        {
            // Set up lockFactory with cascaded defaults: if an instance was passed in,
            // use that; else if locks are disabled, use NoLockFactory; else if the
            // system property Lucene.Net.Store.FSDirectoryLockFactoryClass is set,
            // instantiate that; else, use SimpleFSLockFactory:

            directory = path;

            // due to differences in how Java & .NET refer to files, the checks are a bit different
            if (!directory.Exists && System.IO.File.Exists(directory.FullName))
            {
                throw new NoSuchDirectoryException("file '" + directory.FullName + "' exists but is not a directory");
            }

            if (lockFactory == null)
            {
                if (disableLocks)
                {
                    // Locks are disabled:
                    lockFactory = NoLockFactory.GetNoLockFactory();
                }
                else
                {
                    System.String lockClassName = SupportClass.AppSettings.Get("Lucene.Net.Store.FSDirectoryLockFactoryClass", "");

                    if (lockClassName != null && !lockClassName.Equals(""))
                    {
                        System.Type c;

                        try
                        {
                            c = System.Type.GetType(lockClassName);
                        }
                        catch (System.Exception e)
                        {
                            throw new System.IO.IOException("unable to find LockClass " + lockClassName);
                        }

                        try
                        {
                            lockFactory = (LockFactory)System.Activator.CreateInstance(c, true);
                        }
                        catch (System.UnauthorizedAccessException e)
                        {
                            throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName);
                        }
                        catch (System.InvalidCastException e)
                        {
                            throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory");
                        }
                        catch (System.Exception e)
                        {
                            throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName);
                        }
                    }
                    else
                    {
                        // Our default lock is SimpleFSLockFactory;
                        // default lockDir is our index directory:
                        lockFactory = new SimpleFSLockFactory();
                    }
                }
            }

            SetLockFactory(lockFactory);

            // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed
            // in index dir. If no index dir is given, set ourselves
            if (lockFactory is FSLockFactory)
            {
                FSLockFactory           lf  = (FSLockFactory)lockFactory;
                System.IO.DirectoryInfo dir = lf.GetLockDir();
                // if the lock factory has no lockDir set, use the this directory as lockDir
                if (dir == null)
                {
                    lf.SetLockDir(this.directory);
                    lf.SetLockPrefix(null);
                }
                else if (dir.FullName.Equals(this.directory.FullName))
                {
                    lf.SetLockPrefix(null);
                }
            }
        }
			public MockFSDirectory(System.IO.FileInfo path)
			{
				lockFactory = new NoLockFactory();
				dir = FSDirectory.GetDirectory(path);
			}
Ejemplo n.º 7
0
        // permit subclassing

        private void  Init(System.IO.FileInfo path, LockFactory lockFactory)
        {
            // Set up lockFactory with cascaded defaults: if an instance was passed in,
            // use that; else if locks are disabled, use NoLockFactory; else if the
            // system property Lucene.Net.Store.FSDirectoryLockFactoryClass is set,
            // instantiate that; else, use SimpleFSLockFactory:

            directory = path;

            bool doClearLockID = false;

            if (lockFactory == null)
            {
                if (disableLocks)
                {
                    // Locks are disabled:
                    lockFactory = NoLockFactory.GetNoLockFactory();
                }
                else
                {
                    System.String lockClassName = SupportClass.AppSettings.Get("Lucene.Net.Store.FSDirectoryLockFactoryClass", "");

                    if (lockClassName != null && !lockClassName.Equals(""))
                    {
                        System.Type c;

                        try
                        {
                            c = System.Type.GetType(lockClassName);
                        }
                        catch (System.Exception)
                        {
                            throw new System.IO.IOException("unable to find LockClass " + lockClassName);
                        }

                        try
                        {
                            lockFactory = (LockFactory)System.Activator.CreateInstance(c, true);
                        }
                        catch (System.UnauthorizedAccessException)
                        {
                            throw new System.IO.IOException("IllegalAccessException when instantiating LockClass " + lockClassName);
                        }
                        catch (System.InvalidCastException)
                        {
                            throw new System.IO.IOException("unable to cast LockClass " + lockClassName + " instance to a LockFactory");
                        }
                        catch (System.Exception ex)
                        {
                            throw new System.IO.IOException("InstantiationException when instantiating LockClass " + lockClassName + "\nDetails:" + ex.Message);
                        }

                        if (lockFactory is NativeFSLockFactory)
                        {
                            ((NativeFSLockFactory)lockFactory).SetLockDir(path);
                        }
                        else if (lockFactory is SimpleFSLockFactory)
                        {
                            ((SimpleFSLockFactory)lockFactory).SetLockDir(path);
                        }
                    }
                    else
                    {
                        // Our default lock is SimpleFSLockFactory;
                        // default lockDir is our index directory:
                        lockFactory   = new SimpleFSLockFactory(path);
                        doClearLockID = true;
                    }
                }
            }

            SetLockFactory(lockFactory);

            if (doClearLockID)
            {
                // Clear the prefix because write.lock will be
                // stored in our directory:
                lockFactory.SetLockPrefix(null);
            }
        }
			public MockFSDirectory(System.IO.DirectoryInfo path, System.Random rand)
			{
				this.rand = rand;
				interalLockFactory = new NoLockFactory();
				dir = new SimpleFSDirectory(path, null);
			}
Ejemplo n.º 9
0
 public MockFSDirectory(DirectoryInfo path, Random rand)
 {
     this.Rand = rand;
     SetLockFactory(NoLockFactory.GetNoLockFactory());
     Dir = new SimpleFSDirectory(path, null);
 }