using Raven.Client.Documents;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace RavenDB4Tests.Tryouts
{
public static class StreamingMemory
{
public static async Task StreamingMemoryTest()
{
var rng = new Random();
using (var store = new DocumentStore
{
Urls = new[] { "http://localhost:8081" },
Database = "StreamingMemoryTest"
}.Initialize())
{
if (await ShouldInitData(store))
{
await InitializeData(store);
}
using (var session = store.OpenAsyncSession())
{
Console.WriteLine("Creating stream.");
var query = session.Query<Doc>(collectionName: "Docs");
var stream = await session.Advanced.StreamAsync(query);
while (await stream.MoveNextAsync())
{
var doc = stream.Current.Document;
if (doc.Id.EndsWith("000"))
{
Console.WriteLine($"Processing {doc.Id}");
}
session.Advanced.Evict(doc);
}
Console.WriteLine("Finished processing.");
}
}
}
private static async Task<bool> ShouldInitData(IDocumentStore store)
{
using (var session = store.OpenAsyncSession())
{
var doc = await session.LoadAsync<Doc>("doc/1");
return doc == null;
}
}
private static async Task InitializeData(IDocumentStore store)
{
var start = 0;
var batches = 50;
Console.WriteLine("Generating data.");
var rng = new Random();
for (int batchNo = start; batchNo < start + batches; batchNo++)
{
Console.WriteLine($"{DateTime.Now.ToLongTimeString()}: Generating batch {batchNo + 1}/{batches}");
using (var session = store.OpenAsyncSession())
{
for (int i = 1; i <= 10000; i++)
{
await session.StoreAsync(new Doc { Id = "doc/" + (batchNo * 10000 + i), IntVal = i, IntVals = Enumerable.Range(1, 50).ToDictionary(x => x.ToString(), _ => rng.Next()) });
}
await session.SaveChangesAsync();
}
}
Console.WriteLine("Data generated.");
}
public class Doc
{
public string Id { get; set; }
public int IntVal { get; set; }
public Dictionary<string, int> IntVals { get; set; }
}
}
}
Hibernating Rhinos Ltd
Oren Eini l CEO l Mobile: + 972-52-548-6969
Office: +972-4-622-7811 l Fax: +972-153-4-622-7811
--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hibernating Rhinos Ltd
Tal Weiss l Core Team Developer l Mobile:+972-54-802-4849
Office: +972-4-622-7811 l Fax: +972-153-4-622-7811l Skype: talweiss1982
RavenDB paving the way to "Data Made Simple" http://ravendb.net/