Skip to content

Commit 0815db5

Browse files
committed
Lucene.Net.Store.MockIndexOutputWrapper: Inverted condition on CheckDiskFull to use @in as the nullable object to determine whether the caller intended to use DataInput or ReadOnlySpan<byte>
1 parent 9db5fde commit 0815db5

1 file changed

Lines changed: 4 additions & 46 deletions

File tree

src/Lucene.Net.TestFramework/Store/MockIndexOutputWrapper.cs

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private void CheckCrashed()
5757
}
5858
}
5959

60-
private void CheckDiskFull(byte[]? b, int offset, DataInput? @in, long len)
60+
private void CheckDiskFull(ReadOnlySpan<byte> b, int offset, DataInput? @in, long len)
6161
{
6262
long freeSpace = dir.maxSize == 0 ? 0 : dir.maxSize - dir.GetSizeInBytes();
6363
long realUsage = 0;
@@ -76,9 +76,9 @@ private void CheckDiskFull(byte[]? b, int offset, DataInput? @in, long len)
7676
if (freeSpace > 0)
7777
{
7878
realUsage += freeSpace;
79-
if (b != null)
79+
if (@in is null) // LUCENENET: Inverted condition to use @in, since ReadOnlySpan cannot be null and Empty would not be a reliable check
8080
{
81-
@delegate.WriteBytes(b, offset, (int)freeSpace);
81+
@delegate.WriteBytes(b.Slice(offset, (int)freeSpace));
8282
}
8383
else
8484
{
@@ -104,48 +104,6 @@ private void CheckDiskFull(byte[]? b, int offset, DataInput? @in, long len)
104104
}
105105
}
106106

107-
// LUCENENET specific overload
108-
private void CheckDiskFull(ReadOnlySpan<byte> source)
109-
{
110-
long len = source.Length;
111-
long freeSpace = dir.maxSize == 0 ? 0 : dir.maxSize - dir.GetSizeInBytes();
112-
long realUsage = 0;
113-
114-
// Enforce disk full:
115-
if (dir.maxSize != 0 && freeSpace <= len)
116-
{
117-
// Compute the real disk free. this will greatly slow
118-
// down our test but makes it more accurate:
119-
realUsage = dir.GetRecomputedActualSizeInBytes();
120-
freeSpace = dir.maxSize - realUsage;
121-
}
122-
123-
if (dir.maxSize != 0 && freeSpace <= len)
124-
{
125-
if (freeSpace > 0)
126-
{
127-
realUsage += freeSpace;
128-
@delegate.WriteBytes(source.Slice(/*offset*/ 0, (int)freeSpace));
129-
}
130-
if (realUsage > dir.maxUsedSize)
131-
{
132-
dir.maxUsedSize = realUsage;
133-
}
134-
string message = "fake disk full at " + dir.GetRecomputedActualSizeInBytes() + " bytes when writing " + name + " (file length=" + @delegate.Length;
135-
if (freeSpace > 0)
136-
{
137-
message += "; wrote " + freeSpace + " of " + len + " bytes";
138-
}
139-
message += ")";
140-
if (LuceneTestCase.Verbose)
141-
{
142-
Console.WriteLine(Thread.CurrentThread.Name + ": MDW: now throw fake disk full");
143-
StackTraceHelper.PrintCurrentStackTrace(Console.Out);
144-
}
145-
throw new IOException(message);
146-
}
147-
}
148-
149107
protected override void Dispose(bool disposing)
150108
{
151109
if (disposing)
@@ -220,7 +178,7 @@ public override void WriteBytes(ReadOnlySpan<byte> source)
220178
{
221179
int len = source.Length;
222180
CheckCrashed();
223-
CheckDiskFull(source);
181+
CheckDiskFull(source, 0, null, len);
224182

225183
if (dir.randomState.Next(200) == 0)
226184
{

0 commit comments

Comments
 (0)