public void Null_result_is_not_an_exception() { var shard1 = MockRepository.GenerateStub<IDocumentSession>(); var results = new ParallelShardAccessStrategy().Apply(new[] { shard1 }, x => (IList<Company>)null); Assert.Equal(0, results.Count); }
public void ExecutionExceptionsAreRethrown() { using (GetNewServer(port, path)) using (var shard1 = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) using (var session = shard1.OpenSession()) { var parallelShardAccessStrategy = new ParallelShardAccessStrategy(); Assert.Throws<ApplicationException>(() => parallelShardAccessStrategy.Apply<object>(new[] {session.Advanced.DatabaseCommands}, (x, i) => { throw new ApplicationException(); })); } }
public void Null_result_is_not_an_exception() { using(GetNewServer(port, path)) { var shard1 = new DocumentStore { Url = "http://localhost:8080" }.Initialize().OpenSession(); var results = new ParallelShardAccessStrategy().Apply(new[] { shard1 }, x => (IList<Company>)null); Assert.Equal(0, results.Count); } }
public void ExecutionExceptionsAreRethrown() { using (GetNewServer()) using (var shard1 = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) using (var session = shard1.OpenAsyncSession()) { var parallelShardAccessStrategy = new ParallelShardAccessStrategy(); Assert.Throws<ApplicationException>(() => parallelShardAccessStrategy.ApplyAsync<object>(new[] { shard1.AsyncDatabaseCommands }, new ShardRequestData(), (x, i) => { throw new ApplicationException(); }).Wait()); } }
public void ExecutionExceptionsAreRethrown() { using (GetNewServer()) using (var shard1 = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) using (var session = shard1.OpenSession()) { var parallelShardAccessStrategy = new ParallelShardAccessStrategy(); Assert.Throws <ApplicationException>(() => parallelShardAccessStrategy.Apply <object>(new[] { shard1.DatabaseCommands }, new ShardRequestData(), (x, i) => { throw new ApplicationException(); })); } }
public void NullResultIsNotAnException() { using(GetNewServer(port, path)) using (var shard1 = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) using (var session = shard1.OpenSession()) { var results = new ParallelShardAccessStrategy().Apply(new[] { session.Advanced.DatabaseCommands }, (x, i) => (IList<Company>)null); Assert.Equal(1, results.Length); Assert.Null(results[0]); } }
public void NullResultIsNotAnException() { using(GetNewServer(port, path)) using (var shard1 = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) using (var session = shard1.OpenAsyncSession()) { var results = new ParallelShardAccessStrategy().ApplyAsync(new[] { shard1.AsyncDatabaseCommands }, new ShardRequestData(), (x, i) => CompletedTask.With((IList<Company>)null).Task).Result; Assert.Equal(1, results.Length); Assert.Null(results[0]); } }
public void Null_result_is_not_an_exception() { using (GetNewServer(port, path)) { var shard1 = new DocumentStore { Url = "http://localhost:8079" }.Initialize().OpenSession(); var results = new ParallelShardAccessStrategy().Apply(new[] { shard1 }, x => (IList <Company>)null); Assert.Equal(0, results.Count); } }
public void NullResultIsNotAnException() { using (GetNewServer()) using (var shard1 = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) using (var session = shard1.OpenSession()) { var results = new ParallelShardAccessStrategy().Apply(new[] { shard1.DatabaseCommands }, new ShardRequestData(), (x, i) => (IList <Company>)null); Assert.Equal(1, results.Length); Assert.Null(results[0]); } }
public void Can_get_complete_result_list() { var shard1 = MockRepository.GenerateStub<IDocumentSession>(); var documentQuery1 = MockRepository.GenerateStub<IDocumentQuery<Company>>(); shard1.Stub(x => x.Query<Company>().GetEnumerator()) .Return(new List<Company> { new Company { Name = "Company1" } }.GetEnumerator()); var shard2 = MockRepository.GenerateStub<IDocumentSession>(); shard2.Stub(x => x.Query<Company>().GetEnumerator()) .Return(new List<Company> { new Company { Name = "Company2" } }.GetEnumerator()); var results = new ParallelShardAccessStrategy().Apply(new[] { shard1, shard2 }, x => x.Query<Company>().ToArray()); Assert.Equal(2, results.Count); }
protected IDocumentStore CreateDocumentStore(string prefix) { var documentStore = _documentStores.GetOrAdd(prefix, key => { IDocumentStore ds = null; var shardCountValue = ConfigurationManager.AppSettings.Get(key + ".ShardCount"); int shardCount; if (int.TryParse(shardCountValue, out shardCount)) { var shards = new Dictionary <string, IDocumentStore>(); for (var i = 0; i < shardCount; i++) { var url = ConfigurationManager.AppSettings.Get(key + ".Shard." + i + ".Url"); var id = ConfigurationManager.AppSettings.Get(key + ".Shard." + i + ".Identifier"); shards.Add(id, new DocumentStore { Identifier = id, Url = url }); } var accessStrategyTypeName = ConfigurationManager.AppSettings.Get(key + ".Shard.AccessStrategy"); var resolutionStrategyTypeName = ConfigurationManager.AppSettings.Get(key + ".Shard.ResolutionStrategy"); var selectionStrategyTypeName = ConfigurationManager.AppSettings.Get(key + ".Shard.SelectionStrategy"); IShardAccessStrategy accessStrategy; IShardResolutionStrategy resolutionStrategy; if (!string.IsNullOrEmpty(accessStrategyTypeName) && Type.GetType(accessStrategyTypeName) != null) { accessStrategy = (IShardAccessStrategy)Activator.CreateInstance(Type.GetType(accessStrategyTypeName)); } else { accessStrategy = new ParallelShardAccessStrategy(); } var shardStrategy = new ShardStrategy(shards) { ShardAccessStrategy = accessStrategy }; if (!string.IsNullOrEmpty(resolutionStrategyTypeName) && Type.GetType(resolutionStrategyTypeName) != null) { resolutionStrategy = (IShardResolutionStrategy)Activator.CreateInstance(Type.GetType(resolutionStrategyTypeName)); } else { resolutionStrategy = new DefaultShardResolutionStrategy(shards.Keys, shardStrategy); } ds = new ShardedDocumentStore(shardStrategy); ds.Initialize(); } else { var url = ConfigurationManager.AppSettings.Get(key); if (!string.IsNullOrEmpty(url)) { ds = new DocumentStore() { Url = url }; ds.Initialize(); } } return(ds); }); return(documentStore); }
public ShardStrategy() { ShardAccessStrategy = new ParallelShardAccessStrategy(); ShardSelectionStrategy = new ShardSelectionByRegion(); ShardResolutionStrategy = new AllShardsResolutionStrategy(); }
public UserShardStrategy() { ShardAccessStrategy = new ParallelShardAccessStrategy(); //default ShardSelectionStrategy = new UserShardSelectionStrategy(); //defined by user ShardResolutionStrategy = new AllShardsResolutionStrategy(); //default }