Used by MockDirectoryWrapper to create an input stream that keeps track of when it's been closed.
Inheritance: IndexInput
Esempio n. 1
0
        public override object Clone()
        {
            EnsureOpen();
            Dir.InputCloneCount_Renamed.IncrementAndGet();
            IndexInput            iiclone = (IndexInput)@delegate.Clone();
            MockIndexInputWrapper clone   = new MockIndexInputWrapper(Dir, Name, iiclone);

            clone.IsClone = true;
            // Pending resolution on LUCENE-686 we may want to
            // uncomment this code so that we also track that all
            // clones get closed:

            /*
             * synchronized(dir.openFiles) {
             * if (dir.openFiles.containsKey(name)) {
             *  Integer v = (Integer) dir.openFiles.get(name);
             *  v = Integer.valueOf(v.intValue()+1);
             *  dir.openFiles.put(name, v);
             * } else {
             *  throw new RuntimeException("BUG: cloned file was not open?");
             * }
             * }
             */
            return(clone);
        }
 public override object Clone()
 {
     EnsureOpen();
     Dir.InputCloneCount_Renamed.IncrementAndGet();
     IndexInput iiclone = (IndexInput)@delegate.Clone();
     MockIndexInputWrapper clone = new MockIndexInputWrapper(Dir, Name, iiclone);
     clone.IsClone = true;
     // Pending resolution on LUCENE-686 we may want to
     // uncomment this code so that we also track that all
     // clones get closed:
     /*
     synchronized(dir.openFiles) {
       if (dir.openFiles.containsKey(name)) {
         Integer v = (Integer) dir.openFiles.get(name);
         v = Integer.valueOf(v.intValue()+1);
         dir.openFiles.put(name, v);
       } else {
         throw new RuntimeException("BUG: cloned file was not open?");
       }
     }
     */
     return clone;
 }
 public override IndexInput OpenFullSlice()
 {
     OuterInstance.MaybeYield();
     IndexInput ii = new MockIndexInputWrapper(OuterInstance, Name, DelegateHandle.OpenFullSlice());
     OuterInstance.AddFileHandle(ii, Name, Handle.Input);
     return ii;
 }
        public override IndexInput OpenInput(string name, IOContext context)
        {
            lock (this)
            {
                MaybeThrowDeterministicException();
                MaybeThrowIOExceptionOnOpen(name);
                MaybeYield();
                if (FailOnOpenInput_Renamed)
                {
                    MaybeThrowDeterministicException();
                }
                if (!LuceneTestCase.SlowFileExists(@in, name))
                {
                    throw new FileNotFoundException(name + " in dir=" + @in);
                }

                // cannot open a file for input if it's still open for
                // output, except for segments.gen and segments_N
                if (!AllowReadingFilesStillOpenForWrite_Renamed && OpenFilesForWrite.Contains(name) && !name.StartsWith("segments"))
                {
                    throw FillOpenTrace(new System.IO.IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);
                }

                IndexInput delegateInput = @in.OpenInput(name, LuceneTestCase.NewIOContext(RandomState, context));

                IndexInput ii;
                int randomInt = RandomState.Next(500);
                if (randomInt == 0)
                {
                    if (LuceneTestCase.VERBOSE)
                    {
                        Console.WriteLine("MockDirectoryWrapper: using SlowClosingMockIndexInputWrapper for file " + name);
                    }
                    ii = new SlowClosingMockIndexInputWrapper(this, name, delegateInput);
                }
                else if (randomInt == 1)
                {
                    if (LuceneTestCase.VERBOSE)
                    {
                        Console.WriteLine("MockDirectoryWrapper: using SlowOpeningMockIndexInputWrapper for file " + name);
                    }
                    ii = new SlowOpeningMockIndexInputWrapper(this, name, delegateInput);
                }
                else
                {
                    ii = new MockIndexInputWrapper(this, name, delegateInput);
                }
                AddFileHandle(ii, name, Handle.Input);
                return ii;
            }
        }
 public override IndexInput OpenSlice(string sliceDescription, long offset, long length)
 {
     OuterInstance.MaybeYield();
     IndexInput ii = new MockIndexInputWrapper(OuterInstance, Name, DelegateHandle.OpenSlice(sliceDescription, offset, length));
     OuterInstance.AddFileHandle(ii, Name, Handle.Input);
     return ii;
 }