Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/codecov-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ProjectReference Include="..\..\..\EventSourcing.Backbone.Abstractions\EventSourcing.Backbone.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.7.107.5" />
<PackageReference Include="AWSSDK.S3" Version="3.7.201.9" />
<PackageReference Include="Bnaya.Extensions.Json" Version="5.1.159" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.2.153</Version>
<Version>1.2.157</Version>
<PackageReleaseNotes>
# 1.2.85:
Breaking changes: S3Strategy was renamed to S3Storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
/// Used to retired an API version
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class EventSourceDeprecateVersionAttribute : Attribute
public class EventSourceDeprecateAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="EventsContractAttribute" /> class.
/// </summary>
/// <param name="type">The event target type.</param>
public EventSourceDeprecateVersionAttribute(EventsContractType type)
public EventSourceDeprecateAttribute(EventsContractType type)
{
Type = type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
namespace EventSourcing.Backbone.Tests.Entities
{
namespace EventSourcing.Backbone.Tests.Entities;

/// <summary>
/// Test contract
/// </summary>
public interface IVersionAwareBase
{
//[EventSourceVersion(Retired = 4)]
ValueTask ExecuteAsync(string key, int value);
[EventSourceVersion(1)]
ValueTask ExecuteAsync(int value);
[EventSourceVersion(2)]
ValueTask ExecuteAsync(DateTime value);
[EventSourceVersion(3)]
ValueTask ExecuteAsync(string value);
[EventSourceVersion(4)]
ValueTask ExecuteAsync(TimeSpan value);
[EventSourceVersion(3)]
ValueTask NotIncludesAsync(string value);
}
}
/// <summary>
/// Test contract
/// </summary>
public interface IVersionAwareBase
{
ValueTask ExecuteAsync(string key, int value);
[EventSourceVersion(1)]
ValueTask ExecuteAsync(int value);
[EventSourceVersion(2)]
ValueTask ExecuteAsync(DateTime value);
[EventSourceVersion(3)]
ValueTask ExecuteAsync(string value);
[EventSourceVersion(4)]
[EventSourceDeprecate(EventsContractType.Consumer, Date = "2023-08-02", Remark = "For testing")]
ValueTask ExecuteAsync(TimeSpan value);
[EventSourceVersion(3)]
ValueTask NotIncludesAsync(string value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#pragma warning disable S1133 // Deprecated code should be removed
using Microsoft.Extensions.Logging;

namespace EventSourcing.Backbone.Tests.Entities;

using Generated.VersionAwareDerivedFallback;

/// <summary>
/// Test contract
/// </summary>
[EventsContract(EventsContractType.Producer, MinVersion = 1, VersionNaming = VersionNaming.Append)]
[EventsContract(EventsContractType.Consumer, MinVersion = 2, VersionNaming = VersionNaming.AppendUnderscore)]
[Obsolete("This interface is base for code generation, please use ISimpleEventProducer or ISimpleEventConsumer")]
public interface IVersionAwareDerivedFallback: IVersionAwareBase
{
#region Fallback

/// <summary>
/// Consumers the fallback.
/// Excellent for Migration scenario
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="target">The target.</param>
/// <returns></returns>
public static async Task<bool> Fallback(IConsumerInterceptionContext ctx, IVersionAwareDerivedFallbackConsumer target)
{
ILogger logger = ctx.Logger;
ConsumerContext consumerContext = ctx.Context;
Metadata meta = consumerContext.Metadata;

if (ctx.IsMatchExecuteAsync_V0_String_Int32_Deprecated())
{
var data = await ctx.GetExecuteAsync_V0_String_Int32_DeprecatedAsync();
await target.Execute_3Async(consumerContext, $"{data.key}_{data.value}");
await ctx.AckAsync();
return true;
}
if (ctx.IsMatchExecuteAsync_V1_Int32_Deprecated())
{
var data = await ctx.GetExecuteAsync_V1_Int32_DeprecatedAsync();
await target.Execute_3Async(consumerContext, data.value.ToString());
await ctx.AckAsync();
return true;
}
if (ctx.IsMatchExecuteAsync_V4_TimeSpan_Deprecated())
{
var data = await ctx.GetExecuteAsync_V4_TimeSpan_DeprecatedAsync();
await target.Execute_3Async(consumerContext, data.value.ToString());
await ctx.AckAsync();
return true;
}

logger.LogWarning("Fallback didn't handle: {uri}, {signature}", meta.Uri, meta.Signature);
return false;
}

#endregion // Fallback
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,63 @@

using Microsoft.Extensions.Logging;

namespace EventSourcing.Backbone.Tests.Entities
namespace EventSourcing.Backbone.Tests.Entities;

using Generated.VersionAwareFallback;

/// <summary>
/// Test contract
/// </summary>
[EventsContract(EventsContractType.Producer, MinVersion = 1, VersionNaming = VersionNaming.Append)]
[EventsContract(EventsContractType.Consumer, MinVersion = 2, VersionNaming = VersionNaming.AppendUnderscore)]
[Obsolete("This interface is base for code generation, please use ISimpleEventProducer or ISimpleEventConsumer")]
public interface IVersionAwareFallback// : IVersionAwareBase
{
#region Fallback

/// <summary>
/// Test contract
/// Consumers the fallback.
/// Excellent for Migration scenario
/// </summary>
[EventsContract(EventsContractType.Producer, MinVersion = 1, VersionNaming = VersionNaming.Append)]
[EventsContract(EventsContractType.Consumer, MinVersion = 2, VersionNaming = VersionNaming.AppendUnderscore)]
[Obsolete("This interface is base for code generation, please use ISimpleEventProducer or ISimpleEventConsumer", true)]
public interface IVersionAwareFallback// : IVersionAwareBase
/// <param name="ctx">The context.</param>
/// <param name="target">The target.</param>
/// <returns></returns>
public static async Task<bool> Fallback(IConsumerInterceptionContext ctx, IVersionAwareFallbackConsumer target)
{
//[EventSourceVersion(Retired = 4)]
ValueTask ExecuteAsync(string key, int value);
[EventSourceVersion(1)]
ValueTask ExecuteAsync(int value);
[EventSourceVersion(2)]
ValueTask ExecuteAsync(DateTime value);
[EventSourceVersion(3)]
ValueTask ExecuteAsync(string value);
[EventSourceVersion(4)]
ValueTask ExecuteAsync(TimeSpan value);
[EventSourceVersion(3)]
ValueTask NotIncludesAsync(string value);
ILogger logger = ctx.Logger;
ConsumerContext consumerContext = ctx.Context;
Metadata meta = consumerContext.Metadata;

if (ctx.IsMatchExecuteAsync_V0_String_Int32_Deprecated())
{
var data = await ctx.GetExecuteAsync_V0_String_Int32_DeprecatedAsync();
await target.Execute_3Async(consumerContext, $"{data.key}_{data.value}");
await ctx.AckAsync();
return true;
}
if (ctx.IsMatchExecuteAsync_V1_Int32_Deprecated())
{
var data = await ctx.GetExecuteAsync_V1_Int32_DeprecatedAsync();
await target.Execute_3Async(consumerContext, data.value.ToString());
await ctx.AckAsync();
return true;
}

logger.LogWarning("Fallback didn't handle: {uri}, {signature}", meta.Uri, meta.Signature);
return false;
}

#endregion // Fallback

ValueTask ExecuteAsync(string key, int value);
[EventSourceVersion(1)]
ValueTask ExecuteAsync(int value);
[EventSourceVersion(2)]
ValueTask ExecuteAsync(DateTime value);
[EventSourceVersion(3)]
ValueTask ExecuteAsync(string value);
[EventSourceVersion(4)]
ValueTask ExecuteAsync(TimeSpan value);
[EventSourceVersion(3)]
ValueTask NotIncludesAsync(string value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using EventSourcing.Backbone.Building;
using EventSourcing.Backbone.Tests.Entities;

using FakeItEasy;

using Microsoft.Extensions.Logging;

using Xunit;
using Xunit.Abstractions;

namespace EventSourcing.Backbone.Tests;

public class EndToEndVersionAware_DerivedFallback_Tests : EndToEndVersionAwareBase
{
private readonly IVersionAwareDerivedFallbackConsumer _subscriber = A.Fake<IVersionAwareDerivedFallbackConsumer>();

#region Ctor

public EndToEndVersionAware_DerivedFallback_Tests(
ITestOutputHelper outputHelper,
Func<IProducerStoreStrategyBuilder, ILogger, IProducerStoreStrategyBuilder>? producerChannelBuilder = null,
Func<IConsumerStoreStrategyBuilder, ILogger, IConsumerStoreStrategyBuilder>? consumerChannelBuilder = null)
: base(outputHelper, producerChannelBuilder, consumerChannelBuilder)
{
A.CallTo(() => _subscriber.Execute_2Async(A<ConsumerContext>.Ignored, A<DateTime>.Ignored))
.ReturnsLazily(() => ValueTask.CompletedTask);
}

#endregion // Ctor

protected override string Name { get; } = "fallback-derived";

[Fact]
public async Task End2End_VersionAware_DerivedFallback_Test()
{
IVersionAwareDerivedFallbackProducer producer =
_producerBuilder
.Uri(URI)
.WithLogger(TestLogger.Create(_outputHelper))
.BuildVersionAwareDerivedFallbackProducer();

var ts = TimeSpan.FromSeconds(1);
await producer.Execute4Async(ts);
await producer.Execute1Async(10);
await producer.Execute2Async(DateTime.Now);
await producer.Execute1Async(11);

var cts = new CancellationTokenSource();

var subscription =
_consumerBuilder
.WithOptions(cfg => cfg with { MaxMessages = 4 })
.WithCancellation(cts.Token)
.Uri(URI)
.WithLogger(TestLogger.Create(_outputHelper))
.SubscribeVersionAwareDerivedFallbackConsumer(_subscriber);

await subscription.Completion;

A.CallTo(() => _subscriber.Execute_2Async(A<ConsumerContext>.Ignored, A<DateTime>.Ignored))
.MustHaveHappened();
A.CallTo(() => _subscriber.Execute_3Async(A<ConsumerContext>.Ignored, "10"))
.MustHaveHappened();
A.CallTo(() => _subscriber.Execute_3Async(A<ConsumerContext>.Ignored, "11"))
.MustHaveHappened();
A.CallTo(() => _subscriber.Execute_3Async(A<ConsumerContext>.Ignored, "00:00:01"))
.MustHaveHappened();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using Xunit;
using Xunit.Abstractions;



namespace EventSourcing.Backbone.Tests;

public class EndToEndVersionAware_Fallback_Tests : EndToEndVersionAwareBase
Expand All @@ -34,7 +32,7 @@ public EndToEndVersionAware_Fallback_Tests(

protected override string Name { get; } = "fallback";

[Fact(Skip = "fallback implementation is missing")]
[Fact]
public async Task End2End_VersionAware_Fallback_Test()
{
IVersionAwareFallbackProducer producer =
Expand All @@ -56,7 +54,6 @@ public async Task End2End_VersionAware_Fallback_Test()
.WithCancellation(cts.Token)
.Uri(URI)
.WithLogger(TestLogger.Create(_outputHelper))
// TODO: fallback
.SubscribeVersionAwareFallbackConsumer(_subscriber);

await subscription.Completion;
Expand All @@ -65,7 +62,9 @@ public async Task End2End_VersionAware_Fallback_Test()
.MustNotHaveHappened();
A.CallTo(() => _subscriber.Execute_4Async(A<ConsumerContext>.Ignored, ts))
.MustHaveHappenedOnceExactly();

throw new NotImplementedException();
A.CallTo(() => _subscriber.Execute_3Async(A<ConsumerContext>.Ignored, "10"))
.MustHaveHappened();
A.CallTo(() => _subscriber.Execute_3Async(A<ConsumerContext>.Ignored, "11"))
.MustHaveHappened();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<ItemGroup>
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.7" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
namespace EventSourcing.Backbone.UnitTests.Entities
{
namespace EventSourcing.Backbone.UnitTests;

/// <summary>
/// Test contract
/// </summary>
public interface IVersionAwareBase
{
//[EventSourceVersion(Retired = 4)]
ValueTask ExecuteAsync(string key, int value);
[EventSourceVersion(1)]
ValueTask ExecuteAsync(int value);
[EventSourceVersion(2)]
ValueTask ExecuteAsync(DateTime value);
[EventSourceVersion(3)]
ValueTask ExecuteAsync(string value);
[EventSourceVersion(4)]
ValueTask ExecuteAsync(TimeSpan value);
[EventSourceVersion(3)]
ValueTask NotIncludesAsync(string value);
}
}
/// <summary>
/// Test contract
/// </summary>
public interface IVersionAwareBase
{
ValueTask ExecuteAsync(string key, int value);
[EventSourceVersion(1)]
ValueTask ExecuteAsync(int value);
[EventSourceVersion(2)]
ValueTask ExecuteAsync(DateTime value);
[EventSourceVersion(3)]
ValueTask ExecuteAsync(string value);
[EventSourceVersion(4)]
[EventSourceDeprecate(EventsContractType.Consumer, Date = "2023-08-02", Remark = "For testing")]
ValueTask ExecuteAsync(TimeSpan value);
[EventSourceVersion(3)]
ValueTask NotIncludesAsync(string value);
}
Loading