Skip to content

Commit 869ed37

Browse files
committed
Revert async interfaces, unify IReplicationService with Perform/PerformAsync, update ReplicationServlet, Middleware, and TestServer to use single interface
1 parent 8dcdc0d commit 869ed37

6 files changed

Lines changed: 7 additions & 51 deletions

File tree

src/Lucene.Net.Replicator/Http/ReplicationService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private async Task ExecuteReplicationAsync(
139139
if (!replicators.TryGetValue(pathElements[SHARD_IDX], out IReplicator replicator))
140140
throw ServletException.Create("unrecognized shard ID " + pathElements[SHARD_IDX]);
141141

142+
// SOLR-8933 Don't close this stream.
142143
try
143144
{
144145
switch (action)
@@ -175,7 +176,7 @@ private async Task ExecuteReplicationAsync(
175176
}
176177
catch (Exception)
177178
{
178-
response.StatusCode = (int)HttpStatusCode.InternalServerError;
179+
response.StatusCode = (int)HttpStatusCode.InternalServerError; // propagate the failure
179180
}
180181
finally
181182
{
@@ -208,8 +209,8 @@ public virtual void Perform(IReplicationRequest request, IReplicationResponse re
208209
}
209210
return Task.CompletedTask;
210211
},
211-
() => { response.Flush(); return Task.CompletedTask; }
212-
).GetAwaiter().GetResult(); // // keep sync behavior
212+
() => { response.Body.Flush(); return Task.CompletedTask; }
213+
).ConfigureAwait(false).GetAwaiter().GetResult(); // keep sync behavior
213214
}
214215

215216

@@ -241,7 +242,7 @@ public virtual Task PerformAsync(
241242
await token.SerializeAsync(response.Body, cancellationToken);
242243
}
243244
},
244-
() => response.FlushAsync(cancellationToken)
245+
() => response.Body.FlushAsync(cancellationToken)
245246
);
246247
}
247248
}

src/Lucene.Net.Replicator/Support/Http/Abstractions/IReplicationResponse.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.IO;
2-
using System.Threading;
3-
using System.Threading.Tasks;
42

53
namespace Lucene.Net.Replicator.Http.Abstractions
64
{
@@ -39,17 +37,5 @@ public interface IReplicationResponse
3937
/// The response content.
4038
/// </summary>
4139
Stream Body { get; }
42-
43-
/// <summary>
44-
/// Flushes the reponse to the underlying response stream.
45-
/// </summary>
46-
void Flush();
47-
48-
/// <summary>
49-
/// Flushes the response to the underlying response stream asynchronously.
50-
/// </summary>
51-
/// <param name="cancellationToken">Optional cancellation token.</param>
52-
/// <returns>A task representing the asynchronous operation.</returns>
53-
Task FlushAsync(CancellationToken cancellationToken = default);
5440
}
5541
}

src/Lucene.Net.Tests.Replicator/Http/ReplicationServlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using Lucene.Net.Replicator.AspNetCore;
33
using Lucene.Net.Replicator.Http.Abstractions;
44
using Microsoft.AspNetCore.Builder;
5-
using Microsoft.AspNetCore.Routing;
65
using Microsoft.AspNetCore.Hosting;
76
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Routing;
88
using System;
99
using System.Threading.Tasks;
1010

src/Lucene.Net.Tests.Replicator/Support/Net/HttpListenerReplicationResponse.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,5 @@ public int StatusCode
4040
}
4141

4242
public Stream Body => _response.OutputStream;
43-
44-
public void Flush() => _response.OutputStream.Flush();
45-
46-
public Task FlushAsync(CancellationToken cancellationToken = default) =>
47-
_response.OutputStream.FlushAsync(cancellationToken);
4843
}
4944
}

src/Lucene.Net.Tests.Replicator/Support/Net/TestServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private async Task ListenLoopAsync(CancellationToken token)
107107
}
108108
finally
109109
{
110-
await response.FlushAsync(token);
110+
await response.Body.FlushAsync(token);
111111
context.Response.Close();
112112
}
113113
}, token);

src/dotnet/Lucene.Net.Replicator.AspNetCore/AspNetCoreReplicationResponse.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Lucene.Net.Replicator.Http.Abstractions;
22
using Microsoft.AspNetCore.Http;
33
using System.IO;
4-
using System.Threading;
5-
using System.Threading.Tasks;
64

75
namespace Lucene.Net.Replicator.AspNetCore
86
{
@@ -59,29 +57,5 @@ public int StatusCode
5957
/// This simply returns the <see cref="HttpResponse.Body"/>.
6058
/// </remarks>
6159
public Stream Body => response.Body;
62-
63-
/// <summary>
64-
/// Flushes the reponse to the underlying response stream.
65-
/// </summary>
66-
/// <remarks>
67-
/// This simply calls <see cref="Stream.Flush"/> on the <see cref="HttpResponse.Body"/>.
68-
/// </remarks>
69-
public void Flush()
70-
{
71-
response.Body.Flush();
72-
}
73-
74-
/// <summary>
75-
/// Flushes the response to the underlying response stream asynchronously.
76-
/// </summary>
77-
/// <param name="cancellationToken">Optional cancellation token.</param>
78-
/// <returns>A task representing the asynchronous operation.</returns>
79-
/// <remarks>
80-
/// This simply calls <see cref="Stream.FlushAsync(CancellationToken)"/> on the <see cref="HttpResponse.Body"/>.
81-
/// </remarks>
82-
public async Task FlushAsync(CancellationToken cancellationToken = default)
83-
{
84-
await response.Body.FlushAsync(cancellationToken);
85-
}
8660
}
8761
}

0 commit comments

Comments
 (0)