Skip to content

Commit

Permalink
Revert #7349 and #7352 (#7353)
Browse files Browse the repository at this point in the history
* Revert "Fix unit tests related to the Persistence DateTime bug (#7352)"

This reverts commit f5c4e63.

* Revert "Fix DateTimeOffset.DateTime UTC bug (#7349)"

This reverts commit 33fd92d.
  • Loading branch information
Arkatufus authored Oct 3, 2024
1 parent f5c4e63 commit e5aebed
Show file tree
Hide file tree
Showing 17 changed files with 15 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ namespace Akka.Actor
[System.ObsoleteAttribute("This class will be removed in Akka.NET v1.6.0 - use the IScheduler instead.")]
public class DateTimeOffsetNowTimeProvider : Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider
{
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public static Akka.Actor.DateTimeOffsetNowTimeProvider Instance { get; }
public System.TimeSpan MonotonicClock { get; }
Expand Down Expand Up @@ -933,7 +932,6 @@ namespace Akka.Actor
public sealed class HashedWheelTimerScheduler : Akka.Actor.SchedulerBase, Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider, System.IDisposable
{
public HashedWheelTimerScheduler(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected override System.DateTime DateTimeNow { get; }
public override System.TimeSpan HighResMonotonicClock { get; }
public override System.TimeSpan MonotonicClock { get; }
protected override System.DateTimeOffset TimeNow { get; }
Expand Down Expand Up @@ -1174,7 +1172,6 @@ namespace Akka.Actor
}
public interface ITimeProvider
{
System.DateTime DateTimeNow { get; }
System.TimeSpan HighResMonotonicClock { get; }
System.TimeSpan MonotonicClock { get; }
System.DateTimeOffset Now { get; }
Expand Down Expand Up @@ -1625,7 +1622,6 @@ namespace Akka.Actor
protected readonly Akka.Event.ILoggingAdapter Log;
protected readonly Akka.Configuration.Config SchedulerConfig;
protected SchedulerBase(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected abstract System.DateTime DateTimeNow { get; }
public abstract System.TimeSpan HighResMonotonicClock { get; }
public abstract System.TimeSpan MonotonicClock { get; }
protected abstract System.DateTimeOffset TimeNow { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ namespace Akka.Actor
[System.ObsoleteAttribute("This class will be removed in Akka.NET v1.6.0 - use the IScheduler instead.")]
public class DateTimeOffsetNowTimeProvider : Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider
{
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public static Akka.Actor.DateTimeOffsetNowTimeProvider Instance { get; }
public System.TimeSpan MonotonicClock { get; }
Expand Down Expand Up @@ -931,7 +930,6 @@ namespace Akka.Actor
public sealed class HashedWheelTimerScheduler : Akka.Actor.SchedulerBase, Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider, System.IDisposable
{
public HashedWheelTimerScheduler(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected override System.DateTime DateTimeNow { get; }
public override System.TimeSpan HighResMonotonicClock { get; }
public override System.TimeSpan MonotonicClock { get; }
protected override System.DateTimeOffset TimeNow { get; }
Expand Down Expand Up @@ -1172,7 +1170,6 @@ namespace Akka.Actor
}
public interface ITimeProvider
{
System.DateTime DateTimeNow { get; }
System.TimeSpan HighResMonotonicClock { get; }
System.TimeSpan MonotonicClock { get; }
System.DateTimeOffset Now { get; }
Expand Down Expand Up @@ -1623,7 +1620,6 @@ namespace Akka.Actor
protected readonly Akka.Event.ILoggingAdapter Log;
protected readonly Akka.Configuration.Config SchedulerConfig;
protected SchedulerBase(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected abstract System.DateTime DateTimeNow { get; }
public abstract System.TimeSpan HighResMonotonicClock { get; }
public abstract System.TimeSpan MonotonicClock { get; }
protected abstract System.DateTimeOffset TimeNow { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ namespace Akka.TestKit
{
public TestScheduler(Akka.Configuration.Config schedulerConfig, Akka.Event.ILoggingAdapter log) { }
public Akka.Actor.IAdvancedScheduler Advanced { get; }
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public System.TimeSpan MonotonicClock { get; }
public System.DateTimeOffset Now { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ namespace Akka.TestKit
{
public TestScheduler(Akka.Configuration.Config schedulerConfig, Akka.Event.ILoggingAdapter log) { }
public Akka.Actor.IAdvancedScheduler Advanced { get; }
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public System.TimeSpan MonotonicClock { get; }
public System.DateTimeOffset Now { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override void AfterAll()
public void LocalSnapshotStore_can_snapshot_actors_with_PersistenceId_containing_invalid_path_characters()
{
var pid = @"p\/:*?-1";
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(pid, 1, Sys.Scheduler.DateTimeNow), "sample data"), TestActor);
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(pid, 1, Sys.Scheduler.Now.DateTime), "sample data"), TestActor);
ExpectMsg<SaveSnapshotSuccess>();

SnapshotStore.Tell(new LoadSnapshot(pid, SnapshotSelectionCriteria.Latest, long.MaxValue), TestActor);
Expand Down
3 changes: 1 addition & 2 deletions src/core/Akka.Persistence.TCK/Query/PersistenceIdsSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ protected IActorRef WriteSnapshot(string persistenceId, int n)
ExpectMsg($"{persistenceId}-{i}-done");
}

var metadata = new SnapshotMetadata(persistenceId, n + 10, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(persistenceId, n + 10, Sys.Scheduler.Now.DateTime);
SnapshotStore.Tell(new SaveSnapshot(metadata, $"s-{n}"), _senderProbe.Ref);
_senderProbe.ExpectMsg<SaveSnapshotSuccess>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public virtual void SnapshotStore_should_serialize_Payload()

var snapshot = new Test.MySnapshot("a");

var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.Now.DateTime);
SnapshotStore.Tell(new SaveSnapshot(metadata, snapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -86,8 +85,7 @@ public virtual void SnapshotStore_should_serialize_Payload_with_string_manifest(

var snapshot = new Test.MySnapshot2("a");

var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, 1, Sys.Scheduler.Now.DateTime);
SnapshotStore.Tell(new SaveSnapshot(metadata, snapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -109,8 +107,7 @@ public virtual void SnapshotStore_should_serialize_AtLeastOnceDeliverySnapshot()
};
var atLeastOnceDeliverySnapshot = new AtLeastOnceDeliverySnapshot(17, unconfirmed);

var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.Now.DateTime);
SnapshotStore.Tell(new SaveSnapshot(metadata, atLeastOnceDeliverySnapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -126,8 +123,7 @@ public virtual void SnapshotStore_should_serialize_AtLeastOnceDeliverySnapshot_w
var unconfirmed = Array.Empty<UnconfirmedDelivery>();
var atLeastOnceDeliverySnapshot = new AtLeastOnceDeliverySnapshot(13, unconfirmed);

var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.Now.DateTime);
SnapshotStore.Tell(new SaveSnapshot(metadata, atLeastOnceDeliverySnapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand All @@ -142,8 +138,7 @@ public virtual void SnapshotStore_should_serialize_PersistentFSMSnapshot()

var persistentFSMSnapshot = new PersistentFSM.PersistentFSMSnapshot<string>("mystate", "mydata", TimeSpan.FromDays(4));

var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, 2, Sys.Scheduler.Now.DateTime);
SnapshotStore.Tell(new SaveSnapshot(metadata, persistentFSMSnapshot), probe.Ref);
probe.ExpectMsg<SaveSnapshotSuccess>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,14 @@ public async Task MultipleSnapshotsWithSameSeqNo()
var snapshotStore = persistence.SnapshotStoreFor(null);
var snap = new TestPayload(SenderProbe.Ref);

var metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.UtcNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.Now);
snapshotStore.Tell(new SaveSnapshot(metadata, snap), SenderProbe);
var success = await SenderProbe.ExpectMsgAsync<SaveSnapshotSuccess>(10.Minutes());
success.Metadata.PersistenceId.Should().Be(metadata.PersistenceId);
success.Metadata.Timestamp.Should().Be(metadata.Timestamp);
success.Metadata.SequenceNr.Should().Be(metadata.SequenceNr);

metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.UtcNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
metadata = new SnapshotMetadata(PersistenceId, 3, DateTime.Now);
snapshotStore.Tell(new SaveSnapshot(metadata, 3), SenderProbe);
success = await SenderProbe.ExpectMsgAsync<SaveSnapshotSuccess>();
success.Metadata.PersistenceId.Should().Be(metadata.PersistenceId);
Expand Down
9 changes: 3 additions & 6 deletions src/core/Akka.Persistence.TCK/Snapshot/SnapshotStoreSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ private IEnumerable<SnapshotMetadata> WriteSnapshots()
{
for (int i = 1; i <= 5; i++)
{
var metadata = new SnapshotMetadata(Pid, i + 10, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, i + 10, Sys.Scheduler.Now.DateTime);
SnapshotStore.Tell(new SaveSnapshot(metadata, $"s-{i}"), _senderProbe.Ref);
yield return _senderProbe.ExpectMsg<SaveSnapshotSuccess>().Metadata;
}
Expand Down Expand Up @@ -313,8 +312,7 @@ public virtual void SnapshotStore_should_save_and_overwrite_snapshot_with_same_s
[Fact]
public virtual void SnapshotStore_should_save_bigger_size_snapshot()
{
var metadata = new SnapshotMetadata(Pid, 100, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, 100, Sys.Scheduler.Now.DateTime);
var bigSnapshot = new byte[SnapshotByteSizeLimit];
new Random().NextBytes(bigSnapshot);
SnapshotStore.Tell(new SaveSnapshot(metadata, bigSnapshot), _senderProbe.Ref);
Expand All @@ -328,8 +326,7 @@ public virtual void ShouldSerializeSnapshots()
if (!SupportsSerialization) return;

var probe = CreateTestProbe();
var metadata = new SnapshotMetadata(Pid, 100L, Sys.Scheduler.DateTimeNow);
metadata.Timestamp.Kind.Should().Be(DateTimeKind.Utc);
var metadata = new SnapshotMetadata(Pid, 100L, Sys.Scheduler.Now.DateTime);
var snap = new TestPayload(probe.Ref);

SnapshotStore.Tell(new SaveSnapshot(metadata, snap), _senderProbe.Ref);
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Persistence/Eventsourced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void LoadSnapshot(string persistenceId, SnapshotSelectionCriteria criteri
/// <param name="snapshot">TBD</param>
public void SaveSnapshot(object snapshot)
{
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(SnapshotterId, SnapshotSequenceNr, Context.System.Scheduler.DateTimeNow), snapshot));
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(SnapshotterId, SnapshotSequenceNr, Context.System.Scheduler.Now.Date), snapshot));
}

/// <summary>
Expand Down
4 changes: 0 additions & 4 deletions src/core/Akka.TestKit/TestScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ public void ScheduleRepeatedly(TimeSpan initialDelay, TimeSpan interval, Action
/// <summary>
/// TBD
/// </summary>
public DateTime DateTimeNow { get { return DateTime.SpecifyKind(_now.DateTime, DateTimeKind.Utc); } }
/// <summary>
/// TBD
/// </summary>
public TimeSpan MonotonicClock { get { return Util.MonotonicClock.Elapsed; } }
/// <summary>
/// TBD
Expand Down
1 change: 0 additions & 1 deletion src/core/Akka.Tests/Actor/ActorSystemSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ public void ScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICa
}

public DateTimeOffset Now { get; private set; }
public DateTime DateTimeNow { get; private set; }
public TimeSpan MonotonicClock { get; private set; }
public TimeSpan HighResMonotonicClock { get; private set; }
public IAdvancedScheduler Advanced { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private class ShutdownScheduler : SchedulerBase, IDisposable


protected override DateTimeOffset TimeNow { get; }
protected override DateTime DateTimeNow { get; }
public override TimeSpan MonotonicClock { get; }
public override TimeSpan HighResMonotonicClock { get; }

Expand Down
2 changes: 0 additions & 2 deletions src/core/Akka/Actor/Scheduler/DateTimeNowTimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ private DateTimeOffsetNowTimeProvider() { }

public DateTimeOffset Now { get { return DateTimeOffset.UtcNow; } }

public DateTime DateTimeNow => DateTime.UtcNow;

public TimeSpan MonotonicClock {get { return Util.MonotonicClock.Elapsed; }}

public TimeSpan HighResMonotonicClock{get { return Util.MonotonicClock.ElapsedHighRes; }}
Expand Down
5 changes: 0 additions & 5 deletions src/core/Akka/Actor/Scheduler/HashedWheelTimerScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,6 @@ private void PlaceInBucket(SchedulerRegistration reg)
/// </summary>
protected override DateTimeOffset TimeNow => DateTimeOffset.UtcNow;

/// <summary>
/// TBD
/// </summary>
protected override DateTime DateTimeNow => DateTime.UtcNow;

/// <summary>
/// TBD
/// </summary>
Expand Down
6 changes: 1 addition & 5 deletions src/core/Akka/Actor/Scheduler/ITimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ namespace Akka.Actor
public interface ITimeProvider
{
/// <summary>
/// Gets the scheduler's notion of current time in <see cref="DateTimeOffset"/>.
/// Gets the scheduler's notion of current time.
/// </summary>
DateTimeOffset Now { get; }
/// <summary>
/// Gets the scheduler's notion of current time in <see cref="DateTime"/>.
/// </summary>
DateTime DateTimeNow { get; }
/// <summary>
/// TBD
/// </summary>
TimeSpan MonotonicClock { get; }
Expand Down
9 changes: 1 addition & 8 deletions src/core/Akka/Actor/Scheduler/SchedulerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,11 @@ void IActionScheduler.ScheduleRepeatedly(TimeSpan initialDelay, TimeSpan interva
IAdvancedScheduler IScheduler.Advanced { get { return this; } }
DateTimeOffset ITimeProvider.Now { get { return TimeNow; } }

DateTime ITimeProvider.DateTimeNow => DateTime.SpecifyKind(TimeNow.DateTime, DateTimeKind.Utc);

/// <summary>
/// The current time in <see cref="DateTimeOffset"/> UTC.
/// The current time in UTC.
/// </summary>
protected abstract DateTimeOffset TimeNow { get; }

/// <summary>
/// The current time in <see cref="DateTime"/> UTC.
/// </summary>
protected abstract DateTime DateTimeNow { get; }

/// <summary>
/// The current time since startup, as determined by the monotonic clock implementation.
/// </summary>
Expand Down

0 comments on commit e5aebed

Please sign in to comment.