public void Teardown() { if (_hash != null) { _hash.Dispose(); } if (Directory.Exists(_path)) { Directory.Delete(_path, true); } }
public void Can_access_keys_across_files_after_hash_reload() { _hash = new FirkinHash<string>(_path, 30); var stream = "bar1".ToStream(); _hash.Put("foo1", stream, stream.Length); stream = "bar2".ToStream(); _hash.Put("foo2", stream, stream.Length); stream = "bar3".ToStream(); _hash.Put("foo3", stream, stream.Length); _hash.Dispose(); _hash = new FirkinHash<string>(_path, 30); Assert.AreEqual("bar3", _hash.Get("foo3").To<string>()); Assert.AreEqual("bar1", _hash.Get("foo1").To<string>()); Assert.AreEqual("bar2", _hash.Get("foo2").To<string>()); }
public void Can_access_keys_across_files_after_hash_reload() { _hash = new FirkinHash <string>(_path, 30); var stream = "bar1".ToStream(); _hash.Put("foo1", stream, stream.Length); stream = "bar2".ToStream(); _hash.Put("foo2", stream, stream.Length); stream = "bar3".ToStream(); _hash.Put("foo3", stream, stream.Length); _hash.Dispose(); _hash = new FirkinHash <string>(_path, 30); Assert.AreEqual("bar3", _hash.Get("foo3").To <string>()); Assert.AreEqual("bar1", _hash.Get("foo1").To <string>()); Assert.AreEqual("bar2", _hash.Get("foo2").To <string>()); }
public void Read_write_users_with_hash_reload() { var users = GetDataSource <User>().ToDictionary(k => k.Id, v => GetEntityStream(v)); if (!users.Any()) { return; } var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); var hash = new FirkinHash <int>(path); try { var elapsed = Diagnostics.Time(() => { foreach (var user in users) { hash.Put(user.Key, user.Value, user.Value.Length); } }); Console.WriteLine("Wrote {0} users to firkin @ {1:0,0} users/second)", users.Count, users.Count / elapsed.TotalSeconds); hash.Dispose(); _log.DebugFormat("re-loading hash"); hash = new FirkinHash <int>(path); var comp = new List <Stream[]>(); elapsed = Diagnostics.Time(() => { foreach (var user in users.OrderBy(x => x.Value.Length)) { var stream = hash.Get(user.Key); comp.Add(new[] { new MemoryStream(stream.ReadBytes(stream.Length)), user.Value }); } }); Console.WriteLine("Queried {0} users from firkin @ {1:0,0} users/second)", users.Count, users.Count / elapsed.TotalSeconds); foreach (var pair in comp) { pair[0].Position = 0; pair[1].Position = 0; Assert.AreEqual(pair[0].ReadBytes(pair[0].Length), pair[1].ReadBytes(pair[1].Length)); } } finally { hash.Dispose(); Directory.Delete(path, true); } }
public void Iterate_over_users_with_Firkin() { var users = GetDataSource <User>().ToDictionary(k => k.Id, v => GetEntityStream(v)); if (!users.Any()) { return; } var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); var hash = new FirkinHash <int>(path); try { var elapsed = Diagnostics.Time(() => { foreach (var user in users) { hash.Put(user.Key, user.Value, user.Value.Length); } }); Console.WriteLine("Wrote {0} users to firkin @ {1:0,0} users/second)", users.Count, users.Count / elapsed.TotalSeconds); var comp = new List <KeyValuePair <int, Stream> >(); elapsed = Diagnostics.Time(() => { foreach (var pair in hash) { comp.Add(new KeyValuePair <int, Stream>(pair.Key, new MemoryStream(pair.Value.ReadBytes(pair.Value.Length)))); } }); Console.WriteLine("Queried {0} users from firkin @ {1:0,0} users/second)", users.Count, users.Count / elapsed.TotalSeconds); foreach (var pair in comp) { var userStream = users[pair.Key]; userStream.Position = 0; Assert.AreEqual(userStream.ReadBytes(userStream.Length), pair.Value.ReadBytes(pair.Value.Length)); } } finally { hash.Dispose(); Directory.Delete(path, true); } }
public void Can_call_merge_and_reload_hash_then_retrieve_data() { _hash = new FirkinHash <string>(_path, 30); var stream = "bar1".ToStream(); _hash.Put("foo1", stream, stream.Length); stream = "bar2".ToStream(); _hash.Put("foo2", stream, stream.Length); stream = "bar3".ToStream(); _hash.Put("foo3", stream, stream.Length); stream = "bar4".ToStream(); _hash.Put("foo4", stream, stream.Length); stream = "bar1x".ToStream(); _hash.Put("foo1", stream, stream.Length); _hash.Merge(); _hash.Dispose(); _log.DebugFormat("re-loading hash"); _hash = new FirkinHash <string>(_path, 30); Assert.AreEqual("bar3", _hash.Get("foo3").To <string>()); Assert.AreEqual("bar1x", _hash.Get("foo1").To <string>()); Assert.AreEqual("bar2", _hash.Get("foo2").To <string>()); Assert.AreEqual("bar4", _hash.Get("foo4").To <string>()); }
public void Can_call_merge_and_reload_hash_then_retrieve_data() { _hash = new FirkinHash<string>(_path, 30); var stream = "bar1".ToStream(); _hash.Put("foo1", stream, stream.Length); stream = "bar2".ToStream(); _hash.Put("foo2", stream, stream.Length); stream = "bar3".ToStream(); _hash.Put("foo3", stream, stream.Length); stream = "bar4".ToStream(); _hash.Put("foo4", stream, stream.Length); stream = "bar1x".ToStream(); _hash.Put("foo1", stream, stream.Length); _hash.Merge(); _hash.Dispose(); _log.DebugFormat("re-loading hash"); _hash = new FirkinHash<string>(_path, 30); Assert.AreEqual("bar3", _hash.Get("foo3").To<string>()); Assert.AreEqual("bar1x", _hash.Get("foo1").To<string>()); Assert.AreEqual("bar2", _hash.Get("foo2").To<string>()); Assert.AreEqual("bar4", _hash.Get("foo4").To<string>()); }