Skip to content

Commit

Permalink
(wip) TestSnapshotStore
Browse files Browse the repository at this point in the history
  • Loading branch information
valdisz committed Aug 14, 2019
1 parent 17ac3b3 commit aceb9aa
Show file tree
Hide file tree
Showing 22 changed files with 393 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------
// <copyright file="IJournalBehaviorSetter.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System.Threading.Tasks;

public interface IJournalBehaviorSetter
{
Task SetInterceptorAsync(IJournalInterceptor interceptor);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
// <copyright file="IJournalBehaviorSetter.cs" company="Akka.NET Project">
// <copyright file="JournalRecoveryBehaviorSetter.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
Expand All @@ -11,27 +11,6 @@ namespace Akka.Persistence.TestKit
using System.Threading.Tasks;
using Actor;

public interface IJournalBehaviorSetter
{
Task SetInterceptorAsync(IJournalInterceptor interceptor);
}

internal class JournalWriteBehaviorSetter : IJournalBehaviorSetter
{
internal JournalWriteBehaviorSetter(IActorRef journal)
{
this._journal = journal;
}

private readonly IActorRef _journal;

public Task SetInterceptorAsync(IJournalInterceptor interceptor)
=> _journal.Ask<TestJournal.Ack>(
new TestJournal.UseWriteInterceptor(interceptor),
TimeSpan.FromSeconds(3)
);
}

internal class JournalRecoveryBehaviorSetter : IJournalBehaviorSetter
{
internal JournalRecoveryBehaviorSetter(IActorRef journal)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//-----------------------------------------------------------------------
// <copyright file="JournalWriteBehaviorSetter.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System;
using System.Threading.Tasks;
using Actor;

internal class JournalWriteBehaviorSetter : IJournalBehaviorSetter
{
internal JournalWriteBehaviorSetter(IActorRef journal)
{
this._journal = journal;
}

private readonly IActorRef _journal;

public Task SetInterceptorAsync(IJournalInterceptor interceptor)
=> _journal.Ask<TestJournal.Ack>(
new TestJournal.UseWriteInterceptor(interceptor),
TimeSpan.FromSeconds(3)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// -----------------------------------------------------------------------
// <copyright file="ISnapshotStoreBehaviorSetter.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System.Threading.Tasks;

public interface ISnapshotStoreBehaviorSetter
{
Task SetInterceptorAsync(ISnapshotStoreInterceptor interceptor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------
// <copyright file="ISnapshotStoreInterceptor.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System.Threading.Tasks;

public interface ISnapshotStoreInterceptor
{
Task Intercept(string persistenceId, SnapshotSelectionCriteria criteria);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------
// <copyright file="ITestSnapshotStore.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
public interface ITestSnapshotStore
{
SnapshotStoreSaveBehavior OnSave { get; }
SnapshotStoreLoadBehavior OnLoad { get; }
SnapshotStoreDeleteBehavior OnDelete { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// -----------------------------------------------------------------------
// <copyright file="SnapshotStoreDeleteBehavior.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
public class SnapshotStoreDeleteBehavior : SnapshotStoreSaveBehavior
{
public SnapshotStoreDeleteBehavior(ISnapshotStoreBehaviorSetter setter) : base(setter)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -----------------------------------------------------------------------
// <copyright file="SnapshotStoreDeleteBehaviorSetter.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System;
using System.Threading.Tasks;
using Actor;

internal class SnapshotStoreDeleteBehaviorSetter : ISnapshotStoreBehaviorSetter
{
internal SnapshotStoreDeleteBehaviorSetter(IActorRef snapshots)
{
this._snapshots = snapshots;
}

private readonly IActorRef _snapshots;

public Task SetInterceptorAsync(ISnapshotStoreInterceptor interceptor)
=> _snapshots.Ask<TestSnapshotStore.Ack>(
new TestSnapshotStore.UseDeleteInterceptor(interceptor),
TimeSpan.FromSeconds(3)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//-----------------------------------------------------------------------
// <copyright file="SnapshotStoreInterceptors.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System.Threading.Tasks;

internal static class SnapshotStoreInterceptors
{
internal class Failure : ISnapshotStoreInterceptor
{
public Task Intercept(string persistenceId, SnapshotSelectionCriteria criteria)
{
throw new TestSnapshotStoreFailureException();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// -----------------------------------------------------------------------
// <copyright file="SnapshotStoreLoadBehavior.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
public class SnapshotStoreLoadBehavior : SnapshotStoreSaveBehavior
{
public SnapshotStoreLoadBehavior(ISnapshotStoreBehaviorSetter setter) : base(setter)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -----------------------------------------------------------------------
// <copyright file="SnapshotStoreLoadBehaviorSetter.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System;
using System.Threading.Tasks;
using Actor;

internal class SnapshotStoreLoadBehaviorSetter : ISnapshotStoreBehaviorSetter
{
internal SnapshotStoreLoadBehaviorSetter(IActorRef snapshots)
{
this._snapshots = snapshots;
}

private readonly IActorRef _snapshots;

public Task SetInterceptorAsync(ISnapshotStoreInterceptor interceptor)
=> _snapshots.Ask<TestSnapshotStore.Ack>(
new TestSnapshotStore.UseLoadInterceptor(interceptor),
TimeSpan.FromSeconds(3)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//-----------------------------------------------------------------------
// <copyright file="SnapshotStoreSaveBehavior.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
public class SnapshotStoreSaveBehavior
{
public SnapshotStoreSaveBehavior(ISnapshotStoreBehaviorSetter setter)
{
Setter = setter;
}

protected readonly ISnapshotStoreBehaviorSetter Setter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -----------------------------------------------------------------------
// <copyright file="SnapshotStoreSaveBehaviorSetter.cs" company="Akka.NET Project">
// Copyright (C) 2009-2019 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2019 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

namespace Akka.Persistence.TestKit
{
using System;
using System.Threading.Tasks;
using Actor;

internal class SnapshotStoreSaveBehaviorSetter : ISnapshotStoreBehaviorSetter
{
internal SnapshotStoreSaveBehaviorSetter(IActorRef snapshots)
{
this._snapshots = snapshots;
}

private readonly IActorRef _snapshots;

public Task SetInterceptorAsync(ISnapshotStoreInterceptor interceptor)
=> _snapshots.Ask<TestSnapshotStore.Ack>(
new TestSnapshotStore.UseSaveInterceptor(interceptor),
TimeSpan.FromSeconds(3)
);
}
}
Loading

0 comments on commit aceb9aa

Please sign in to comment.