Skip to content

Commit

Permalink
Added auto-recovery info in the Simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
jodydonetti committed Mar 30, 2024
1 parent f7e5404 commit 8dbdd77
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions tests/ZiggyCreatures.FusionCache.Simulator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ internal static class SimulatorOptions
public static readonly string BackplaneRedisConnection = RedisConnection;
public static readonly TimeSpan? ChaosBackplaneSyntheticDelay = null; //TimeSpan.FromMilliseconds(500);

// AUTO-RECOVERY
public static readonly bool EnableAutoRecovery = true;
public static readonly TimeSpan? AutoRecoveryDelay = null;
public static readonly TimeSpan AutoRecoveryDefaultDelay = new FusionCacheOptions().AutoRecoveryDelay;

// OTHERS
public static readonly TimeSpan RefreshDelay = TimeSpan.FromMilliseconds(500);
public static readonly TimeSpan DataChangesMinDelay = TimeSpan.FromSeconds(1);
Expand Down Expand Up @@ -283,7 +288,7 @@ private static void SetupSerilogLogger(IServiceCollection services, LogEventLeve
DateTimeOffset? physicalExpiration = null;
try
{
physicalExpiration = (DateTimeOffset?)entry.GetType().GetProperty("LogicalExpiration")?.GetValue(entry);
physicalExpiration = (DateTimeOffset?)entry.GetType().GetProperty("PhysicalExpiration")?.GetValue(entry);
}
catch (Exception exc)
{
Expand All @@ -294,11 +299,11 @@ private static void SetupSerilogLogger(IServiceCollection services, LogEventLeve
if (logicalExpiration is not null && physicalExpiration is not null)
return logicalExpiration.Value < physicalExpiration.Value ? logicalExpiration : physicalExpiration;

// USE THE PHYSICAL
// USE THE LOGICAL
if (logicalExpiration is not null)
return logicalExpiration;

// USE THE LOGICAL
// USE THE PHYSICAL
if (physicalExpiration is not null)
return physicalExpiration;

Expand Down Expand Up @@ -333,8 +338,11 @@ private static void SetupClusters(IServiceProvider serviceProvider, ILogger<Fusi
{
CacheName = cacheName,
DefaultEntryOptions = new FusionCacheEntryOptions(SimulatorOptions.CacheDuration),
AutoRecoveryDelay = TimeSpan.FromSeconds(3),
EnableAutoRecovery = SimulatorOptions.EnableAutoRecovery
};
if (SimulatorOptions.AutoRecoveryDelay is not null)
options.AutoRecoveryDelay = SimulatorOptions.AutoRecoveryDelay.Value;

options.SetInstanceId(cacheInstanceId);

var deo = options.DefaultEntryOptions;
Expand Down Expand Up @@ -706,13 +714,37 @@ static async Task GetValueFromNode(ConcurrentDictionary<int, (bool Error, int? V
AnsiConsole.MarkupLine($"- [deepskyblue1]SIZE :[/] {SimulatorOptions.NodesPerClusterCount} NODES x {SimulatorOptions.ClustersCount} CLUSTERS ({SimulatorOptions.NodesPerClusterCount * SimulatorOptions.ClustersCount} TOTAL NODES)");
AnsiConsole.MarkupLine($"- [deepskyblue1]CACHE DURATION:[/] {SimulatorOptions.CacheDuration}");

// AUTO-RECOVERY
AnsiConsole.Markup("- [deepskyblue1]AUTO-RECOVERY :[/] ");
if (SimulatorOptions.EnableAutoRecovery)
{
AnsiConsole.Markup($"[{Color_DarkGreen} on {Color_MidGreen}] ON [/]");
if (SimulatorOptions.AutoRecoveryDelay.HasValue)
{
AnsiConsole.Markup($" - DELAY: {SimulatorOptions.AutoRecoveryDelay}");
}
else
{
AnsiConsole.Markup($" - DELAY: {SimulatorOptions.AutoRecoveryDefaultDelay} (default)");
}
}
else
{
AnsiConsole.MarkupLine($"[{Color_DarkRed} on {Color_MidRed}] OFF [/]");
}
AnsiConsole.WriteLine();

// DATABASE
AnsiConsole.Markup("- [deepskyblue1]DATABASE :[/] ");

// MEMORY CACHE
AnsiConsole.Markup($"Memory ");
if (DatabaseEnabled)
AnsiConsole.MarkupLine($"[{Color_DarkGreen} on {Color_MidGreen}] ON [/]");
else
AnsiConsole.MarkupLine($"[{Color_DarkRed} on {Color_MidRed}] OFF [/]");

// DISTRIBUTED CACHE
AnsiConsole.Markup("- [deepskyblue1]DIST. CACHE :[/] ");
if (SimulatorOptions.DistributedCacheType == DistributedCacheType.None)
{
Expand All @@ -727,6 +759,7 @@ static async Task GetValueFromNode(ConcurrentDictionary<int, (bool Error, int? V
AnsiConsole.MarkupLine($"[{Color_DarkRed} on {Color_MidRed}] OFF [/]");
}

// BACKPLANE
AnsiConsole.Markup("- [deepskyblue1]BACKPLANE :[/] ");
if (SimulatorOptions.BackplaneType == BackplaneType.None)
{
Expand Down

0 comments on commit 8dbdd77

Please sign in to comment.