Skip to content

Instantly share code, notes, and snippets.

@robashton
Last active December 21, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robashton/6317678 to your computer and use it in GitHub Desktop.
Save robashton/6317678 to your computer and use it in GitHub Desktop.
public class Dog
{
public string Id { get; set; }
public string Name { get; set; }
public string Breed { get; set; }
}
[Test]
public void BlindShardingDemo()
{
var shards = new Dictionary<string, IDocumentStore>
{
{ "One", new DocumentStore() { Url = "http://localhost:8080", DefaultDatabase = "ShardOne"}},
{ "Two", new DocumentStore() { Url = "http://localhost:8081", DefaultDatabase = "ShardTwo"}},
{ "Three", new DocumentStore() { Url = "http://localhost:8082", DefaultDatabase = "ShardThree"}}
};
var strategy = new ShardStrategy(shards);
var store = new ShardedDocumentStore(strategy);
store.Initialize();
using (var session = store.OpenSession())
{
}
// https://gist.github.com/robashton/6317678
}
using (var session = store.OpenSession())
{
session.Store(new Dog() { Name = "Bow wow", Breed = "Terrier"});
session.Store(new Dog() { Name = "Fred", Breed = "Terrier"});
session.Store(new Dog() { Name = "Avara", Breed = "Shepherd"});
session.Store(new Dog() { Name = "Billy", Breed = "Mixed"});
session.Store(new Dog() { Name = "George", Breed = "Mixed"});
session.SaveChanges();
}
[Test]
public void ReplicationFailover()
{
var store = new DocumentStore()
{
Url = "http://localhost:8080",
DefaultDatabase = "Master",
};
store.Conventions.FailoverBehavior = FailoverBehavior.AllowReadsFromSecondariesAndWritesToSecondaries;
store.Initialize();
using (var session = store.OpenSession())
{
session.Store(new Dog() { Name = "Bow wow", Breed ="Mixed"});
session.Store(new Dog() { Name = "Bow wow", Breed ="Mixed"});
session.Store(new Dog() { Name = "Bow wow", Breed ="Mixed"});
session.Store(new Dog() { Name = "Bow wow", Breed ="Mixed"});
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var dogs = session.Query<Dog>().ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment