Last active
December 21, 2015 14:09
-
-
Save robashton/6317678 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 | |
} |
This file contains hidden or 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
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(); | |
} | |
This file contains hidden or 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
[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