Skip to content

Commit

Permalink
Improved naming
Browse files Browse the repository at this point in the history
  • Loading branch information
krzlabrdx committed Aug 18, 2022
1 parent 331ddfd commit 8340117
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static string AsUtcIsoDateToSecondsForLogs(this Instant instant)

public static Duration GetTimeAgo(this Instant instant)
{
return SystemClock.Instance.GetCurrentInstant() - instant;
return NodaTime.SystemClock.Instance.GetCurrentInstant() - instant;
}

public static Duration Absolute(this Duration duration)
Expand Down Expand Up @@ -117,12 +117,12 @@ public static string FormatSecondsHumanReadable(this Duration duration)

public static string FormatSecondsAgo(this Instant dateTime)
{
return $"{(SystemClock.Instance.GetCurrentInstant() - dateTime).FormatSecondsHumanReadable()} ago";
return $"{(NodaTime.SystemClock.Instance.GetCurrentInstant() - dateTime).FormatSecondsHumanReadable()} ago";
}

public static string FormatSecondsAgo(this Instant? dateTime)
{
return dateTime == null ? "never" : $"{(SystemClock.Instance.GetCurrentInstant() - dateTime.Value).FormatSecondsHumanReadable()} ago";
return dateTime == null ? "never" : $"{(NodaTime.SystemClock.Instance.GetCurrentInstant() - dateTime.Value).FormatSecondsHumanReadable()} ago";
}

public static string FormatPositiveDurationHumanReadable(this Duration? durationOrNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public static class ServiceCollectionExtensions
{
public static void AddNetworkGatewayCore(this IServiceCollection services)
{
services.TryAddSingleton<ISystemClock, TmpSystemClock>();
services.TryAddSingleton<ISystemClock, SystemClock>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface ISystemClock
public DateTimeOffset UtcNow { get; }
}

public class TmpSystemClock : ISystemClock
public class SystemClock : ISystemClock
{
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
}
12 changes: 6 additions & 6 deletions src/RadixDlt.NetworkGateway.Common/Workers/LoopedWorkerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected virtual Task OnStartRequested(CancellationToken cancellationToken, boo
_logger.Log(
_stillRunningLogLimiter.GetLogLevel(),
"Start requested at: {Time}. Service enabled status: {EnabledStatus}",
SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs(),
NodaTime.SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs(),
isCurrentlyEnabled ? "ENABLED" : "DISABLED"
);
return Task.CompletedTask;
Expand All @@ -249,7 +249,7 @@ protected virtual Task OnStopRequested(CancellationToken nonGracefulShutdownCanc
"{GracefulState} stop requested via {StopInstantiationMethod}. Stopping at: {Time}",
nonGracefulShutdownCancellationToken.IsCancellationRequested ? "Non-graceful" : "Graceful",
ExplicitStopRequested ? "an explicit StopAsync call" : "the cancellation of the token passed on start",
SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs()
NodaTime.SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs()
);
return Task.CompletedTask;
}
Expand All @@ -259,7 +259,7 @@ protected virtual Task OnStopRequested(CancellationToken nonGracefulShutdownCanc
/// </summary>
protected virtual Task OnStoppedSuccessfully()
{
_logger.LogInformation("Stopped successfully at: {Time}", SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
_logger.LogInformation("Stopped successfully at: {Time}", NodaTime.SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
return Task.CompletedTask;
}

Expand Down Expand Up @@ -333,17 +333,17 @@ private async Task ExecuteLoopIteration(CancellationToken cancellationToken)
{
if (wasLastEnabled == false)
{
_logger.LogInformation("Detected as re-enabled at {Time}, service will start doing work in a loop again", SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
_logger.LogInformation("Detected as re-enabled at {Time}, service will start doing work in a loop again", NodaTime.SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
}

_logger.Log(_stillRunningLogLimiter.GetLogLevel(), "Still running at {Time}", SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
_logger.Log(_stillRunningLogLimiter.GetLogLevel(), "Still running at {Time}", NodaTime.SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
await DoWork(cancellationToken);
}
else
{
if (wasLastEnabled == true)
{
_logger.LogInformation("Detected as disabled at {Time}. Service won't do work till re-enabled", SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
_logger.LogInformation("Detected as disabled at {Time}. Service won't do work till re-enabled", NodaTime.SystemClock.Instance.GetCurrentInstant().AsUtcIsoDateToSecondsForLogs());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static MempoolTransaction NewAsSubmittedForFirstTimeByGateway(
{
var mempoolTransaction = new MempoolTransaction(payloadHash, payload, transactionContents);

submittedTimestamp ??= SystemClock.Instance.GetCurrentInstant();
submittedTimestamp ??= NodaTime.SystemClock.Instance.GetCurrentInstant();
mempoolTransaction.MarkAsSubmittedToGateway(submittedTimestamp);

// We assume it's been successfully submitted until we see an error and then mark it as an error then
Expand Down Expand Up @@ -292,12 +292,12 @@ public GatewayTransactionContents GetTransactionContents()
public void MarkAsMissing(Instant? timestamp = null)
{
Status = MempoolTransactionStatus.Missing;
LastDroppedOutOfMempoolTimestamp = timestamp ?? SystemClock.Instance.GetCurrentInstant();
LastDroppedOutOfMempoolTimestamp = timestamp ?? NodaTime.SystemClock.Instance.GetCurrentInstant();
}

public void MarkAsCommitted(long ledgerStateVersion, Instant ledgerCommitTimestamp)
{
var commitToDbTimestamp = SystemClock.Instance.GetCurrentInstant();
var commitToDbTimestamp = NodaTime.SystemClock.Instance.GetCurrentInstant();
Status = MempoolTransactionStatus.Committed;
CommitTimestamp = commitToDbTimestamp;

Expand All @@ -311,20 +311,20 @@ public void MarkAsCommitted(long ledgerStateVersion, Instant ledgerCommitTimesta
public void MarkAsSeenInAMempool(Instant? timestamp = null)
{
Status = MempoolTransactionStatus.SubmittedOrKnownInNodeMempool;
FirstSeenInMempoolTimestamp ??= timestamp ?? SystemClock.Instance.GetCurrentInstant();
FirstSeenInMempoolTimestamp ??= timestamp ?? NodaTime.SystemClock.Instance.GetCurrentInstant();
}

public void MarkAsFailed(MempoolTransactionFailureReason failureReason, string failureExplanation, Instant? timestamp = null)
{
Status = MempoolTransactionStatus.Failed;
FailureReason = failureReason;
FailureExplanation = failureExplanation;
FailureTimestamp = timestamp ?? SystemClock.Instance.GetCurrentInstant();
FailureTimestamp = timestamp ?? NodaTime.SystemClock.Instance.GetCurrentInstant();
}

public void MarkAsSubmittedToGateway(Instant? submittedAt = null)
{
submittedAt ??= SystemClock.Instance.GetCurrentInstant();
submittedAt ??= NodaTime.SystemClock.Instance.GetCurrentInstant();
SubmittedByThisGateway = true;
FirstSubmittedToGatewayTimestamp ??= submittedAt;
LastSubmittedToGatewayTimestamp = submittedAt;
Expand All @@ -350,7 +350,7 @@ public void MarkAsResolvedButUnknownAfterSubmittedToNode(string nodeSubmittedTo,

private void RecordSubmission(string nodeSubmittedTo, Instant? submittedAt = null)
{
LastSubmittedToNodeTimestamp = submittedAt ?? SystemClock.Instance.GetCurrentInstant();
LastSubmittedToNodeTimestamp = submittedAt ?? NodaTime.SystemClock.Instance.GetCurrentInstant();
LastSubmittedToNodeName = nodeSubmittedTo;
SubmissionToNodesCount += 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public void WhenGiven_NullValue_Succeeds()
[InlineData("aGVsbG8=")]
[InlineData("R0lGODlhAQABAAAAACw=")]
[InlineData("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=")]
public void WhenGiven_ValidValue_Succeeds(string hex)
public void WhenGiven_ValidValue_Succeeds(string base64)
{
var validator = new TestValidator(v => v.RuleFor(x => x.StringProperty).Base64());
var result = validator.TestValidate(new TestSubject { StringProperty = hex });
var result = validator.TestValidate(new TestSubject { StringProperty = base64 });

result.ShouldNotHaveValidationErrorFor(x => x.StringProperty);
}
Expand All @@ -99,10 +99,10 @@ public void WhenGiven_ValidValue_Succeeds(string hex)
[InlineData("aGVsbG8=", 5)]
[InlineData("R0lGODlhAQABAAAAACw=", 14)]
[InlineData("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=", 68)]
public void WhenGiven_HexValueOfExpectedLength_Succeeds(string hex, int expectedLength)
public void WhenGiven_Base64ValueOfExpectedLength_Succeeds(string base64, int expectedLength)
{
var validator = new TestValidator(v => v.RuleFor(x => x.StringProperty).Base64(expectedLength));
var result = validator.TestValidate(new TestSubject { StringProperty = hex });
var result = validator.TestValidate(new TestSubject { StringProperty = base64 });

result.ShouldNotHaveValidationErrorFor(x => x.StringProperty);
}
Expand All @@ -111,10 +111,10 @@ public void WhenGiven_HexValueOfExpectedLength_Succeeds(string hex, int expected
[InlineData("YQ")]
[InlineData("YQ=")]
[InlineData("Yś==")]
public void WhenGiven_InvalidBase64Value_Fails(string hex)
public void WhenGiven_InvalidBase64Value_Fails(string base64)
{
var validator = new TestValidator(v => v.RuleFor(x => x.StringProperty).Base64());
var result = validator.TestValidate(new TestSubject { StringProperty = hex });
var result = validator.TestValidate(new TestSubject { StringProperty = base64 });

result.ShouldHaveValidationErrorFor(x => x.StringProperty);
}
Expand Down

0 comments on commit 8340117

Please sign in to comment.