Skip to content

Commit

Permalink
Merge branch 'projections-deleted-stream' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ysw committed Feb 20, 2014
2 parents 7466e47 + 7eb4eea commit bd283f8
Show file tree
Hide file tree
Showing 219 changed files with 6,456 additions and 796 deletions.
2 changes: 1 addition & 1 deletion src/EventStore/EventStore.ClientAPI/Common/SystemNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static class SystemMetadata
public const string SystemStreamAcl = "$systemStreamAcl";
}

static class SystemEventTypes
public static class SystemEventTypes
{
public const string StreamDeleted = "$streamDeleted";
public const string StatsCollection = "$statsCollected";
Expand Down
5 changes: 5 additions & 0 deletions src/EventStore/EventStore.ClientAPI/ProjectionsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public Task Disable(IPEndPoint endPoint, string name, UserCredentials userCreden
return SendPost(endPoint.ToHttpUrl("/projection/{0}/command/disable", name), string.Empty, userCredentials, HttpStatusCode.OK);
}

public Task Abort(IPEndPoint endPoint, string name, UserCredentials userCredentials = null)
{
return SendPost(endPoint.ToHttpUrl("/projection/{0}/command/abort", name), string.Empty, userCredentials, HttpStatusCode.OK);
}

public Task CreateOneTime(IPEndPoint endPoint, string query, UserCredentials userCredentials = null)
{
return SendPost(endPoint.ToHttpUrl("/projections/onetime?type=JS"), query, userCredentials, HttpStatusCode.Created);
Expand Down
25 changes: 24 additions & 1 deletion src/EventStore/EventStore.ClientAPI/ProjectionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Disable(string name, UserCredentials userCredentials = null)
}

/// <summary>
/// Asynchronously disables a projection.
/// Asynchronously aborts and disables a projection without writing a checkpoint.
/// </summary>
/// <param name="name">The name of the projection.</param>
/// <param name="userCredentials">Credentials for a user with permission to disable a projection.</param>
Expand All @@ -101,6 +101,29 @@ public Task DisableAsync(string name, UserCredentials userCredentials = null)
return _client.Disable(_httpEndPoint, name, userCredentials);
}

/// <summary>
/// Synchronously avborts and disables a projection without writing a checkpoint.
/// </summary>
/// <param name="name">The name of the projection.</param>
/// <param name="userCredentials">Credentials for a user with permission to disable a projection.</param>
public void Abort(string name, UserCredentials userCredentials = null)
{
Ensure.NotNullOrEmpty(name, "name");
AbortAsync(name, userCredentials).Wait();
}

/// <summary>
/// Asynchronously disables a projection.
/// </summary>
/// <param name="name">The name of the projection.</param>
/// <param name="userCredentials">Credentials for a user with permission to disable a projection.</param>
/// <returns>A task representing the operation.</returns>
public Task AbortAsync(string name, UserCredentials userCredentials = null)
{
Ensure.NotNullOrEmpty(name, "name");
return _client.Abort(_httpEndPoint, name, userCredentials);
}

/// <summary>
/// Synchronously creates a one-time query.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions src/EventStore/EventStore.ClientAPI/RecordedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
using System;
using System.Text;
using EventStore.ClientAPI.Messages;

namespace EventStore.ClientAPI
Expand Down Expand Up @@ -65,6 +66,20 @@ public class RecordedEvent
/// </summary>
public readonly byte[] Metadata;


#if DEBUG
public string DebugDataView
{
get { return Encoding.UTF8.GetString(Data); }
}

public string DebugMetadataView
{
get { return Encoding.UTF8.GetString(Metadata); }
}
#endif


internal RecordedEvent(ClientMessage.EventRecord systemRecord)
{
EventStreamId = systemRecord.EventStreamId;
Expand Down
2 changes: 1 addition & 1 deletion src/EventStore/EventStore.ClientAPI/ResolvedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal ResolvedEvent(ClientMessage.ResolvedEvent evnt)

internal ResolvedEvent(ClientMessage.ResolvedIndexedEvent evnt)
{
Event = new RecordedEvent(evnt.Event);
Event = evnt.Event == null ? null : new RecordedEvent(evnt.Event);
Link = evnt.Link == null ? null : new RecordedEvent(evnt.Link);
OriginalPosition = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

namespace EventStore.Core.Tests.ClientAPI.Helpers
{
internal class TestEvent
public class TestEvent
{
public static EventData NewTestEvent(string data = null, string metadata = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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.
//

using EventStore.ClientAPI;
using EventStore.Core.Tests.ClientAPI.Helpers;
using EventStore.Core.Tests.Helpers;
using NUnit.Framework;

namespace EventStore.Core.Tests.ClientAPI
{
public abstract class SpecificationWithMiniNode : SpecificationWithDirectoryPerTestFixture
{
private MiniNode _node;
protected IEventStoreConnection _conn;

protected abstract void When();

[TestFixtureSetUp]
public override void TestFixtureSetUp()
{
base.TestFixtureSetUp();
_node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false);
_node.Start();
_conn = TestConnection.Create(_node.TcpEndPoint);
_conn.Connect();
When();
}

[TestFixtureTearDown]
public override void TestFixtureTearDown()
{
_conn.Close();
_node.Shutdown();
base.TestFixtureTearDown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,12 @@
namespace EventStore.Core.Tests.ClientAPI
{
[TestFixture, Category("LongRunning")]
public class read_all_events_backward_should: SpecificationWithDirectoryPerTestFixture
public class read_all_events_backward_should: SpecificationWithMiniNode
{
private MiniNode _node;
private IEventStoreConnection _conn;
private EventData[] _testEvents;

[TestFixtureSetUp]
public override void TestFixtureSetUp()
protected override void When()
{
base.TestFixtureSetUp();
_node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false);
_node.Start();
_conn = TestConnection.Create(_node.TcpEndPoint);
_conn.Connect();
_conn.SetStreamMetadata("$all", -1,
StreamMetadata.Build().SetReadRole(SystemRoles.All),
new UserCredentials(SystemUsers.Admin, SystemUsers.DefaultAdminPassword));
Expand All @@ -61,14 +53,6 @@ public override void TestFixtureSetUp()
_conn.AppendToStream("stream", ExpectedVersion.EmptyStream, _testEvents);
}

[TestFixtureTearDown]
public override void TestFixtureTearDown()
{
_conn.Close();
_node.Shutdown();
base.TestFixtureTearDown();
}

[Test, Category("LongRunning")]
public void return_empty_slice_if_asked_to_read_from_start()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,12 @@
namespace EventStore.Core.Tests.ClientAPI
{
[TestFixture, Category("LongRunning")]
public class read_all_events_forward_should: SpecificationWithDirectoryPerTestFixture
public class read_all_events_forward_should: SpecificationWithMiniNode
{
private MiniNode _node;
private IEventStoreConnection _conn;
private EventData[] _testEvents;

[TestFixtureSetUp]
public override void TestFixtureSetUp()
protected override void When()
{
base.TestFixtureSetUp();
_node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false);
_node.Start();
_conn = TestConnection.Create(_node.TcpEndPoint);
_conn.Connect();
_conn.SetStreamMetadata("$all", -1,
StreamMetadata.Build().SetReadRole(SystemRoles.All),
new UserCredentials(SystemUsers.Admin, SystemUsers.DefaultAdminPassword));
Expand All @@ -62,14 +54,6 @@ public override void TestFixtureSetUp()
_conn.AppendToStream("stream", ExpectedVersion.EmptyStream, _testEvents);
}

[TestFixtureTearDown]
public override void TestFixtureTearDown()
{
_conn.Close();
_node.Shutdown();
base.TestFixtureTearDown();
}

[Test, Category("LongRunning")]
public void return_empty_slice_if_asked_to_read_from_end()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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.
//

using System.Linq;
using EventStore.ClientAPI;
using EventStore.ClientAPI.SystemData;
using EventStore.Core.Data;
using EventStore.Core.Services;
using EventStore.Core.Tests.ClientAPI.Helpers;
using EventStore.Core.Tests.Helpers;
using NUnit.Framework;
using ExpectedVersion = EventStore.ClientAPI.ExpectedVersion;
using StreamMetadata = EventStore.ClientAPI.StreamMetadata;

namespace EventStore.Core.Tests.ClientAPI
{
[TestFixture, Category("LongRunning")]
public class read_all_events_forward_with_hard_deleted_stream_should : SpecificationWithMiniNode
{
private EventData[] _testEvents;

protected override void When()
{
_conn.SetStreamMetadata(
"$all", -1, StreamMetadata.Build().SetReadRole(SystemRoles.All),
new UserCredentials(SystemUsers.Admin, SystemUsers.DefaultAdminPassword));

_testEvents = Enumerable.Range(0, 20).Select(x => TestEvent.NewTestEvent(x.ToString())).ToArray();
_conn.AppendToStream("stream", ExpectedVersion.EmptyStream, _testEvents);
_conn.DeleteStream("stream", ExpectedVersion.Any, hardDelete: true);
}

[Test, Category("LongRunning")]
public void ensure_deleted_stream()
{
var res = _conn.ReadStreamEventsForward("stream", 0, 100, false);
Assert.AreEqual(SliceReadStatus.StreamDeleted, res.Status);
Assert.AreEqual(0, res.Events.Length);
}

[Test, Category("LongRunning")]
public void returns_all_events_including_tombstone()
{
AllEventsSlice read = _conn.ReadAllEventsForward(Position.Start, _testEvents.Length + 10, false);
Assert.That(
EventDataComparer.Equal(
_testEvents.ToArray(),
read.Events.Skip(read.Events.Length - _testEvents.Length - 1)
.Take(_testEvents.Length)
.Select(x => x.Event)
.ToArray()));
var lastEvent = read.Events.Last().Event;
Assert.AreEqual("stream", lastEvent.EventStreamId);
Assert.AreEqual(SystemEventTypes.StreamDeleted, lastEvent.EventType);
}
}
}
Loading

0 comments on commit bd283f8

Please sign in to comment.