OpenAsyncSession() public method

Opens the async session.
public OpenAsyncSession ( ) : IAsyncDocumentSession
return IAsyncDocumentSession
示例#1
0
        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));

                }
            }
        }
示例#2
0
		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);
				}
			}
		}
示例#3
0
		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();
				}
			}
		}
示例#4
0
		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);
			}
		}
示例#5
0
		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);
			}
		}
示例#6
0
		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);
			}
		}
示例#7
0
		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();
				}
			}
		}
示例#8
0
		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);
			}
		}
示例#9
0
		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);
				}
			}
		}
示例#10
0
		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);
				}
			}
		}