Permalink
Browse files

Returning Next/Last EventNumber, IsEndOfStream, Status in EventStream…

…Slice, never throwing StreamDoesNotExistException, not throwing StreamDeletedException on readeventstreambackward/forward + fixed corresponding tests and scenariobase in test client
  • Loading branch information...
1 parent ab0c0ed commit 625f6144dbdc0ceb84bf360e1fe8a5494eb7b912 @PropertyOfTuckerSystems PropertyOfTuckerSystems committed Nov 13, 2012
@@ -107,11 +107,9 @@ public InspectionResult InspectPackage(TcpPackage package)
switch ((RangeReadResult)dto.Result)
{
case RangeReadResult.Success:
- return new InspectionResult(InspectionDecision.Succeed);
case RangeReadResult.StreamDeleted:
- return new InspectionResult(InspectionDecision.NotifyError, new StreamDeletedException(_stream));
case RangeReadResult.NoStream:
- return new InspectionResult(InspectionDecision.NotifyError, new StreamDoesNotExistException());
+ return new InspectionResult(InspectionDecision.Succeed);
default:
throw new ArgumentOutOfRangeException();
}
@@ -127,7 +125,14 @@ public void Complete()
if (Interlocked.CompareExchange(ref _completed, 1, 0) == 0)
{
if (_result != null)
- _source.SetResult(new EventStreamSlice(_stream, _start, _count, _result.Events));
+ _source.SetResult(new EventStreamSlice(StatusCode.Convert((RangeReadResult) _result.Result),
+ _stream,
+ _start,
+ _count,
+ _result.Events,
+ _result.NextEventNumber,
+ _result.LastEventNumber,
+ _result.IsEndOfStream));
else
_source.SetException(new NoResultException());
}
@@ -97,8 +97,8 @@ public InspectionResult InspectPackage(TcpPackage package)
if (package.Command != TcpCommand.ReadStreamEventsForwardCompleted)
{
return new InspectionResult(InspectionDecision.NotifyError,
- new CommandNotExpectedException(TcpCommand.ReadStreamEventsForwardCompleted.ToString(),
- package.Command.ToString()));
+ new CommandNotExpectedException(TcpCommand.ReadStreamEventsForwardCompleted.ToString(),
+ package.Command.ToString()));
}
var data = package.Data;
@@ -108,11 +108,9 @@ public InspectionResult InspectPackage(TcpPackage package)
switch ((RangeReadResult)dto.Result)
{
case RangeReadResult.Success:
- return new InspectionResult(InspectionDecision.Succeed);
case RangeReadResult.StreamDeleted:
- return new InspectionResult(InspectionDecision.NotifyError, new StreamDeletedException(_stream));
case RangeReadResult.NoStream:
- return new InspectionResult(InspectionDecision.NotifyError, new StreamDoesNotExistException());
+ return new InspectionResult(InspectionDecision.Succeed);
default:
throw new ArgumentOutOfRangeException();
}
@@ -128,7 +126,14 @@ public void Complete()
if (Interlocked.CompareExchange(ref _completed, 1, 0) == 0)
{
if (_result != null)
- _source.SetResult(new EventStreamSlice(_stream, _start, _count, _result.Events));
+ _source.SetResult(new EventStreamSlice(StatusCode.Convert((RangeReadResult) _result.Result),
+ _stream,
+ _start,
+ _count,
+ _result.Events,
+ _result.NextEventNumber,
+ _result.LastEventNumber,
+ _result.IsEndOfStream));
else
_source.SetException(new NoResultException());
}
@@ -95,7 +95,6 @@
<Compile Include="Exceptions\ProjectionCommandFailedException.cs" />
<Compile Include="Exceptions\InvalidTransactionException.cs" />
<Compile Include="Exceptions\StreamDeletedException.cs" />
- <Compile Include="Exceptions\StreamDoesNotExistException.cs" />
<Compile Include="Exceptions\WrongExpectedVersionException.cs" />
<Compile Include="IEvent.cs" />
<Compile Include="EventStoreTransaction.cs" />
@@ -122,7 +121,9 @@
<Compile Include="Messages\ClusterMessages.cs" />
<Compile Include="Position.cs" />
<Compile Include="RecordedEvent.cs" />
+ <Compile Include="SliceReadStatus.cs" />
<Compile Include="StreamPosition.cs" />
+ <Compile Include="SystemData\StatusCode.cs" />
<Compile Include="SystemData\EndpointsPair.cs" />
<Compile Include="ExpectedVersion.cs" />
<Compile Include="SystemData\InspectionResult.cs" />
@@ -37,19 +37,37 @@ public class EventStreamSlice
{
internal static readonly RecordedEvent[] EmptyEvents = new RecordedEvent[0];
+ public readonly SliceReadStatus Status;
public readonly string Stream;
- public readonly int StartIndex;
+
+ public readonly int Start;
public readonly int Count;
public readonly RecordedEvent[] Events;
- internal EventStreamSlice(string stream, int startIndex, int count, IEnumerable<ClientMessage.EventLinkPair> events)
+ public readonly int NextEventNumber;
+ public readonly int LastEventNumber;
+
+ public readonly bool IsEndOfStream;
+
+ internal EventStreamSlice(SliceReadStatus status,
+ string stream,
+ int start,
+ int count,
+ IEnumerable<ClientMessage.EventLinkPair> events,
+ int nextEventNumber,
+ int lastEventNumber,
+ bool isEndOfStream)
{
Ensure.NotNullOrEmpty(stream, "stream");
+ Status = status;
Stream = stream;
- StartIndex = startIndex;
+ Start = start;
Count = count;
Events = events == null ? EmptyEvents : events.Select(e => new RecordedEvent(e.Event)).ToArray();
+ NextEventNumber = nextEventNumber;
+ LastEventNumber = lastEventNumber;
+ IsEndOfStream = isEndOfStream;
}
}
}
@@ -0,0 +1,37 @@
+// Copyright (c) 2012, Event Store LLP
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Event Store LLP nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+namespace EventStore.ClientAPI
+{
+ public enum SliceReadStatus
+ {
+ Success,
+ StreamNotFound,
+ StreamDeleted
+ }
+}
@@ -27,26 +27,24 @@
//
using System;
-using System.Runtime.Serialization;
-namespace EventStore.ClientAPI.Exceptions
+namespace EventStore.ClientAPI.SystemData
{
- public class StreamDoesNotExistException : Exception
+ internal class StatusCode
{
- public StreamDoesNotExistException()
- {
- }
-
- public StreamDoesNotExistException(string message) : base(message)
- {
- }
-
- public StreamDoesNotExistException(string message, Exception innerException) : base(message, innerException)
- {
- }
-
- protected StreamDoesNotExistException(SerializationInfo info, StreamingContext context) : base(info, context)
+ public static SliceReadStatus Convert(RangeReadResult code)
{
+ switch (code)
+ {
+ case RangeReadResult.Success:
+ return SliceReadStatus.Success;
+ case RangeReadResult.NoStream:
+ return SliceReadStatus.StreamNotFound;
+ case RangeReadResult.StreamDeleted:
+ return SliceReadStatus.StreamDeleted;
+ default:
+ throw new ArgumentOutOfRangeException("code");
+ }
}
}
}
@@ -50,22 +50,24 @@ public void throw_if_count_le_zero()
[Test]
[Category("Network")]
- public void throw_if_no_stream()
+ public void notify_using_status_code_if_stream_not_found()
{
- const string stream = "read_event_stream_backward_should_throw_if_no_stream";
+ const string stream = "read_event_stream_backward_should_notify_using_status_code_if_stream_not_found";
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
var read = store.ReadEventStreamBackwardAsync(stream, StreamPosition.End, 1);
- Assert.That(() => read.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDoesNotExistException>());
+ Assert.DoesNotThrow(read.Wait);
+
+ Assert.That(read.Result.Status, Is.EqualTo(SliceReadStatus.StreamNotFound));
}
}
[Test]
[Category("Network")]
- public void throw_if_stream_deleted()
+ public void notify_using_status_code_if_stream_was_deleted()
{
- const string stream = "read_event_stream_backward_should_throw_if_stream_deleted";
+ const string stream = "read_event_stream_backward_should_notify_using_status_code_if_stream_was_deleted";
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
@@ -75,7 +77,9 @@ public void throw_if_stream_deleted()
Assert.DoesNotThrow(delete.Wait);
var read = store.ReadEventStreamBackwardAsync(stream, StreamPosition.End, 1);
- Assert.That(() => read.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
+ Assert.DoesNotThrow(read.Wait);
+
+ Assert.That(read.Result.Status, Is.EqualTo(SliceReadStatus.StreamDeleted));
}
}
@@ -28,7 +28,6 @@
using System;
using System.Linq;
using EventStore.ClientAPI;
-using EventStore.ClientAPI.Exceptions;
using NUnit.Framework;
namespace EventStore.Core.Tests.ClientAPI
{
@@ -61,22 +60,24 @@ public void throw_if_start_lt_zero()
[Test]
[Category("Network")]
- public void throw_if_no_stream()
+ public void notify_using_status_code_if_stream_not_found()
{
- const string stream = "read_event_stream_forward_should_throw_if_no_stream";
+ const string stream = "read_event_stream_forward_should_notify_using_status_code_if_stream_not_found";
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
var read = store.ReadEventStreamForwardAsync(stream, 0, 1);
- Assert.That(() => read.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDoesNotExistException>());
+ Assert.DoesNotThrow(read.Wait);
+
+ Assert.That(read.Result.Status, Is.EqualTo(SliceReadStatus.StreamNotFound));
}
}
[Test]
[Category("Network")]
- public void throw_if_stream_deleted()
+ public void notify_using_status_code_if_stream_was_deleted()
{
- const string stream = "read_event_stream_forward_should_throw_if_stream_deleted";
+ const string stream = "read_event_stream_forward_should_notify_using_status_code_if_stream_was_deleted";
using (var store = EventStoreConnection.Create())
{
store.Connect(MiniNode.Instance.TcpEndPoint);
@@ -86,7 +87,9 @@ public void throw_if_stream_deleted()
Assert.DoesNotThrow(delete.Wait);
var read = store.ReadEventStreamForwardAsync(stream, 0, 1);
- Assert.That(() => read.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
+ Assert.DoesNotThrow(read.Wait);
+
+ Assert.That(read.Result.Status, Is.EqualTo(SliceReadStatus.StreamDeleted));
}
}
@@ -222,7 +222,7 @@ protected Task CheckStreamsDeleted(IEnumerable<string> streams)
var s = stream;
var task = store.ReadEventStreamForwardAsync(stream, 0, 1).ContinueWith(t =>
{
- if (!t.IsFaulted)
+ if (t.Result.Status != SliceReadStatus.StreamDeleted)
throw new Exception(string.Format("Stream '{0}' is not deleted, but should be!", s));
});

0 comments on commit 625f614

Please sign in to comment.