Exemplo n.º 1
0
		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);
		}
Exemplo n.º 2
0
		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);
		}
Exemplo n.º 3
0
		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);
		}
Exemplo n.º 4
0
		public void CanAddAndSearch()
		{
			var buffer = new byte[1024];
			var tree = new Tree(new MemoryStream(buffer), new MemoryStream(buffer), StartMode.Create);
			for (int i = 0; i < 7; i++)
			{
				tree.Add("commitinfos/" + (i + 1), i);
			}

			for (int i = 0; i < 7; i++)
			{
				Assert.NotNull(tree.FindNode("commitinfos/" + (i + 1)));
			}
		}
Exemplo n.º 5
0
		public Queue(Stream reader, Stream writer, StartMode mode)
		{
			this.reader = reader;
			this.writer = writer;

			binaryReader = new BinaryReaderWith7BitEncoding(reader);
			binaryWriter = new BinaryWriterWith7BitEncoding(writer);

			if(mode == StartMode.Open)
			{
				currentId = binaryReader.Read7BitEncodedInt64();
				var treePos = binaryReader.Read7BitEncodedInt64();
				reader.Position = treePos;
			}
			tree = new Tree(reader, writer, mode);
		}
Exemplo n.º 6
0
		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);
		}
Exemplo n.º 7
0
		private void CreateFromScratch()
		{
			binaryWriter.Write(HeaderSignature);
			binaryWriter.Write7BitEncodedInt(Version);
			binaryWriter.Write(Guid.NewGuid().ToByteArray());
			using (var reader = OpenReader())
			{
				var docs = new Tree(reader, writer, StartMode.Create);
				var docsInTx = new Tree(reader, writer, StartMode.Create);
				var docById = new Tree(reader, writer, StartMode.Create);
				var docByEtag = new Tree(reader, writer, StartMode.Create);
				var tx = new Tree(reader, writer, StartMode.Create);
				var attachments = new Tree(reader, writer, StartMode.Create);
				var tasks = new Queue(reader, writer, StartMode.Create);
				var tasksByIndex = new Tree(reader, writer, StartMode.Create);
				var identity = new Tree(reader, writer, StartMode.Create);
				var indexes = new Tree(reader, writer, StartMode.Create);
				var queues = new TreeOfQueues(reader, writer, StartMode.Create);
				var mapResultsByDocId = new TreeOfBags(reader, writer, StartMode.Create);
				var mapResultsByReduceKey = new TreeOfBags(reader, writer, StartMode.Create);
				docs.Flush();
				docsInTx.Flush();
				docById.Flush();
				docByEtag.Flush();
				tx.Flush();
				attachments.Flush();
				tasks.Flush();
				tasksByIndex.Flush();
				identity.Flush();
				indexes.Flush();
				queues.Flush();
				mapResultsByDocId.Flush();
				mapResultsByReduceKey.Flush();

				WriteTransaction(new StorageTransaction
				{
					AttachmentPosition = attachments.RootPosition,
					AttachmentsCount = 0,
					DocumentsPosition = docs.RootPosition,
					DocumentsCount = 0,
					DocumentsInTransactionPosition = docsInTx.RootPosition,
					DocumentsByIdPosition = docById.RootPosition,
					DocumentsByEtagPosition = docByEtag.RootPosition,
					TasksPosition = tasks.RootPosition,
					TasksCount = 0,
					TransactionPosition = tx.RootPosition,
					IdentityPosition = identity.RootPosition,
					IndexesPosition = indexes.RootPosition,
					QueuesPosition = queues.RootPosition,
					TasksByIndexPosition = tasksByIndex.RootPosition,
					MappedResultsByDocumentIdPosition = mapResultsByDocId.RootPosition,
					MappedResultsByReduceKeyPosition = mapResultsByReduceKey.RootPosition
				});
				writer.Flush(true);
			}
		}
Exemplo n.º 8
0
		public TreeOfQueues(Stream reader, Stream writer, StartMode mode)
		{
			this.reader = reader;
			this.writer = writer;
			queues = new Tree(reader, writer, mode);
		}
Exemplo n.º 9
0
		public TreeOfBags(Stream reader, Stream writer, StartMode mode)
		{
			this.reader = reader;
			this.writer = writer;
			bags = new Tree(reader, writer, mode);
		}
Exemplo n.º 10
0
		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);
		}
Exemplo n.º 11
0
		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);

		}