本文整理汇总了C#中Raven.Client.Shard.ShardedDocumentStore.OpenAsyncSession方法的典型用法代码示例。如果您正苦于以下问题:C# ShardedDocumentStore.OpenAsyncSession方法的具体用法?C# ShardedDocumentStore.OpenAsyncSession怎么用?C# ShardedDocumentStore.OpenAsyncSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Client.Shard.ShardedDocumentStore
的用法示例。
在下文中一共展示了ShardedDocumentStore.OpenAsyncSession方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteItemOnAsyncShardedDocumentSession
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: CanOverrideTheShardIdGeneration
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: CanQueryUsingInt
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: CanGetAllShardedEntities
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: CanGetSingleEntityFromCorrectShardedServerWhenLocationIsUnknown
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: CanGetSingleEntityFromCorrectShardedServer
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: CanInsertIntoTwoShardedServers
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: CanDisableQueryResultsCachingForAsyncShardedDocumentQuery
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: CanDisableQueryResultsTrackingForAsyncShardedDocumentQuery
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: get_metadata_for_async_sharded
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);
}
}
}