Skip to content

Commit c296154

Browse files
committed
Make client api throw on too big timespans
1 parent 0ac7abf commit c296154

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/EventStore.ClientAPI.NetCore/PersistentSubscriptionSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ public static PersistentSubscriptionSettingsBuilder Create()
101101
/// </summary>
102102
internal PersistentSubscriptionSettings(bool resolveLinkTos, int startFrom, bool extraStatistics, TimeSpan messageTimeout,
103103
int maxRetryCount, int liveBufferSize, int readBatchSize, int historyBufferSize,
104-
TimeSpan checkPointAfter, int minCheckPointCount, int maxCheckPointCount,
104+
TimeSpan checkPointAfter, int minCheckPointCount, int maxCheckPointCount,
105105
int maxSubscriberCount, string namedConsumerStrategy)
106106
{
107+
if(messageTimeout.TotalMilliseconds > Int32.MaxValue) throw new ArgumentException("messageTimeout", "milliseconds must be less or equal to than int32.MaxValue");
108+
if(checkPointAfter.TotalMilliseconds > Int32.MaxValue) throw new ArgumentException("checkPointAfter", "milliseconds must be less or equal to than int32.MaxValue");
107109
MessageTimeout = messageTimeout;
108110
ResolveLinkTos = resolveLinkTos;
109111
StartFrom = startFrom;

src/EventStore.ClientAPI.NetCore/PersistentSubscriptionSettingsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public PersistentSubscriptionSettingsBuilder WithMessageTimeoutOf(TimeSpan timeo
134134
/// <returns>A new <see cref="PersistentSubscriptionSettingsBuilder"></see></returns>
135135
public PersistentSubscriptionSettingsBuilder DontTimeoutMessages()
136136
{
137-
_timeout = TimeSpan.MaxValue;
137+
_timeout = TimeSpan.Zero;
138138
return this;
139139
}
140140

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using EventStore.ClientAPI;
3+
using NUnit.Framework;
4+
5+
namespace Eventstore.ClientAPI.Tests
6+
{
7+
[TestFixture, Category("LongRunning")]
8+
public class create_persistent_subscription_with_too_big_message_timeout : SpecificationWithConnection
9+
{
10+
11+
protected override void When()
12+
{
13+
14+
}
15+
16+
[Test]
17+
public void the_build_fails_with_argument_exception()
18+
{
19+
Assert.Throws<ArgumentException>(() => PersistentSubscriptionSettings.Create().WithMessageTimeoutOf(TimeSpan.FromDays(25 * 365)).Build());
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using EventStore.ClientAPI;
3+
using NUnit.Framework;
4+
5+
namespace Eventstore.ClientAPI.Tests
6+
{
7+
[TestFixture, Category("LongRunning")]
8+
public class create_persistent_subscription_with_too_big_retry_after : SpecificationWithConnection
9+
{
10+
11+
protected override void When()
12+
{
13+
14+
}
15+
16+
[Test]
17+
public void the_build_fails_with_argument_exception()
18+
{
19+
Assert.Throws<ArgumentException>(() => PersistentSubscriptionSettings.Create().CheckPointAfter(TimeSpan.FromDays(25 * 365)).Build());
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)