public RoundRobinSharding() { servers = new Dictionary<string, RavenDbServer> { {"one",GetNewServer(8078)}, {"two", GetNewServer(8077)}, {"tri", GetNewServer(8076)} }; var documentStores = new Dictionary<string, IDocumentStore> { {"one", new DocumentStore{Url = "http://localhost:8078"}}, {"two", new DocumentStore{Url = "http://localhost:8077"}}, {"tri", new DocumentStore{Url = "http://localhost:8076"}}, }; foreach (var documentStore in documentStores) { documentStore.Value.Conventions.FailoverBehavior = FailoverBehavior.FailImmediately; } var shardStrategy = new ShardStrategy(documentStores) .ShardingOn<Post>() .ShardingOn<PostComments>(x => x.PostId); store = new ShardedDocumentStore(shardStrategy); store.Initialize(); }
protected ShardingScenario() { RavenDbServer users = null; RavenDbServer blogs = null; RavenDbServer posts1 = null; RavenDbServer posts2 = null; RavenDbServer posts3 = null; try { users = GetNewServer(8079, "shard1"); blogs = GetNewServer(8078, "shard2"); posts1 = GetNewServer(8077, "shard3"); posts2 = GetNewServer(8076, "shard4"); posts3 = GetNewServer(8075, "shard5"); } catch (Exception) { if (users != null) users.Dispose(); if (blogs != null) blogs.Dispose(); if (posts1 != null) posts1.Dispose(); if (posts2 != null) posts2.Dispose(); if (posts3 != null) posts3.Dispose(); throw; } Servers = new Dictionary<string, RavenDbServer> { {"Users", users}, {"Blogs", blogs}, {"Posts01", posts1}, {"Posts02", posts2}, {"Posts03", posts3} }; var shards = new List<IDocumentStore> { new DocumentStore {Identifier = "Users", Url = "http://localhost:8079"}, new DocumentStore {Identifier = "Blogs", Url = "http://localhost:8078"}, new DocumentStore {Identifier = "Posts01", Url = "http://localhost:8077"}, new DocumentStore {Identifier = "Posts02", Url = "http://localhost:8076"}, new DocumentStore {Identifier = "Posts03", Url = "http://localhost:8075"} }.ToDictionary(x => x.Identifier, x => x); foreach (var shard in shards) { shard.Value.Conventions.FailoverBehavior = FailoverBehavior.FailImmediately; } ShardedDocumentStore = new ShardedDocumentStore(new ShardStrategy(shards) { ShardAccessStrategy = new SequentialShardAccessStrategy(), ShardResolutionStrategy = new BlogShardResolutionStrategy(3), }); ShardedDocumentStore = (ShardedDocumentStore) ShardedDocumentStore.Initialize(); }
private static void Main() { //set up const int createUserCount = 30; Shards shards = ShardsConfiguration.SetupShards(); IEnumerable<User> users = TestDataGenerator.GenerateUsers(createUserCount); var shardStore = new ShardedDocumentStore(new UserShardStrategy(), shards); //main logic using (IDocumentStore store = shardStore.Initialize()) { //Based on user id, save users into the three shards var repo = new UserRepository(store); repo.SaveAll(users); //load all from database //this will query all three shards IEnumerable<User> persistedUsers = repo.FindAll(); ConsoleOutput.PrintUsersInfo(persistedUsers); Console.WriteLine("==================================================="); //pick a random user int id = rnd.Next(1, createUserCount); //query all shards for specific user //user location in a shard is resolved automatically User user = repo.FindUserById(id); ConsoleOutput.PrintTweetsPostedBy(user); Console.WriteLine("==================================================="); } Console.ReadLine(); }
public void CanDisableQueryResultsTrackingForShardedDocumentQuery() { using (GetNewServer(8079)) using (GetNewServer(8078)) using (var store = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore> { {"1", CreateDocumentStore(8079)}, {"2", CreateDocumentStore(8078)}, }))) { store.Initialize(); using (var session = store.OpenSession()) { session.Store(new Item()); session.Store(new Item()); session.SaveChanges(); } using (var session = store.OpenSession()) { var items = session.Query<Item>().Customize(x => x.NoTracking().WaitForNonStaleResults()).ToList(); Assert.Equal(2, items.Count); Assert.Equal(0, ((InMemoryDocumentSessionOperations) session).NumberOfEntitiesInUnitOfWork); } } }
public void CanIgnoreMultiShard() { using (var server1 = GetNewServer(8079)) using (var server2 = GetNewServer(8078)) using (var server3 = GetNewServer(8077)) using (var server4 = server3) { Dictionary<string, IDocumentStore> shards = new Dictionary<string, IDocumentStore> { {"Eastern", server1.DocumentStore}, {"Western", server2.DocumentStore}, {"Northern", server3.DocumentStore}, {"Southern", server4.DocumentStore}, }; ShardStrategy shardStrategy = new ShardStrategy(shards) .ShardingOn<Region2>(r => r.Name)//, name => (name == "Northern" || name == "Southern") ? "NorthSouth" : name) .ShardingOn<TerritoryOf>(x => x.RegionId); IDocumentStore store = new ShardedDocumentStore(shardStrategy); NotSupportedException notSuppotedEx = null; try { store.Initialize(); } catch (Exception ex) { notSuppotedEx = ex as NotSupportedException; } Assert.NotNull(notSuppotedEx); Assert.Contains("Multiple keys in shard dictionary for", notSuppotedEx.Message); } }
public void bulk_insert_sharded(string databaseName1, string databaseName2) { var server1 = GetNewServer(8079); var server2 = GetNewServer(8078); var shards = new Dictionary<string, IDocumentStore> { {"Shard1", new DocumentStore {Url = server1.Configuration.ServerUrl, DefaultDatabase = databaseName1}}, {"Shard2", new DocumentStore {Url = server2.Configuration.ServerUrl, DefaultDatabase = databaseName2}} }; var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); var entity1 = new Profile {Id = "bulk1", Name = "Hila", Location = "Shard1"}; var entity2 = new Profile {Name = "Jay", Location = "Shard2"}; var entity3 = new Profile {Name = "Jay", Location = "Shard1"}; using (var bulkInsert = shardedDocumentStore.ShardedBulkInsert()) { bulkInsert.Store(entity1); bulkInsert.Store(entity2); bulkInsert.Store(entity3); } } using (var store1 = new DocumentStore { Url = server1.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = databaseName1 }.Initialize()) { using (var session = store1.OpenSession()) { var docs = session.Load<Profile>("Shard1/bulk1"); Assert.Equal("Shard1", docs.Location); var docs2 = session.Load<Profile>("Shard1/profiles/2"); Assert.Equal("Shard1", docs2.Location); var totalDocs = session.Query<Profile>() .Customize(x => x.WaitForNonStaleResults()) .ToList(); Assert.Equal(2, totalDocs.Count); } } using (var store2 = new DocumentStore { Url = server2.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = databaseName2 }.Initialize()) { using (var session = store2.OpenSession()) { var docs = session.Load<Profile>("Shard2/profiles/1"); Assert.Equal("Shard2", docs.Location); var totalDocs = session.Query<Profile>() .Customize(x => x.WaitForNonStaleResults()) .ToList(); Assert.Equal(1, totalDocs.Count); } } }
public void CanQueryUsingInt() { shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy(); using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Load<Company>(1); } } }
public void Can_insert_into_two_sharded_servers() { using (var documentStore = new ShardedDocumentStore(shardStrategy, shards)) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Store(company1); session.Store(company2); session.SaveChanges(); } } }
public void ToFacetsDoesntWorkWithShardedDocumentSession() { var server1 = GetNewServer(8079); var server2 = GetNewServer(8078); var shards = new Dictionary<string, IDocumentStore> { {"Shard1", new DocumentStore{Url = server1.Configuration.ServerUrl}}, {"Shard2", new DocumentStore{Url = server2.Configuration.ServerUrl}}, }; var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardResolutionStrategy = new HybridShardingResolutionStrategy(shards.Keys, shardStrategy, new Type[0], "Shard1"); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); new ProfileIndex().Execute(shardedDocumentStore); /*var facetSetup = new FacetSetup { Id = "facets/ProfileFacet", Facets = new List<Facet> { new Facet {Name = "Name", Mode = FacetMode.Default} } };*/ var facets = new List<Facet> { new Facet {Name = "Name", Mode = FacetMode.Default} }; var profile = new Profile {Name = "Test", Location = "Shard1"}; using (var documentSession = shardedDocumentStore.OpenSession()) { documentSession.Store(profile, profile.Id); //documentSession.Store(facetSetup); documentSession.SaveChanges(); } using (var documentSession = shardedDocumentStore.OpenSession()) { var query = documentSession.Query<Profile>("ProfileIndex").Where(x => x.Name == "Test"); var res = query.ToFacets(facets); Assert.Equal(1, res.Results.Count); } } }
public ShardedSessionInclude() { servers = new[] { GetNewServer(8079,requestedStorage: "esent"), GetNewServer(8080, requestedStorage: "esent") }; documentStore = CreateDocumentStore(8080); shardedDocumentStore = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore> { {"1", CreateDocumentStore(8079)} })); shardedDocumentStore.Initialize(); documentStore.Initialize(); }
public RavenDB_579() { servers = new[] { GetNewServer(8079), GetNewServer(8078), GetNewServer(8077), }; documentStore = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore> { {shardNames[0], CreateDocumentStore(8079)}, {shardNames[1], CreateDocumentStore(8078)}, {shardNames[2], CreateDocumentStore(8077)} })); documentStore.Initialize(); }
public SimpleSharding() { servers = new[] { GetNewServer(8079), GetNewServer(8078), GetNewServer(8077), }; documentStore = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore> { {"1", CreateDocumentStore(8079)}, {"2", CreateDocumentStore(8078)}, {"3", CreateDocumentStore(8077)} })); documentStore.Initialize(); }
public void get_metadata_for_sharded() { var server1 = GetNewServer(8079); var server2 = GetNewServer(8078); var shards = new List<IDocumentStore> { new DocumentStore {Identifier = "Shard1", Url = server1.Configuration.ServerUrl}, new DocumentStore {Identifier = "Shard2", Url = server2.Configuration.ServerUrl} } .ToDictionary(x => x.Identifier, x => x); var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); var profile = new Profile {Name = "Test", Location = "Shard1"}; var profile2 = new Profile {Name = "Test2", Location = "Shard2"}; using (var documentSession = shardedDocumentStore.OpenSession()) { documentSession.Store(profile, profile.Id); documentSession.Store(profile2, profile2.Id); documentSession.SaveChanges(); } using (var documentSession = shardedDocumentStore.OpenSession()) { var correctId = profile.Id; var correctId2 = profile2.Id; documentSession.Store(profile, profile.Id); var metaData = documentSession.Advanced.GetMetadataFor(profile); var metaData2 = documentSession.Advanced.GetMetadataFor(profile2); Assert.NotNull(metaData); Assert.NotNull(metaData2); Assert.Equal(correctId, profile.Id); } } }
public async Task get_metadata_for_async_sharded() { var server1 = GetNewServer(8079); var server2 = GetNewServer(8078); var shards = new Dictionary<string, IDocumentStore> { {"Shard1", new DocumentStore{Url = server1.Configuration.ServerUrl}}, {"Shard2", new DocumentStore{Url = server2.Configuration.ServerUrl}}, }; var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); var profile = new Profile {Name = "Test", Location = "Shard1"}; var profile2 = new Profile {Name = "Test2", Location = "Shard2"}; using (var documentSession = shardedDocumentStore.OpenSession()) { documentSession.Store(profile, profile.Id); documentSession.Store(profile2, profile2.Id); documentSession.SaveChanges(); } using (var documentSession = shardedDocumentStore.OpenSession()) { var metaData = documentSession.Advanced.GetMetadataFor(profile); } using (var documentSession = shardedDocumentStore.OpenAsyncSession()) { //var data = await documentSession.LoadAsync<Profile>(profile.Id); var metaData = await documentSession.Advanced.GetMetadataForAsync(profile); var metaData2 = await documentSession.Advanced.GetMetadataForAsync(profile2); Assert.NotNull(metaData); Assert.NotNull(metaData2); } } }
public void Can_insert_into_two_sharded_servers() { var serverPortsStoredUpon = new List<string>(); using (var documentStore = new ShardedDocumentStore(shardStrategy, shards)) { documentStore.Stored += (storeServer, storeEntity) => serverPortsStoredUpon.Add(storeServer); documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Store(company1); session.Store(company2); session.SaveChanges(); } } Assert.Contains("Shard1", serverPortsStoredUpon[0]); Assert.Contains("Shard2", serverPortsStoredUpon[1]); }
public async Task DeleteItemOnAsyncShardedDocumentSession() { var server1 = GetNewServer(8079); var server2 = GetNewServer(8078); var shards = new Dictionary<string, IDocumentStore> { {"Shard1", new DocumentStore {Url = server1.Configuration.ServerUrl}}, {"Shard2", new DocumentStore {Url = server2.Configuration.ServerUrl}}, }; var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); var profile = new Profile { Name = "Test", Location = "Shard1" }; var profile2 = new Profile { Name = "Test2", Location = "Shard2" }; using (var documentSessionAsync = shardedDocumentStore.OpenAsyncSession()) { await documentSessionAsync.StoreAsync(profile, profile.Id); await documentSessionAsync.StoreAsync(profile2, profile2.Id); await documentSessionAsync.SaveChangesAsync(); documentSessionAsync.Delete(profile); await documentSessionAsync.SaveChangesAsync(); var doc = documentSessionAsync.LoadAsync<Profile>(profile.Id); Assert.Null(await doc); } using (var documentSessionAsync = shardedDocumentStore.OpenAsyncSession()) { Assert.Null(await documentSessionAsync.LoadAsync<Profile>(profile.Id)); } } }
public void CanOverrideTheShardIdGeneration() { using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); foreach (var shard in shards) { shard.Value.Conventions.DocumentKeyGenerator = c => ((Company)c).Name; } using (var session = documentStore.OpenSession()) { session.Store(company1); session.Store(company2); Assert.Equal("Shard1/companies/1", company1.Id); Assert.Equal("Shard2/companies/2", company2.Id); } } }
public void Can_override_the_shard_id_generation() { using (var documentStore = new ShardedDocumentStore(shardStrategy, shards)) { documentStore.Initialize(); foreach (var shard in shards) { var s = shard; shard.Conventions.DocumentKeyGenerator = c => ((Company) c).Name; } using (var session = documentStore.OpenSession()) { session.Store(company1); session.Store(company2); Assert.Equal("Company1", company1.Id); Assert.Equal("Company2", company2.Id); } } }
public void OverwritingExistingDocumentGeneratesWrongIdWithShardedDocumentStore() { using (var store1 = NewRemoteDocumentStoreWithUrl(8079, ravenDbServer: GetNewServer(8079))) { using (var store2 = NewRemoteDocumentStoreWithUrl(8078, ravenDbServer: GetNewServer(8078))) { var shards = new List<IDocumentStore> { new DocumentStore { Identifier="Shard1", Url = store1.Url}, new DocumentStore { Identifier="Shard2", Url = store2.Url} } .ToDictionary(x => x.Identifier, x => x); var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); var profile = new Profile { Name = "Test", Location = "Shard1" }; using (var documentSession = shardedDocumentStore.OpenSession()) { documentSession.Store(profile, profile.Id); documentSession.SaveChanges(); } using (var documentSession = shardedDocumentStore.OpenSession()) { var correctId = profile.Id; documentSession.Store(profile, profile.Id); Assert.Equal(correctId, profile.Id); } } } } }
public async Task CanOverrideTheShardIdGeneration() { using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); foreach (var shard in shards) { shard.Value.Conventions.DocumentKeyGenerator = (dbName, cmds, c) => ((Company)c).Name; } using (var session = documentStore.OpenAsyncSession()) { await session.StoreAsync(company1); await session.StoreAsync(company2); await session.SaveChangesAsync(); Assert.Equal("Shard1/companies/1", company1.Id); Assert.Equal("Shard2/companies/2", company2.Id); } } }
public void OverwritingExistingDocumentGeneratesWrongIdWithShardedDocumentStore() { var server1 = GetNewServer(8079); var server2 = GetNewServer(8078); var shards = new Dictionary<string, IDocumentStore> { {"Shard1", new DocumentStore{Url = server1.Configuration.ServerUrl}}, {"Shard2", new DocumentStore{Url = server2.Configuration.ServerUrl}}, }; var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); var profile = new Profile {Name = "Test", Location = "Shard1"}; using (var documentSession = shardedDocumentStore.OpenSession()) { documentSession.Store(profile, profile.Id); documentSession.SaveChanges(); } using (var documentSession = shardedDocumentStore.OpenSession()) { var correctId = profile.Id; documentSession.Store(profile, profile.Id); Assert.Equal(correctId, profile.Id); } } }
public async Task CanInsertIntoTwoShardedServers() { using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); using (var session = documentStore.OpenAsyncSession()) { await session.StoreAsync(company1); await session.StoreAsync(company2); await session.SaveChangesAsync(); } } }
public void CanInsertIntoTwoShardedServers() { using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Store(company1); session.Store(company2); session.SaveChanges(); } } }
static void Main() { var consoleAppender = new ConsoleAppender { Layout = new SimpleLayout(), }; consoleAppender.AddFilter(new LoggerMatchFilter { AcceptOnMatch = true, LoggerToMatch = "Raven.Client" }); consoleAppender.AddFilter(new DenyAllFilter()); BasicConfigurator.Configure(consoleAppender); // start 5 instances of Raven's servers Console.WriteLine("Starting..."); DeleteDirectories("Users", "Blogs", "Posts.1", "Posts.2", "Posts.3"); var ravenDbServers = StartServers(); Console.WriteLine("All servers started..."); var shards = new Shards { new DocumentStore { Identifier = "Users", Url = "http://*****:*****@ Rahien" }; session.Store(user); session.Store(blog); // we have to save to Raven to get the generated id for the blog instance session.SaveChanges(); var posts = new List<Post>(); for (var i = 0; i < 6; i++) { var post = new Post { BlogId = blog.Id, UserId = user.Id, Content = "Just a post", Title = "Post #" + (i + 1) }; posts.Add(post); session.Store(post); } session.SaveChanges(); } // queries using (var session = documentStore.OpenSession()) { session.LuceneQuery<User>().WaitForNonStaleResults().ToArray(); session.LuceneQuery<Blog>().WaitForNonStaleResults().ToArray(); session.LuceneQuery<Post>().WaitForNonStaleResults().ToArray(); } // loading using (var session = documentStore.OpenSession()) { session.Load<User>("users/ayende"); session.Load<Blog>("blogs/1"); session.Load<Post>("posts/1/2"); session.Load<Post>("posts/2/2"); } documentStore.Dispose(); foreach (var server in ravenDbServers) { server.Dispose(); } }
public void TestWithShardedStore(Action<ShardedDocumentStore, string> action, string mainShard) { var server1 = GetNewServer(8079); var server2 = GetNewServer(8078); var shards = new List<IDocumentStore> { new DocumentStore {Identifier = "ShardA", Url = server1.Configuration.ServerUrl}, new DocumentStore {Identifier = "ShardB", Url = server2.Configuration.ServerUrl} }.ToDictionary(x => x.Identifier, x => x); using (var documentStore = new ShardedDocumentStore(new ShardStrategy(shards) { ModifyDocumentId = (convention, shardId, documentId) => documentId }.ShardingOn<User>(x => x.Shard).ShardingOn<UserRole>(x => x.Shard))) { documentStore.Initialize(); action(documentStore, mainShard); } }
public void Can_query_using_int() { shardStrategy.Stub(x => x.ShardAccessStrategy).Return(new SequentialShardAccessStrategy()); using (var documentStore = new ShardedDocumentStore(shardStrategy, shards)) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Load<Company>(1); } } }
public void CanDisableQueryResultsCachingForAsyncShardedDocumentQuery() { using (GetNewServer(8079)) using (GetNewServer(8078)) using (var store = new ShardedDocumentStore(new ShardStrategy(new Dictionary<string, IDocumentStore> { {"1", CreateDocumentStore(8079)}, {"2", CreateDocumentStore(8078)}, }))) { store.Initialize(); using (var session = store.OpenSession()) { session.Store(new Item()); session.Store(new Item()); session.SaveChanges(); } store.ShardStrategy.Shards["1"].JsonRequestFactory.ResetCache(); store.ShardStrategy.Shards["2"].JsonRequestFactory.ResetCache(); using (var asyncSession = store.OpenAsyncSession()) { var asyncQuery = asyncSession.Query<Item>().Customize(x => x.NoCaching().WaitForNonStaleResults()).ToListAsync(); asyncQuery.Wait(); Assert.Equal(2, asyncQuery.Result.Count); } Assert.Equal(0, store.ShardStrategy.Shards["1"].JsonRequestFactory.CurrentCacheSize); Assert.Equal(0, store.ShardStrategy.Shards["2"].JsonRequestFactory.CurrentCacheSize); } }
private IDocumentStore InitDocumentStore(AutofacCreationConverter converter) { var shardStrategy = new ShardStrategy(_shards) { ShardAccessStrategy = new ParallelShardAccessStrategy(), ShardResolutionStrategy = this }; var ds = new ShardedDocumentStore(shardStrategy); ds.Initialize(); if (converter != null) { ds.Conventions.CustomizeJsonSerializer += s => s.Converters.Add(converter); } return ds; }
public void ToFacetsDoesntWorkWithShardedDocumentSession() { using (var store1 = NewRemoteDocumentStoreWithUrl(8079, ravenDbServer: GetNewServer(8079))) { using (var store2 = NewRemoteDocumentStoreWithUrl(8078, ravenDbServer: GetNewServer(8078))) { var shards = new List<IDocumentStore> { new DocumentStore { Identifier="Shard1", Url = store1.Url}, new DocumentStore { Identifier="Shard2", Url = store2.Url} } .ToDictionary(x => x.Identifier, x => x); var shardStrategy = new ShardStrategy(shards); shardStrategy.ShardResolutionStrategy = new HybridShardingResolutionStrategy(shards.Keys, shardStrategy, new Type[0], "Shard1"); shardStrategy.ShardingOn<Profile>(x => x.Location); using (var shardedDocumentStore = new ShardedDocumentStore(shardStrategy)) { shardedDocumentStore.Initialize(); new ProfileIndex().Execute(shardedDocumentStore); /*var facetSetup = new FacetSetup { Id = "facets/ProfileFacet", Facets = new List<Facet> { new Facet {Name = "Name", Mode = FacetMode.Default} } };*/ var facets = new List<Facet> { new Facet {Name = "Name", Mode = FacetMode.Default} }; var profile = new Profile { Name = "Test", Location = "Shard1" }; using (var documentSession = shardedDocumentStore.OpenSession()) { documentSession.Store(profile, profile.Id); //documentSession.Store(facetSetup); documentSession.SaveChanges(); } using (var documentSession = shardedDocumentStore.OpenSession()) { var query = documentSession.Query<Profile>("ProfileIndex").Where(x => x.Name == "Test"); var res = query.ToFacets(facets); Assert.Equal(1,res.Results.Count); } } } } }
public async Task CanQueryUsingInt() { shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy(); using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); using (var session = documentStore.OpenAsyncSession()) { await session.LoadAsync<Company>(1); } } }