Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Akka.Persistence.Query: include more descriptive ToString() values for all Offset types #6927 #6978

Merged
merged 3 commits into from
Oct 31, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace Akka.Persistence.Query
{
public static Akka.Persistence.Query.NoOffset Instance { get; }
public override int CompareTo(Akka.Persistence.Query.Offset other) { }
public override string ToString() { }
}
public abstract class Offset : System.IComparable<Akka.Persistence.Query.Offset>
{
Expand All @@ -72,6 +73,7 @@ namespace Akka.Persistence.Query
public static Akka.Persistence.Query.Offset NoOffset() { }
public static Akka.Persistence.Query.Offset Sequence(long value) { }
public static Akka.Persistence.Query.Offset TimeBasedUuid(System.Guid value) { }
public virtual string ToString() { }
}
public sealed class PersistenceQuery : Akka.Actor.IExtension
{
Expand Down Expand Up @@ -100,6 +102,7 @@ namespace Akka.Persistence.Query
public override int CompareTo(Akka.Persistence.Query.Offset other) { }
public override bool Equals(object obj) { }
public override int GetHashCode() { }
public override string ToString() { }
}
public sealed class TimeBasedUuid : Akka.Persistence.Query.Offset, System.IComparable<Akka.Persistence.Query.TimeBasedUuid>
{
Expand All @@ -109,5 +112,6 @@ namespace Akka.Persistence.Query
public override int CompareTo(Akka.Persistence.Query.Offset other) { }
public override bool Equals(object obj) { }
public override int GetHashCode() { }
public override string ToString() { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace Akka.Persistence.Query
{
public static Akka.Persistence.Query.NoOffset Instance { get; }
public override int CompareTo(Akka.Persistence.Query.Offset other) { }
public override string ToString() { }
}
public abstract class Offset : System.IComparable<Akka.Persistence.Query.Offset>
{
Expand All @@ -72,6 +73,7 @@ namespace Akka.Persistence.Query
public static Akka.Persistence.Query.Offset NoOffset() { }
public static Akka.Persistence.Query.Offset Sequence(long value) { }
public static Akka.Persistence.Query.Offset TimeBasedUuid(System.Guid value) { }
public virtual string ToString() { }
}
public sealed class PersistenceQuery : Akka.Actor.IExtension
{
Expand Down Expand Up @@ -100,6 +102,7 @@ namespace Akka.Persistence.Query
public override int CompareTo(Akka.Persistence.Query.Offset other) { }
public override bool Equals(object obj) { }
public override int GetHashCode() { }
public override string ToString() { }
}
public sealed class TimeBasedUuid : Akka.Persistence.Query.Offset, System.IComparable<Akka.Persistence.Query.TimeBasedUuid>
{
Expand All @@ -109,5 +112,6 @@ namespace Akka.Persistence.Query
public override int CompareTo(Akka.Persistence.Query.Offset other) { }
public override bool Equals(object obj) { }
public override int GetHashCode() { }
public override string ToString() { }
}
}
19 changes: 19 additions & 0 deletions src/core/Akka.Persistence.Query.Tests/OffsetSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,24 @@ public void Sequence_offset_must_be_ordered_correctly()
var shuffledSequenceBasedList = sequenceBasedList.OrderBy(_ => Guid.NewGuid());
shuffledSequenceBasedList.Should().BeEquivalentTo(sequenceBasedList);
}

[Fact]
public void Sequence_must_log_value_correctly()
{
Assert.Equal("7", new Sequence(7).ToString());
}

[Fact]
public void TimeBasedUuid_must_log_value_correctly()
{
var timeBasedUuid = new TimeBasedUuid(new Guid("49225740-2019-11ea-a6f0-a0a60c2ef4ff"));
Assert.Equal("49225740-2019-11ea-a6f0-a0a60c2ef4ff", timeBasedUuid.ToString());
}

[Fact]
public void NoOffset_must_log_zero()
{
Assert.Equal("0", NoOffset.Instance.ToString());
}
}
}
11 changes: 11 additions & 0 deletions src/core/Akka.Persistence.Query/Offset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public abstract class Offset : IComparable<Offset>
/// </summary>
/// <param name="other">The other offset to compare.</param>
public abstract int CompareTo(Offset other);

/// <summary>
/// Used to log offset's value
/// </summary>
public abstract override string ToString();
}

/// <summary>
Expand Down Expand Up @@ -83,6 +88,8 @@ public override int CompareTo(Offset other)

throw new InvalidOperationException($"Can't compare offset of type {GetType()} to offset of type {other.GetType()}");
}

public override string ToString() => Value.ToString();
}

/// <summary>
Expand Down Expand Up @@ -123,6 +130,8 @@ public override int CompareTo(Offset other)
? CompareTo(seq)
: throw new InvalidOperationException($"Can't compare offset of type {GetType()} to offset of type {other.GetType()}");
}

public override string ToString() => Value.ToString();
}

/// <summary>
Expand All @@ -145,5 +154,7 @@ public override int CompareTo(Offset other)

throw new InvalidOperationException($"Can't compare offset of type {GetType()} to offset of type {other.GetType()}");
}

public override string ToString() => "0";
}
}
Loading