public override IndexOutput CreateOutput(string name, IOContext context)
{
lock (this)
{
MaybeThrowDeterministicException();
MaybeThrowIOExceptionOnOpen(name);
MaybeYield();
if (FailOnCreateOutput_Renamed)
{
MaybeThrowDeterministicException();
}
if (Crashed)
{
throw new System.IO.IOException("cannot createOutput after crash");
}
Init();
lock (this)
{
if (PreventDoubleWrite_Renamed && CreatedFiles.Contains(name) && !name.Equals("segments.gen"))
{
throw new System.IO.IOException("file \"" + name + "\" was already written to");
}
}
if ((NoDeleteOpenFile_Renamed || assertNoDeleteOpenFile) && OpenFiles.ContainsKey(name))
{
if (!assertNoDeleteOpenFile)
{
throw new System.IO.IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite");
}
else
{
throw new InvalidOperationException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite");
}
}
if (Crashed)
{
throw new System.IO.IOException("cannot createOutput after crash");
}
UnSyncedFiles.Add(name);
CreatedFiles.Add(name);
if (@in is RAMDirectory)
{
RAMDirectory ramdir = (RAMDirectory)@in;
RAMFile file = new RAMFile(ramdir);
RAMFile existing = ramdir.GetNameFromFileMap_Nunit(name);
// Enforce write once:
if (existing != null && !name.Equals("segments.gen") && PreventDoubleWrite_Renamed)
{
throw new System.IO.IOException("file " + name + " already exists");
}
else
{
if (existing != null)
{
ramdir.GetAndAddSizeInBytes_Nunit(-existing.SizeInBytes);
existing.SetDirectory_Nunit(null);
}
ramdir.SetNameForFileMap_Nunit(name, file);
}
}
//System.out.println(Thread.currentThread().getName() + ": MDW: create " + name);
IndexOutput delegateOutput = @in.CreateOutput(name, LuceneTestCase.NewIOContext(RandomState, context));
if (RandomState.Next(10) == 0)
{
// once in a while wrap the IO in a Buffered IO with random buffer sizes
delegateOutput = new BufferedIndexOutputWrapper(this, 1 + RandomState.Next(BufferedIndexOutput.DEFAULT_BUFFER_SIZE), delegateOutput);
}
IndexOutput io = new MockIndexOutputWrapper(this, delegateOutput, name);
AddFileHandle(io, name, Handle.Output);
OpenFilesForWrite.Add(name);
// throttling REALLY slows down tests, so don't do it very often for SOMETIMES.
if (throttling == Throttling_e.ALWAYS || (throttling == Throttling_e.SOMETIMES && RandomState.Next(50) == 0) && !(@in is RateLimitedDirectoryWrapper))
{
if (LuceneTestCase.VERBOSE)
{
Console.WriteLine("MockDirectoryWrapper: throttling indexOutput (" + name + ")");
}
return ThrottledOutput.NewFromDelegate(io);
}
else
{
return io;
}
}
}