Skip to content

Instantly share code, notes, and snippets.

@slimflem
Forked from PaulStovell/gist:6269309
Created September 2, 2013 11:50
Show Gist options
  • Save slimflem/6412051 to your computer and use it in GitHub Desktop.
Save slimflem/6412051 to your computer and use it in GitHub Desktop.
class Program
{
static int bats = 0;
static int frogs = 0;
static void Main(string[] args)
{
using (var store = new EmbeddableDocumentStore())
{
store.Initialize();
IndexCreation.CreateIndexes(typeof(Program).Assembly, store);
ThreadPool.QueueUserWorkItem(delegate
{
var i = 0;
while (true)
{
Thread.Sleep(1000);
i++;
using (var session = store.OpenSession())
{
if (i % 2 == 1)
{
session.Store(new Frog { Name = "Frog " + i });
session.SaveChanges();
frogs++;
}
else
{
//session.Store(new Bat { Name = "Bat " + i });
//session.SaveChanges();
//bats++;
}
}
}
});
while (true)
{
Thread.Sleep(100);
var stats = store.DatabaseCommands.GetStatistics();
Console.Clear();
Console.WriteLine("Bats: " + bats);
Console.WriteLine("Frogs: " + frogs);
Console.WriteLine("Stale indexes: " + string.Join(", ", stats.StaleIndexes));
foreach (var ix in stats.Indexes)
{
Console.WriteLine(ix.Name + " etag: " + ix.LastIndexedEtag);
}
}
}
}
}
public class Frog
{
public string Name { get; set; }
}
public class Bat
{
public string Name { get; set; }
}
public class Bats : AbstractIndexCreationTask<Bat>
{
public Bats()
{
Map = bats => from b in bats
select new { b.Name };
}
}
public class Frogs : AbstractIndexCreationTask<Frog>
{
public Frogs()
{
Map = frogs => from f in frogs
select new { f.Name };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment