Skip to content

Commit

Permalink
Bugfix: Make the Put on the SimpleDnsCache idempotent
Browse files Browse the repository at this point in the history
Bugfix for the exception: itemwith the same key has already been added.
Make the Put on the SimpleDnsCache idempotent when a same host is
resolved.
  • Loading branch information
evertmulder committed Aug 8, 2015
1 parent 581ec04 commit 2ed1d57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/core/Akka.Tests/IO/SimpleDnsCacheSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,19 @@ public void Cache_should_sweep_out_expired_entries_on_cleanup()
cache.Cached("test.local").ShouldBe(null);

}

[Fact]
public void Cache_should_be_updated_with_the_latest_resolved()
{
var localClock = new AtomicReference<long>(0);
var cache = new SimpleDnsCacheTestDouble(localClock);
var cacheEntryOne = Dns.Resolved.Create("test.local", System.Net.Dns.GetHostEntry("127.0.0.1").AddressList);
var cacheEntryTwo = Dns.Resolved.Create("test.local", System.Net.Dns.GetHostEntry("127.0.0.1").AddressList);
long ttl = 500;
cache.Put(cacheEntryOne, ttl);
cache.Cached("test.local").ShouldBe(cacheEntryOne);
cache.Put(cacheEntryTwo, ttl);
cache.Cached("test.local").ShouldBe(cacheEntryTwo);
}
}
}
5 changes: 4 additions & 1 deletion src/core/Akka/IO/SimpleDnsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public Cache Put(Dns.Resolved answer, long ttl)
{
var until = _clock() + ttl;
_queue.Add(new ExpiryEntry(answer.Name, until));
_cache.Add(answer.Name, new CacheEntry(answer, until));
if (_cache.ContainsKey(answer.Name))
_cache[answer.Name] = new CacheEntry(answer, until);
else
_cache.Add(answer.Name, new CacheEntry(answer, until));
return this;
}

Expand Down

0 comments on commit 2ed1d57

Please sign in to comment.