-
-
Save slimflem/6412051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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