public void CanAddToTree() { var buffer = new byte[1024]; var tree = new Tree(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create); tree.Add("ayende", 13); var docPos = tree.FindValue("ayende"); Assert.Equal(13, docPos); }
public void CanSearchInTree() { var buffer = new byte[1024]; var tree = new Tree(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create); tree.Add("ayende", 53); tree.Add("oren", 15); var doc = tree.FindValue("oren"); Assert.Equal(15, doc); }
public void PartialSearches_ShouldResultInIndexScan() { var buffer = new byte[1024]; var tree = new Tree(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create); tree.Add(JObject.FromObject(new { One = 1, Two = 2 }), 13); tree.Add(JObject.FromObject(new { One = 3, Two = 3 }), 14); tree.Add(JObject.FromObject(new { One = 3, Two = 1 }), 15); var docPos = tree.FindValue(JObject.FromObject(new { One = 1, Two = 2 })); Assert.Equal(13, docPos); docPos = tree.FindValue(JObject.FromObject(new { Two = 2 })); Assert.Equal(13, docPos); docPos = tree.FindValue(JObject.FromObject(new { Two = 3 })); Assert.Equal(14, docPos); docPos = tree.FindValue(JObject.FromObject(new { Two = 1 })); Assert.Equal(15, docPos); }
public void CanAddToTreeAndReadFromAnother() { var buffer = new byte[1024]; var tree = new Tree(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create); tree.Add("ayende", 45); tree.Flush(); tree = new Tree(new MemoryStream(buffer) { Position = tree.RootPosition }, new MemoryStream(buffer), StartMode.Open); var doc = tree.FindValue("ayende"); Assert.Equal(45, doc); }
public Queue GetQueue(string name) { Queue value; if (queuesInMem.TryGetValue(name, out value)) { return(value); } var queuePos = queues.FindValue(name); if (queuePos == null) { return(null); } reader.Position = queuePos.Value; var q = new Queue(reader, writer, StartMode.Open); queuesInMem.Add(name, q); return(q); }
public Bag GetBag(JToken key) { Bag value; if (bagsInMem.TryGetValue(key, out value)) { return(value); } var pos = bags.FindValue(key); if (pos == null) { return(null); } reader.Position = pos.Value; value = new Bag(reader, writer, StartMode.Open); bagsInMem.Add(key, value); return(value); }
public void CanRemoveFromTreeAndReadFromAnother() { var buffer = new byte[1024]; var tree = new Tree(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create); tree.Add("ayende", 13); tree.Add("oren", 978); tree.Remove("ayende"); tree.Flush(); tree = new Tree(new MemoryStream(buffer) { Position = tree.RootPosition }, new MemoryStream(buffer), StartMode.Open); Assert.Null(tree.FindValue("ayende")); var doc = tree.FindValue("oren"); Assert.Equal(978, doc); }
public void CanRemoveFromTree() { var buffer = new byte[1024]; var tree = new Tree(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create); tree.Add("ayende", 44); tree.Add("oren", 77); var doc = tree.FindValue("oren"); Assert.Equal(77, doc); tree.Remove("ayende"); Assert.Null(tree.FindValue("ayende")); doc = tree.FindValue("oren"); Assert.Equal(77, doc); }