Skip to content

Commit

Permalink
Expose Tags property in EventEnvelope (#6862)
Browse files Browse the repository at this point in the history
* Expose `Tags` property in `EventEnvelope`

* update API approval list

* Change `Tags` default value from `null` to empty array

* Update API approval list
  • Loading branch information
Arkatufus authored Aug 1, 2023
1 parent 4df9a60 commit 147d039
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ public InMemoryCurrentEventsByTagSpec(ITestOutputHelper output) :
{
ReadJournal = Sys.ReadJournalFor<InMemoryReadJournal>(InMemoryReadJournal.Identifier);
}

protected override bool SupportsTagsInEventEnvelope => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ public InMemoryEventsByTagSpec(ITestOutputHelper output) :
{
ReadJournal = Sys.ReadJournalFor<InMemoryReadJournal>(InMemoryReadJournal.Identifier);
}

protected override bool SupportsTagsInEventEnvelope => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ protected bool Replaying( object message)
if (replayed.Offset > ToOffset)
return true;

// NOTES: tags is empty because tags are not retrieved from the database query (as of this writing)
Buffer.Add(new EventEnvelope(
offset: new Sequence(replayed.Offset),
persistenceId: replayed.Persistent.PersistenceId,
sequenceNr: replayed.Persistent.SequenceNr,
@event: replayed.Persistent.Payload,
timestamp: replayed.Persistent.Timestamp));
timestamp: replayed.Persistent.Timestamp,
tags: Array.Empty<string>()));

CurrentOffset = replayed.Offset + 1;
Buffer.DeliverBuffer(TotalDemand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ protected Receive Replaying(int limit)
{
case ReplayedMessage replayed:
var seqNr = replayed.Persistent.SequenceNr;
// NOTES: tags is empty because tags are not retrieved from the database query (as of this writing)
Buffer.Add(new EventEnvelope(
offset: new Sequence(seqNr),
persistenceId: PersistenceId,
sequenceNr: seqNr,
@event: replayed.Persistent.Payload,
timestamp: replayed.Persistent.Timestamp));
timestamp: replayed.Persistent.Timestamp,
tags: Array.Empty<string>()));
CurrentSequenceNr = seqNr + 1;
Buffer.DeliverBuffer(TotalDemand);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ protected Receive Replaying(int limit)
persistenceId: replayed.Persistent.PersistenceId,
sequenceNr: replayed.Persistent.SequenceNr,
@event: replayed.Persistent.Payload,
timestamp: replayed.Persistent.Timestamp));
timestamp: replayed.Persistent.Timestamp,
tags: new [] { replayed.Tag }));
CurrentOffset = replayed.Offset + 1;
Buffer.DeliverBuffer(TotalDemand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ protected bool Replaying( object message )
if (replayed.Offset > ToOffset)
return true;

// NOTES: tags is empty because tags are not retrieved from the database query (as of this writing)
Buffer.Add(new EventEnvelope(
offset: new Sequence(replayed.Offset),
persistenceId: replayed.Persistent.PersistenceId,
sequenceNr: replayed.Persistent.SequenceNr,
@event: replayed.Persistent.Payload,
timestamp: replayed.Persistent.Timestamp));
timestamp: replayed.Persistent.Timestamp,
tags: Array.Empty<string>()));

CurrentOffset = replayed.Offset;
Buffer.DeliverBuffer(TotalDemand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ protected bool Replaying(object message)
{
case ReplayedMessage replayed:
var seqNr = replayed.Persistent.SequenceNr;
// NOTES: tags is empty because tags are not retrieved from the database query (as of this writing)
Buffer.Add(new EventEnvelope(
offset: new Sequence(seqNr),
persistenceId: PersistenceId,
sequenceNr: seqNr,
@event: replayed.Persistent.Payload,
timestamp: replayed.Persistent.Timestamp));
timestamp: replayed.Persistent.Timestamp,
tags: Array.Empty<string>()));
CurrentSequenceNr = seqNr + 1;
Buffer.DeliverBuffer(TotalDemand);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ protected bool Replaying(object message)
persistenceId: replayed.Persistent.PersistenceId,
sequenceNr: replayed.Persistent.SequenceNr,
@event: replayed.Persistent.Payload,
timestamp: replayed.Persistent.Timestamp));
timestamp: replayed.Persistent.Timestamp,
tags: new [] { replayed.Tag }));

CurrentOffset = replayed.Offset;
Buffer.DeliverBuffer(TotalDemand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public SqliteCurrentEventsByTagSpec(ITestOutputHelper output) : base(Config(Coun
{
ReadJournal = Sys.ReadJournalFor<SqlReadJournal>(SqlReadJournal.Identifier);
}

protected override bool SupportsTagsInEventEnvelope => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public SqliteEventsByTagSpec(ITestOutputHelper output) : base(Config(Counter.Get
{
ReadJournal = Sys.ReadJournalFor<SqlReadJournal>(SqlReadJournal.Identifier);
}

protected override bool SupportsTagsInEventEnvelope => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")]
namespace Akka.Persistence.Query
{
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class EventEnvelope : System.IEquatable<Akka.Persistence.Query.EventEnvelope>
{
[System.ObsoleteAttribute("For binary compatibility with previous releases")]
[System.ObsoleteAttribute("For binary compatibility with previous releases. Since 1.4.14")]
public EventEnvelope(Akka.Persistence.Query.Offset offset, string persistenceId, long sequenceNr, object @event) { }
[System.ObsoleteAttribute("For binary compatibility with previous releases. Since 1.5.11")]
public EventEnvelope(Akka.Persistence.Query.Offset offset, string persistenceId, long sequenceNr, object @event, long timestamp) { }
public EventEnvelope(Akka.Persistence.Query.Offset offset, string persistenceId, long sequenceNr, object @event, long timestamp, string[] tags) { }
public object Event { get; }
public Akka.Persistence.Query.Offset Offset { get; }
public string PersistenceId { get; }
public long SequenceNr { get; }
public string[] Tags { get; }
public long Timestamp { get; }
public bool Equals(Akka.Persistence.Query.EventEnvelope other) { }
public override bool Equals(object obj) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
namespace Akka.Persistence.Query
{
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class EventEnvelope : System.IEquatable<Akka.Persistence.Query.EventEnvelope>
{
[System.ObsoleteAttribute("For binary compatibility with previous releases")]
[System.ObsoleteAttribute("For binary compatibility with previous releases. Since 1.4.14")]
public EventEnvelope(Akka.Persistence.Query.Offset offset, string persistenceId, long sequenceNr, object @event) { }
[System.ObsoleteAttribute("For binary compatibility with previous releases. Since 1.5.11")]
public EventEnvelope(Akka.Persistence.Query.Offset offset, string persistenceId, long sequenceNr, object @event, long timestamp) { }
public EventEnvelope(Akka.Persistence.Query.Offset offset, string persistenceId, long sequenceNr, object @event, long timestamp, string[] tags) { }
public object Event { get; }
public Akka.Persistence.Query.Offset Offset { get; }
public string PersistenceId { get; }
public long SequenceNr { get; }
public string[] Tags { get; }
public long Timestamp { get; }
public bool Equals(Akka.Persistence.Query.EventEnvelope other) { }
public override bool Equals(object obj) { }
Expand Down
23 changes: 16 additions & 7 deletions src/core/Akka.Persistence.Query/EventEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;

#nullable enable
namespace Akka.Persistence.Query
{
/// <summary>
Expand All @@ -23,21 +24,27 @@ public sealed class EventEnvelope : IEquatable<EventEnvelope>
/// <summary>
/// Initializes a new instance of the <see cref="EventEnvelope"/> class.
/// </summary>
[Obsolete("For binary compatibility with previous releases")]
[Obsolete("For binary compatibility with previous releases. Since 1.4.14")]
public EventEnvelope(Offset offset, string persistenceId, long sequenceNr, object @event)
: this(offset, persistenceId, sequenceNr, @event, 0L)
: this(offset, persistenceId, sequenceNr, @event, 0L, Array.Empty<string>())
{ }

/// <summary>
/// Initializes a new instance of the <see cref="EventEnvelope"/> class.
/// </summary>
[Obsolete("For binary compatibility with previous releases. Since 1.5.11")]
public EventEnvelope(Offset offset, string persistenceId, long sequenceNr, object @event, long timestamp)
: this(offset, persistenceId, sequenceNr, @event, timestamp, Array.Empty<string>())
{ }

public EventEnvelope(Offset offset, string persistenceId, long sequenceNr, object @event, long timestamp, string[] tags)
{
Offset = offset;
PersistenceId = persistenceId;
SequenceNr = sequenceNr;
Event = @event;
Timestamp = timestamp;
Tags = tags ?? Array.Empty<string>();
}

public Offset Offset { get; }
Expand All @@ -50,28 +57,30 @@ public EventEnvelope(Offset offset, string persistenceId, long sequenceNr, objec

public long Timestamp { get; }

public bool Equals(EventEnvelope other)
public string[] Tags { get; }

public bool Equals(EventEnvelope? other)
{
if (ReferenceEquals(this, other)) return true;
if (ReferenceEquals(other, null)) return false;

// timestamp not included in Equals for backwards compatibility
// Timestamp and Tags not included in Equals for backwards compatibility
return Offset == other.Offset
&& PersistenceId == other.PersistenceId
&& SequenceNr == other.SequenceNr
&& Equals(Event, other.Event);
}

public override bool Equals(object obj) => obj is EventEnvelope evt && Equals(evt);
public override bool Equals(object? obj) => obj is EventEnvelope evt && Equals(evt);

public override int GetHashCode()
{
unchecked
{
var hashCode = Offset.GetHashCode();
hashCode = (hashCode*397) ^ (PersistenceId != null ? PersistenceId.GetHashCode() : 0);
hashCode = (hashCode*397) ^ (PersistenceId?.GetHashCode() ?? 0);
hashCode = (hashCode*397) ^ SequenceNr.GetHashCode();
hashCode = (hashCode*397) ^ (Event != null ? Event.GetHashCode() : 0);
hashCode = (hashCode*397) ^ (Event?.GetHashCode() ?? 0);
return hashCode;
}
}
Expand Down
Loading

0 comments on commit 147d039

Please sign in to comment.