-
Notifications
You must be signed in to change notification settings - Fork 102
Fix consume 503 handling #849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9374704
Add consume 503 handling
mtmk ca49658
Update consume notifications
mtmk d9b134e
Fix test and format
mtmk 5be8958
Update src/NATS.Client.JetStream/Internal/NatsJSConsume.cs
mtmk 78bff5d
Fix test
mtmk 2dc7b5e
Fix format
mtmk b87d47a
Fix build warnings
mtmk d9fcaa4
Add an error case for consumer
mtmk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using System.Text; | ||
| using NATS.Client.TestUtilities; | ||
| using NATS.Net; | ||
|
|
||
| namespace NATS.Client.JetStream.Tests; | ||
|
|
||
| public class ConsumeResponseTest | ||
| { | ||
| [Fact] | ||
| public async Task Consume_response() | ||
| { | ||
| var headers = new Stack<string>(); | ||
| headers.Push("NATS/1.0 400 Bad Test Request"); | ||
| headers.Push("NATS/1.0 999 Unknown Error"); | ||
| headers.Push("NATS/1.0 503"); | ||
| headers.Push("NATS/1.0 409 Message Size Exceeds MaxBytes"); | ||
| headers.Push("NATS/1.0 409 Leadership Change"); | ||
|
|
||
| await using var ms = new MockServer((_, cmd) => | ||
| { | ||
| if (cmd.Name == "PUB" && cmd.Subject.Contains("CONSUMER.INFO")) | ||
| { | ||
| cmd.Reply(payload: """{"stream_name":"x","name":"x"}"""); | ||
| } | ||
| else if (cmd.Name == "PUB" && cmd.Subject.Contains("CONSUMER.MSG.NEXT")) | ||
| { | ||
| if (headers.Peek() != null) | ||
| { | ||
| var header = headers.Pop(); | ||
| cmd.Reply(headers: header); | ||
| } | ||
| } | ||
|
|
||
| return Task.CompletedTask; | ||
| }); | ||
|
|
||
| var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); | ||
| await using var nats = new NatsConnection(new NatsOpts { Url = ms.Url }); | ||
| var js = nats.CreateJetStreamContext(); | ||
| var consumer = await js.GetConsumerAsync("x", "x", cts.Token); | ||
|
|
||
| var notifications = new List<INatsJSNotification>(); | ||
| var exception = await Assert.ThrowsAsync<NatsJSProtocolException>(async () => | ||
| { | ||
| await foreach (var msg in consumer.ConsumeAsync<string>( | ||
| opts: new NatsJSConsumeOpts | ||
| { | ||
| MaxMsgs = 1000, | ||
| IdleHeartbeat = TimeSpan.FromSeconds(1), | ||
| NotificationHandler = (n, ct) => | ||
| { | ||
| notifications.Add(n); | ||
| return Task.CompletedTask; | ||
| }, | ||
| }, | ||
| cancellationToken: cts.Token)) | ||
| { | ||
| } | ||
| }); | ||
|
|
||
| Assert.Equal(400, exception.HeaderCode); | ||
| Assert.Equal("Bad Test Request", exception.HeaderMessageText); | ||
|
|
||
| var types = notifications.Select(n => n.GetType()).ToList(); | ||
| Assert.Contains(typeof(NatsJSTimeoutNotification), types); | ||
| Assert.Contains(typeof(NatsJSNoRespondersNotification), types); | ||
| Assert.Contains(typeof(NatsJSLeadershipChangeNotification), types); | ||
| Assert.Contains(typeof(NatsJSMessageSizeExceedsMaxBytesNotification), types); | ||
| Assert.Contains(typeof(NatsJSProtocolNotification), types); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using NATS.Client.Core2.Tests; | ||
| using NATS.Client.JetStream.Models; | ||
| using NATS.Client.TestUtilities; | ||
|
|
||
| namespace NATS.Client.JetStream.Tests; | ||
|
|
||
| [Collection("nats-server")] | ||
| public class DirectGetTest | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
| private readonly NatsServerFixture _server; | ||
|
|
||
| public DirectGetTest(ITestOutputHelper output, NatsServerFixture server) | ||
| { | ||
| _output = output; | ||
| _server = server; | ||
| } | ||
|
|
||
| [SkipIfNatsServer(versionEarlierThan: "2.10.28")] | ||
| public async Task Direct_get_returns_503_no_responders() | ||
| { | ||
| // https://github.com/nats-io/nats-server/commit/ce309b79d99552996e18dce47dc04bdc730c0d84 | ||
| // When we fail to deliver a message through a service import respond with no responders. | ||
| await using var nats = new NatsConnection(new NatsOpts { Url = _server.Url }); | ||
| var prefix = _server.GetNextId(); | ||
| var js = new NatsJSContext(nats); | ||
|
|
||
| var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | ||
|
|
||
| var s1 = await js.CreateStreamAsync( | ||
| new StreamConfig($"{prefix}S1", [$"{prefix}s1"]) { AllowDirect = false }, | ||
| cancellationToken: cts.Token); | ||
|
|
||
| await js.PublishAsync($"{prefix}s1", "x", cancellationToken: cts.Token); | ||
|
|
||
| await Assert.ThrowsAsync<NatsNoRespondersException>(async () => await s1.GetDirectAsync<string>( | ||
| new StreamMsgGetRequest { Seq = 1 }, | ||
| cancellationToken: cts.Token)); | ||
| } | ||
|
|
||
| [SkipIfNatsServer(versionLaterThan: "2.10.28")] | ||
| public async Task Direct_get_returns_no_reply() | ||
| { | ||
| await using var nats = new NatsConnection(new NatsOpts { Url = _server.Url }); | ||
| var prefix = _server.GetNextId(); | ||
| var js = new NatsJSContext(nats); | ||
|
|
||
| var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | ||
|
|
||
| var s1 = await js.CreateStreamAsync( | ||
| new StreamConfig($"{prefix}S1", [$"{prefix}s1"]) { AllowDirect = false }, | ||
| cancellationToken: cts.Token); | ||
|
|
||
| await js.PublishAsync($"{prefix}s1", "x", cancellationToken: cts.Token); | ||
|
|
||
| await Assert.ThrowsAsync<NatsNoReplyException>(async () => await s1.GetDirectAsync<string>( | ||
| new StreamMsgGetRequest { Seq = 1 }, | ||
| cancellationToken: cts.Token)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.