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 = (cmds, c) => ((Company)c).Name; } using (var session = documentStore.OpenAsyncSession()) { session.Store(company1); session.Store(company2); session.SaveChangesAsync().Wait(); Assert.Equal("Shard1/companies/1", company1.Id); Assert.Equal("Shard2/companies/2", company2.Id); } } }
public void CanQueryUsingInt() { shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy(); using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); using (var session = documentStore.OpenAsyncSession()) { session.LoadAsync<Company>(1).Wait(); } } }
public void CanGetAllShardedEntities() { //get them in simple single threaded sequence for this test shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy(); using (var documentStore = new ShardedDocumentStore(shardStrategy).Initialize()) using (var session = documentStore.OpenAsyncSession()) { //store 2 items in 2 shards session.Store(company1); session.Store(company2); session.SaveChangesAsync().Wait(); //get all, should automagically retrieve from each shard var allCompanies = session.Advanced.AsyncLuceneQuery<Company>() .WaitForNonStaleResults() .ToListAsync().Result.Item2; Assert.NotNull(allCompanies); Assert.Equal(company1.Name, allCompanies[0].Name); Assert.Equal(company2.Name, allCompanies[1].Name); } }
public void CanGetSingleEntityFromCorrectShardedServerWhenLocationIsUnknown() { shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy(); using (var documentStore = new ShardedDocumentStore(shardStrategy).Initialize()) using (var session = documentStore.OpenAsyncSession()) { //store item that goes in 2nd shard session.Store(company2); session.SaveChangesAsync().Wait(); //get it, should try all shards and find it shardResolution.Stub(x => x.PotentialShardsFor(null)).IgnoreArguments().Return(null); var loadedCompany = session.LoadAsync<Company>(company2.Id).Result; Assert.NotNull(loadedCompany); Assert.Equal(company2.Name, loadedCompany.Name); } }
public void CanGetSingleEntityFromCorrectShardedServer() { using (var documentStore = new ShardedDocumentStore(shardStrategy).Initialize()) using (var session = documentStore.OpenAsyncSession()) { //store item that goes in 2nd shard session.Store(company2); session.SaveChangesAsync().Wait(); //get it, should automagically retrieve from 2nd shard shardResolution.Stub(x => x.PotentialShardsFor(null)).IgnoreArguments().Return(new[] { "Shard2" }); var loadedCompany = session.LoadAsync<Company>(company2.Id).Result; Assert.NotNull(loadedCompany); Assert.Equal(company2.Name, loadedCompany.Name); } }
public void CanInsertIntoTwoShardedServers() { using (var documentStore = new ShardedDocumentStore(shardStrategy)) { documentStore.Initialize(); using (var session = documentStore.OpenAsyncSession()) { session.Store(company1); session.Store(company2); session.SaveChangesAsync().Wait(); } } }
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); } }
public void CanDisableQueryResultsTrackingForAsyncShardedDocumentQuery() { 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 asyncSession = store.OpenAsyncSession()) { var asyncQuery = asyncSession.Query<Item>().Customize(x => x.NoTracking().WaitForNonStaleResults()).ToListAsync(); asyncQuery.Wait(); Assert.Equal(2, asyncQuery.Result.Count); Assert.Equal(0, ((InMemoryDocumentSessionOperations)asyncSession).NumberOfEntitiesInUnitOfWork); } } }
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); } } }