Esempio n. 1
0
		public void CanReadValuesBackWithoutFilter()
		{
			var state = new StorageState("none", new StorageOptions
			{
				ParanoidChecks = true,
				FilterPolicy = null
			});
			string name;
			using (var file = CreateFile())
			{
				name = file.Name;
				using (var tblBuilder = new TableBuilder(state, file, new TemporaryFiles(state.FileSystem, 1)))
				{
					for (int i = 0; i < 10; i++)
					{
						string k = "tests/" + i.ToString("0000");
						tblBuilder.Add(new InternalKey(k, 1, ItemType.Value).TheInternalKey, new MemoryStream(Encoding.UTF8.GetBytes(k)));
					}

					tblBuilder.Finish();
					file.Flush(true);
				}
			}

			using (var mmf = MemoryMappedFile.CreateFromFile(name, FileMode.Open))
			{
				var length = new FileInfo(name).Length;
				using (var table = new Table(state, new FileData(new MemoryMappedFileAccessor(name, mmf), length)))
				using (var iterator = table.CreateIterator(new ReadOptions()))
				{
					for (int i = 0; i < 10; i++)
					{
						string k = "tests/" + i.ToString("0000");
						iterator.Seek(new InternalKey(k, 100, ItemType.Value).TheInternalKey);
						Assert.True(iterator.IsValid);
						using (var stream = iterator.CreateValueStream())
						using (var reader = new StreamReader(stream))
						{
							Assert.Equal(k, reader.ReadToEnd());
						}
					}
				}
			}
		}
		private IEnumerable<RavenJObject> YieldSstContents(Table table, Reference<Slice> reference)
		{
			using (var iterator = table.CreateIterator(new ReadOptions()))
			{
				iterator.Seek(reference.Value);
				while (iterator.IsValid)
				{
					reference.Value = iterator.Key;
					using (var stream = iterator.CreateValueStream())
					{
						yield return RavenJObject.Load(new BsonReader(stream));
					}
					iterator.Next();
				}
			}
		}