Skip to content

Commit

Permalink
Revert "akkadotnet#4353 Config.WithFallback is acting inconsistently (a…
Browse files Browse the repository at this point in the history
…kkadotnet#4358)"

This reverts commit 3788ced.
  • Loading branch information
Aaronontheweb committed Mar 30, 2020
1 parent 2dbeeaf commit 4696b4d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 178 deletions.
146 changes: 0 additions & 146 deletions src/core/Akka.Cluster.Tests.MultiNode/Bugfix4353Specs.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Deploy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public bool Equals(Deploy other)
string.Equals(_path, other._path) &&
_routerConfig.Equals(other._routerConfig) &&
((_config.IsNullOrEmpty() && other._config.IsNullOrEmpty()) ||
_config.Root.ToString().Equals(other._config.Root.ToString())) &&
_config.ToString().Equals(other._config.ToString())) &&
(_scope == null && other._scope == null || (_scope != null && _scope.Equals(other._scope)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private static string GetProviderClass(string provider)
/// <inheritdoc/>
public override string ToString()
{
return Config.Root.ToString();
return Config.ToString();
}
}
}
30 changes: 18 additions & 12 deletions src/core/Akka/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public Config(HoconRoot root)
if (root.Value == null)
throw new ArgumentNullException(nameof(root), "The root value cannot be null.");

Value = root.Value;
Root = root.Value;
Substitutions = root.Substitutions;
}
Expand All @@ -53,7 +52,6 @@ public Config(Config source, Config fallback)
if (source == null)
throw new ArgumentNullException(nameof(source), "The source configuration cannot be null.");

Value = source.Value;
Root = source.Root;
Fallback = fallback;
}
Expand All @@ -71,8 +69,6 @@ public virtual bool IsEmpty
get { return Root == null || Root.IsEmpty; }
}

private HoconValue Value { get; set; }

/// <summary>
/// The root node of this configuration section
/// </summary>
Expand All @@ -94,7 +90,6 @@ protected Config Copy(Config fallback = null)
{
Fallback = Fallback != null ? Fallback.Copy(fallback) : fallback,
Root = Root,
Value = Value,
Substitutions = Substitutions
};
}
Expand Down Expand Up @@ -428,10 +423,10 @@ public virtual TimeSpan GetTimeSpan(string path, TimeSpan? @default = null, bool
/// <returns>A string containing the current configuration.</returns>
public override string ToString()
{
if (Value == null)
if (Root == null)
return "";

return Value.ToString();
return Root.ToString();
}

/// <summary>
Expand All @@ -443,7 +438,21 @@ public string ToString(bool includeFallback)
{
if (includeFallback == false)
return ToString();
return Root.ToString();

Config current = this;

if (current.Fallback == null)
return current.ToString();

Config clone = Copy();

while (current.Fallback != null)
{
clone.Root.GetObject().Merge(current.Fallback.Root.GetObject());
current = current.Fallback;
}

return clone.ToString();
}

/// <summary>
Expand All @@ -458,10 +467,7 @@ public virtual Config WithFallback(Config fallback)
throw new ArgumentException("Config can not have itself as fallback", nameof(fallback));
if (fallback == null)
return this;
if (IsEmpty)
return fallback;

var mergedRoot = fallback.Root.GetObject().MergeImmutable(Root.GetObject());
var mergedRoot = Root.GetObject().MergeImmutable(fallback.Root.GetObject());
var newRoot = new HoconValue();
newRoot.AppendValue(mergedRoot);
var mergedConfig = Copy(fallback);
Expand Down
21 changes: 3 additions & 18 deletions src/core/Akka/Configuration/Hocon/HoconObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public string ToString(int indent)
var sb = new StringBuilder();
foreach (var kvp in Items)
{
if (kvp.Value.AdoptedFromFallback) continue;
string key = QuoteIfNeeded(kvp.Key);
sb.AppendFormat("{0}{1} : {2}\r\n", i, key, kvp.Value.ToString(indent));
}
Expand All @@ -185,7 +186,6 @@ public void Merge(HoconObject other)
{
var thisItems = Items;
var otherItems = other.Items;
var modified = new List<KeyValuePair<string, HoconValue>>();

foreach (var otherItem in otherItems)
{
Expand All @@ -195,27 +195,14 @@ public void Merge(HoconObject other)
{
//if both values are objects, merge them
if (thisItem.IsObject() && otherItem.Value.IsObject())
{
var newObject = thisItem.GetObject().MergeImmutable(otherItem.Value.GetObject());
var value = new HoconValue();
value.Values.Add(newObject);
modified.Add(new KeyValuePair<string, HoconValue>(otherItem.Key, value));
}
else
modified.Add(new KeyValuePair<string, HoconValue>(otherItem.Key, otherItem.Value));
thisItem.GetObject().Merge(otherItem.Value.GetObject());
}
else
{
//other key was not present in this object, just copy it over
modified.Add(new KeyValuePair<string, HoconValue>(otherItem.Key, otherItem.Value));
Items.Add(otherItem.Key, otherItem.Value);
}
}

if (modified.Count == 0)
return;

foreach(var kvp in modified)
Items[kvp.Key] = kvp.Value;
}

/// <summary>
Expand All @@ -241,8 +228,6 @@ internal HoconObject MergeImmutable(HoconObject other)
mergedValue.AppendValue(mergedObject);
thisItems[otherItem.Key] = mergedValue;
}
else
thisItems[otherItem.Key] = otherItem.Value;
}
else
{
Expand Down

0 comments on commit 4696b4d

Please sign in to comment.