Initialize() public method

Initializes this instance.
public Initialize ( ) : IDocumentStore
return IDocumentStore
Ejemplo n.º 1
0
		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();
		}
Ejemplo n.º 2
0
		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();
		}
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
		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);
				}
			}
		}
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }
Ejemplo n.º 7
0
		public void CanQueryUsingInt()
		{
			shardStrategy.ShardAccessStrategy = new SequentialShardAccessStrategy();
			using (var documentStore = new ShardedDocumentStore(shardStrategy))
			{
				documentStore.Initialize();

				using (var session = documentStore.OpenSession())
				{
					session.Load<Company>(1);
				}
			}
		}
Ejemplo n.º 8
0
        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();
                }
            }
        }
Ejemplo n.º 9
0
        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);
                }
            }
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
		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();
		}
Ejemplo n.º 12
0
		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();
		}
Ejemplo n.º 13
0
		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);
				}
			}
		}
Ejemplo n.º 14
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);
				}
			}
		}
Ejemplo n.º 15
0
        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]);
        }
Ejemplo n.º 16
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));

                }
            }
        }
Ejemplo n.º 17
0
		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);
				}
			}
		}
Ejemplo n.º 19
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
		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);
				}
			}
		}
Ejemplo n.º 21
0
        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);
		        }
	        }
        }
Ejemplo n.º 22
0
		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();
				}
			}
		}
Ejemplo n.º 23
0
		public void CanInsertIntoTwoShardedServers()
		{
			using (var documentStore = new ShardedDocumentStore(shardStrategy))
			{
				documentStore.Initialize();

				using (var session = documentStore.OpenSession())
				{
					session.Store(company1);
					session.Store(company2);
					session.SaveChanges();
				}
			}
		}
Ejemplo n.º 24
0
		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();
			}
		}
Ejemplo n.º 25
0
        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);
				}
			}
		}
Ejemplo n.º 27
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);
			}
		}
        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;
        }
Ejemplo n.º 29
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 30
0
		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);
				}
			}
		}