Example #1
0
        protected override void ModifyStore(FilesStore store)
        {
            FactIfWindowsAuthenticationIsAvailable.LoadCredentials();
            ConfigurationHelper.ApplySettingsToConventions(store.Conventions);

            base.ModifyStore(store);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add MVC services to the services container.
            services.AddMvc();
            
            services.AddSingleton(p =>
            {
                var documentStore = new DocumentStore()
                {
                    Url = Configuration["RavenDb:Url"],
                    DefaultDatabase = Configuration["RavenDb:DefaultDatabase"]
                }.Initialize();

                IndexCreation.CreateIndexes(this.GetType().Assembly, documentStore);
                return documentStore;
            });
            services.AddSingleton(p =>
            {
                var fsStore = new FilesStore()
                {
                    Url = Configuration["RavenDb:Url"],
                    DefaultFileSystem = Configuration["RavenDb:DefaultFilesStore"]
                }.Initialize();
                return fsStore;
            });


        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryFilesSessionOperations"/> class.
        /// </summary>
        protected InMemoryFilesSessionOperations(FilesStore filesStore, FilesSessionListeners listeners, Guid id)
        {
            this.Id           = id;
            this.filesStore   = filesStore;
            this.theListeners = listeners;

            this.MaxNumberOfRequestsPerSession = filesStore.Conventions.MaxNumberOfRequestsPerSession;
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryFilesSessionOperations"/> class.
		/// </summary>
        protected InMemoryFilesSessionOperations( FilesStore filesStore, FilesSessionListeners listeners, Guid id)
		{
            Id = id;
            this.filesStore = filesStore;
            theListeners = listeners;            

            MaxNumberOfRequestsPerSession = filesStore.Conventions.MaxNumberOfRequestsPerSession;
	        UseOptimisticConcurrency = filesStore.Conventions.DefaultUseOptimisticConcurrency;
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryFilesSessionOperations"/> class.
        /// </summary>
        protected InMemoryFilesSessionOperations( FilesStore filesStore, FilesSessionListeners listeners, Guid id)
        {
            Id = id;
            this.filesStore = filesStore;
            theListeners = listeners;            

            MaxNumberOfRequestsPerSession = filesStore.Conventions.MaxNumberOfRequestsPerSession;
            UseOptimisticConcurrency = filesStore.Conventions.DefaultUseOptimisticConcurrency;
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
 /// </summary>
 public AsyncFilesSession(FilesStore filesStore,
                          IAsyncFilesCommands asyncFilesCommands,
                          FilesSessionListeners listeners,
                          Guid id)
     : base(filesStore, listeners, id)
 {
     Commands = asyncFilesCommands;
     filesStore.Changes().ForConflicts().Subscribe(this);
 }
Example #7
0
        public async Task CanMigrateAttachmentsToFileSystemOnDifferentServer()
        {
            using (var store = NewRemoteDocumentStore())
            using (GetNewServer(8078))
            using (var fsStore = new FilesStore()
            {
                Url = "http://localhost:8078",
                DefaultFileSystem = "RavenDB_2115"
            }.Initialize(true))
            {
                var random = new Random();
                var bytes = new byte[137];

                random.NextBytes(bytes);

                for (int i = 0; i < 10; i++)
                {
                    store.DatabaseCommands.PutAttachment("files/" + i, null, new MemoryStream(bytes), new RavenJObject());
                }

                new CopyAttachmentsToFileSystem(new RavenConnectionStringOptions()
                {
                    Url = store.Url,
                    DefaultDatabase = store.DefaultDatabase
                }, new RavenConnectionStringOptions()
                {
                    Url = "http://localhost:8078",
                }, "RavenDB_2115", false, 1).Execute();

                Assert.Equal(10, store.DatabaseCommands.GetStatistics().CountOfAttachments);

                var browseResult = await fsStore.AsyncFilesCommands.BrowseAsync();

                Assert.Equal(10, browseResult.Length);

                for (int i = 10; i < 20; i++)
                {
                    store.DatabaseCommands.PutAttachment("files/" + i, null, new MemoryStream(bytes), new RavenJObject());
                }

                new CopyAttachmentsToFileSystem(new RavenConnectionStringOptions()
                {
                    Url = store.Url,
                    DefaultDatabase = store.DefaultDatabase
                }, new RavenConnectionStringOptions()
                {
                    Url = "http://localhost:8078",
                }, "RavenDB_2115", true, 3).Execute();

                Assert.Equal(0, store.DatabaseCommands.GetStatistics().CountOfAttachments);

                browseResult = await fsStore.AsyncFilesCommands.BrowseAsync();

                Assert.Equal(20, browseResult.Length);
            }
        }
        private static IFilesStore CreateStore()
        {
            var filesStore = new FilesStore()
            {
                Url = String.Format("http://{0}:{1}", DocumentStoreHolder.Address, DocumentStoreHolder.Port),
                DefaultFileSystem = DocumentStoreHolder.DatabaseName + "FS"
            }.Initialize();

            return filesStore;
        }
        public override bool InitBackup()
        {
            parameters.ServerUrl = parameters.ServerUrl.TrimEnd('/');
            try //precaution - to show error properly just in case
            {
                var serverUri = new Uri(parameters.ServerUrl);
                var serverHostname = serverUri.Scheme + Uri.SchemeDelimiter + serverUri.Host + ":" + serverUri.Port;

                store = new FilesStore { Url = serverHostname, DefaultFileSystem = parameters.Filesystem, ApiKey = parameters.ApiKey, Credentials = parameters.Credentials };
                store.Initialize();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
                try
                {
                    store.Dispose();
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception) { }
                return false;
            }


            var backupRequest = new
            {
                BackupLocation = parameters.BackupPath.Replace("\\", "\\\\"),
            };


            var json = RavenJObject.FromObject(backupRequest).ToString();

            var url = "/admin/backup";
            if (parameters.Incremental)
                url += "?incremental=true";
            try
            {
	            using (var req = CreateRequest("/fs/" + parameters.Filesystem + url, "POST"))
	            {
					req.WriteAsync(json).Wait();

					Console.WriteLine("Sending json {0} to {1}", json, parameters.ServerUrl);

					var response = req.ReadResponseJson();
					Console.WriteLine(response);
	            }  
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
                return false;
            }

            return true;
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
 /// </summary>
 public AsyncFilesSession(FilesStore filesStore,
                          IAsyncFilesCommands asyncFilesCommands,
                          FilesSessionListeners listeners,
                          Guid id)
     : base(filesStore, listeners, id)
 {
     Commands             = asyncFilesCommands;
     conflictCacheRemoval = filesStore.Changes(this.FileSystemName)
                            .ForConflicts()
                            .Subscribe(new FileConflictObserver(this));
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
 /// </summary>
 public AsyncFilesSession(FilesStore filesStore,
                          IAsyncFilesCommands asyncFilesCommands,
                          FilesSessionListeners listeners,
                          Guid id)
     : base(filesStore, listeners, id)
 {
     Commands             = asyncFilesCommands;
     conflictCacheRemoval = filesStore.Changes(this.FileSystemName)
                            .ForConflicts()
                            .Subscribe <ConflictNotification>(this.OnFileConflict);
 }
Example #12
0
        /// <summary>
		/// Initializes a new instance of the <see cref="AsyncFilesSession"/> class.
		/// </summary>
        public AsyncFilesSession(FilesStore filesStore,
                                 IAsyncFilesCommands asyncFilesCommands,
								 FilesSessionListeners listeners,
								 Guid id)
			: base(filesStore, listeners, id)
		{
            Commands = asyncFilesCommands;
            conflictCacheRemoval = filesStore.Changes(this.FileSystemName)
                                             .ForConflicts()
                                             .Subscribe<ConflictNotification>(this.OnFileConflict);
		}
        public override async Task ImportData(SmugglerImportOptions<FilesConnectionStringOptions> importOptions)
        {
            if (importOptions.To == null)
                throw new ArgumentNullException("importOptions");

            using (primaryStore = await CreateStore(importOptions.To))
            using (documentStore = CreateDocumentStore(importOptions.To))
            {
                Operations = new SmugglerRemoteFilesOperations(() => primaryStore, () => documentStore);

                await base.ImportData(importOptions);
            }
        }
        public override async Task<ExportFilesResult> ExportData(SmugglerExportOptions<FilesConnectionStringOptions> exportOptions)
        {
            if (exportOptions.From == null)
                throw new ArgumentNullException("exportOptions");

            using (primaryStore = await CreateStore(exportOptions.From))
            using (documentStore = CreateDocumentStore(exportOptions.From))
			{
                Operations = new SmugglerRemoteFilesOperations(() => primaryStore, () => documentStore);

				return await base.ExportData(exportOptions);
			}
        }
Example #15
0
        public void CredentialsAreLoadedFromConnectionString()
        {
            using (var store = new FilesStore()
            {
                ConnectionStringName = "RavenFS"
            })
            {
                var credentials = (NetworkCredential)store.Credentials;

                Assert.Equal("local_user_test", credentials.UserName);
                Assert.Equal("local_user_test", credentials.Password);
                Assert.Equal(string.Empty, credentials.Domain);
            }
        }
 protected async Task WaitForSynchronization(FilesStore store)
 {
     for (int i = 0; i < RetriesCount; i++)
     {
         using (var session = store.OpenAsyncSession())
         {
             try
             {
                 var file = await session.DownloadAsync(FileName);
                 break;
             }
             catch { }
             Thread.Sleep(100);
         }
     }
 }
        public override async Task Between(SmugglerBetweenOptions<FilesConnectionStringOptions> betweenOptions)
        {
            if (betweenOptions.From == null)
                throw new ArgumentNullException("betweenOptions.From");

            if (betweenOptions.To == null)
                throw new ArgumentNullException("betweenOptions.To");            

            using (primaryStore = await CreateStore(betweenOptions.From))
            using (secondaryStore = await CreateStore(betweenOptions.To))
            using (documentStore = CreateDocumentStore(betweenOptions.To))
            {
                Operations = new SmugglerBetweenRemoteFilesOperations(() => primaryStore, () => secondaryStore, () => documentStore);

                await base.Between(betweenOptions);
            }              
        }
Example #18
0
 public RavenDbServer(InMemoryRavenConfiguration configuration)
 {
     this.configuration = configuration;
     documentStore = new DocumentStore
     {
         Conventions =
         {
             FailoverBehavior = FailoverBehavior.FailImmediately
         }
     };
     filesStore = new FilesStore
     {
         Conventions =
         {
             FailoverBehavior = FailoverBehavior.FailImmediately
         }
     };
 }
Example #19
0
        protected virtual IAsyncFilesCommands NewAsyncClient(int index = 0, bool fiddler = false, bool enableAuthentication = false, string apiKey = null, 
                                                             ICredentials credentials = null, string requestedStorage = null, [CallerMemberName] string fileSystemName = null)
        {
            fileSystemName = NormalizeFileSystemName(fileSystemName);

            var server = CreateServer(Ports[index], fileSystemName: fileSystemName, enableAuthentication: enableAuthentication, requestedStorage: requestedStorage);
            server.Url = GetServerUrl(fiddler, server.SystemDatabase.ServerUrl);

            var store = new FilesStore()
            {
                Url = server.Url,
                DefaultFileSystem = fileSystemName,
                Credentials = credentials,
                ApiKey = apiKey,
            };

            store.Initialize(true);

            this.filesStores.Add(store);

            var client = store.AsyncFilesCommands;
            asyncCommandClients.Add(client);

            return client;       
        }
        internal static async Task<FilesStore> CreateStore(FilesConnectionStringOptions options)
        {
            var credentials = options.Credentials as NetworkCredential;
            if (credentials == null)
            {
                credentials = CredentialCache.DefaultNetworkCredentials;
            }
            else if ((String.IsNullOrWhiteSpace(credentials.UserName) || String.IsNullOrWhiteSpace(credentials.Password)))
            {
                credentials = CredentialCache.DefaultNetworkCredentials;
            }

            var store = new FilesStore
            {
                Credentials = credentials,
                ApiKey = options.ApiKey,
                Url = options.Url,
                DefaultFileSystem = options.DefaultFileSystem,
            };

            store.Initialize();

            await ValidateThatServerIsUpAndFilesystemExists(options, store);

            return store;
        }
        internal static async Task ValidateThatServerIsUpAndFilesystemExists(FilesConnectionStringOptions server, FilesStore s)
        {
            var shouldDispose = false;

            try
            {
                var commands = !string.IsNullOrEmpty(server.DefaultFileSystem)
                                   ? s.AsyncFilesCommands.ForFileSystem(server.DefaultFileSystem)
                                   : s.AsyncFilesCommands;

                await commands.GetStatisticsAsync(); // check if file system exist
            }
            catch (Exception e)
            {
                shouldDispose = true;

                var responseException = e as ErrorResponseException;
                if (responseException != null && responseException.StatusCode == HttpStatusCode.ServiceUnavailable && responseException.Message.StartsWith("Could not find a file system named"))
                    throw new SmugglerException(
                        string.Format(
                            "Smuggler does not support file system creation (file system '{0}' on server '{1}' must exist before running Smuggler).",
                            server.DefaultFileSystem,
                            s.Url), e);


                if (e.InnerException != null)
                {
                    var webException = e.InnerException as WebException;
                    if (webException != null)
                    {
                        throw new SmugglerException(string.Format("Smuggler encountered a connection problem: '{0}'.", webException.Message), webException);
                    }
                } 
                throw new SmugglerException(string.Format("Smuggler encountered a connection problem: '{0}'.", e.Message), e);
            }
            finally
            {
                if (shouldDispose)
                    s.Dispose();
            }
        }
        protected virtual IAsyncFilesCommands NewAsyncClient(int index = 0, 
			bool fiddler = false, 
			bool enableAuthentication = false, 
			string apiKey = null, 
			ICredentials credentials = null, 
            string requestedStorage = null, 
			[CallerMemberName] string fileSystemName = null, 
			Action<RavenConfiguration> customConfig = null,
			string activeBundles = null,
			string dataDirectory = null,
			bool runInMemory = true)
        {
            fileSystemName = NormalizeFileSystemName(fileSystemName);

	        var server = CreateServer(Ports[index], fileSystemName: fileSystemName, enableAuthentication: enableAuthentication, requestedStorage: requestedStorage, activeBundles: activeBundles, customConfig: customConfig,
				dataDirectory: dataDirectory, runInMemory: runInMemory);
            server.Url = GetServerUrl(fiddler, server.SystemDatabase.ServerUrl);

            var store = new FilesStore()
            {
                Url = server.Url,
                DefaultFileSystem = fileSystemName,
                Credentials = credentials,
                ApiKey = apiKey,
            };

            store.Initialize(true);

            filesStores.Add(store);

            var client = store.AsyncFilesCommands;
            asyncCommandClients.Add(client);

            return client;       
        }
Example #23
0
		private static void RunRemoteFilesystemRestoreOperation(string backupLocation, string restoreLocation, string restoreFilesystemName, bool defrag, Uri uri, bool waitForRestore, int? timeout)
		{
			long operationId;
			using (var filesStore = new FilesStore
									{
										Url = uri.AbsoluteUri
									}.Initialize())
			{
				operationId = filesStore.AsyncFilesCommands.Admin.StartRestore(new FilesystemRestoreRequest
																			   {
																				   BackupLocation = backupLocation,
																				   FilesystemLocation = restoreLocation,
																				   FilesystemName = restoreFilesystemName,
																				   Defrag = defrag,
																				   RestoreStartTimeout = timeout
																			   }).ResultUnwrap();
				Console.WriteLine("Started restore operation from {0} on {1} server.", backupLocation, uri.AbsoluteUri);
			}

			if (waitForRestore)
			{
				using (var sysDbStore = new DocumentStore
										{
											Url = uri.AbsoluteUri
										}.Initialize())
				{
					new Operation((AsyncServerClient)sysDbStore.AsyncDatabaseCommands, operationId).WaitForCompletion();
					Console.WriteLine("Completed restore operation from {0} on {1} server.", backupLocation, uri.AbsoluteUri);
				}
			}
		}
Example #24
0
        protected virtual IFilesStore NewStore( int index = 0, bool fiddler = false, bool enableAuthentication = false, string apiKey = null, 
                                                ICredentials credentials = null, string requestedStorage = null, [CallerMemberName] string fileSystemName = null)
        {
            fileSystemName = NormalizeFileSystemName(fileSystemName);

            var server = CreateRavenDbServer(Ports[index], fileSystemName: fileSystemName, enableAuthentication: enableAuthentication, requestedStorage: requestedStorage);

            var store = new FilesStore()
            {
                Url = GetServerUrl(fiddler, server.SystemDatabase.ServerUrl),
                DefaultFileSystem = fileSystemName,
                Credentials = credentials,
                ApiKey = apiKey,                 
            };

            store.Initialize(true);

            this.filesStores.Add(store);

            return store;                        
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InMemoryFilesSessionOperations"/> class.
		/// </summary>
        protected InMemoryFilesSessionOperations( FilesStore filesStore, FilesSessionListeners listeners, Guid id)
		{
            this.Id = id;
            this.filesStore = filesStore;
            this.theListeners = listeners;            

            this.MaxNumberOfRequestsPerSession = filesStore.Conventions.MaxNumberOfRequestsPerSession;
		}
Example #26
0
        public async Task after_failed_upload_file_should_not_exist()
        {
            const int fileSize = 1024*1024*2; // 2 MB
            const string fileName = "test.bin";
            const int portIndex = 0;

            using (var initialStore = NewStore(portIndex))
            {
                var alreadyReset = false;
                var port = 8070;
                var putInitialized = false;
                var uploaded = 0;

                using (new ProxyServer(ref port, Ports[portIndex])
                {
                    VetoTransfer = (totalRead, buffer) =>
                    {
                        var numOfBytes = buffer.Count - buffer.Offset;
                        var s = Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count);

                        if (s.StartsWith("PUT"))
                        {
                            putInitialized = true;
                            uploaded = numOfBytes;
                            return false;
                        }

                        if (putInitialized && alreadyReset == false)
                        {
                            uploaded += numOfBytes;

                            if (uploaded > fileSize / 2)
                            {
                                alreadyReset = true;
                                return true;
                            }
                        }

                        return false;
                    }
                })
                {
                    using (var storeUsingProxy = new FilesStore
                    {
                        Url = "http://localhost:" + port,
                        DefaultFileSystem = initialStore.DefaultFileSystem
                    }.Initialize())
                    {
                        HttpRequestException hre = null;

                        try
                        {
                            await storeUsingProxy.AsyncFilesCommands.UploadAsync(fileName, new MemoryStream(new byte[fileSize]));
                        }
                        catch (HttpRequestException e)
                        {
                            hre = e;
                        }

                        Assert.NotNull(hre);

                        // the exception we caught was actually the client side exception because our proxy server forced the connection to be closed
                        // wait a bit to make sure the actual request completed and the file has been marked as deleted on the server side

                        Thread.Sleep(1000);

                        var fileMetadata = await storeUsingProxy.AsyncFilesCommands.GetMetadataForAsync(fileName);

                        Assert.Null(fileMetadata);
                    }
                }
            }
        }
Example #27
0
        protected virtual FilesStore NewStore( int index = 0, bool fiddler = false, bool enableAuthentication = false, string apiKey = null, 
                                                ICredentials credentials = null, string requestedStorage = null, [CallerMemberName] string fileSystemName = null, 
                                                bool runInMemory = true, Action<RavenConfiguration> customConfig = null)
        {
            fileSystemName = NormalizeFileSystemName(fileSystemName);

            var server = CreateServer(Ports[index], 
                fileSystemName: fileSystemName,
                enableAuthentication: enableAuthentication, 
                customConfig: customConfig,
                requestedStorage: requestedStorage, 
                runInMemory:runInMemory);

            server.Url = GetServerUrl(fiddler, server.SystemDatabase.ServerUrl);

            var store = new FilesStore
            {
                Url = server.Url,
                DefaultFileSystem = fileSystemName,
                Credentials = credentials,
                ApiKey = apiKey,                 
            };

            store.Initialize(true);

            this.filesStores.Add(store);

            return store;                        
        }
Example #28
0
		public async Task CleanerStartupTaskShouldRemoveFileSystemsAfterIdleTimeout()
		{
			using (var server = GetNewServer())
			using (var store = NewRemoteDocumentStore(ravenDbServer: server))
			using (var fStore = new FilesStore { Url = store.Url, DefaultFileSystem = store.DefaultDatabase }.Initialize())
			{
				await fStore.AsyncFilesCommands.Admin.CreateFileSystemAsync(new FileSystemDocument
				{
					Id = "Northwind",
					Settings =
					{
						{ Constants.FileSystem.DataDirectory, NewDataPath() }
					}
				}, "Northwind");

				await fStore.AsyncFilesCommands.Admin.CreateFileSystemAsync(new FileSystemDocument
				{
					Id = "Northwind2",
					Settings =
					{
						{ Constants.FileSystem.DataDirectory, NewDataPath() }
					}
				}, "Northwind2");

				await fStore.AsyncFilesCommands.Admin.CreateFileSystemAsync(new FileSystemDocument
				{
					Id = "Northwind3",
					Settings =
					{
						{ Constants.FileSystem.DataDirectory, NewDataPath() }
					}
				}, "Northwind3");

				await fStore
					.AsyncFilesCommands
					.ForFileSystem("Northwind2")
					.GetStatisticsAsync();

				await fStore
					.AsyncFilesCommands
					.ForFileSystem("Northwind3")
					.GetStatisticsAsync();

                Assert.NotNull(store.DatabaseCommands.ForSystemDatabase().Get(Constants.FileSystem.Prefix + "Northwind"));
                Assert.NotNull(store.DatabaseCommands.ForSystemDatabase().Get(Constants.FileSystem.Prefix + "Northwind2"));

				server
					.Options
					.ServerStartupTasks
					.OfType<LiveTestResourceCleanerStartupTask>().First()
					.ExecuteCleanup(null);

                Assert.Null(store.DatabaseCommands.ForSystemDatabase().Get(Constants.FileSystem.Prefix + "Northwind"));
                Assert.NotNull(store.DatabaseCommands.ForSystemDatabase().Get(Constants.FileSystem.Prefix + "Northwind2"));

				server.Server.Options.FileSystemLandlord.LastRecentlyUsed["Northwind2"] = DateTime.MinValue;

				server
					.Options
					.ServerStartupTasks
					.OfType<LiveTestResourceCleanerStartupTask>().First()
					.ExecuteCleanup(null);

                Assert.Null(store.DatabaseCommands.ForSystemDatabase().Get(Constants.FileSystem.Prefix + "Northwind2"));
                Assert.NotNull(store.DatabaseCommands.ForSystemDatabase().Get(Constants.FileSystem.Prefix + "Northwind3"));
			}
		}
 protected override void ModifyStore(FilesStore store)
 {
     store.Conventions.FailoverBehavior = FailoverBehavior.FailImmediately;
 }
        private async Task VerifyDump(FilesStore store, string backupPath, Action<FilesStore> action)
        {
            try
            {
                store.DefaultFileSystem += "-Verify";
                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(store.DefaultFileSystem);

                bool incremental = false;
                var directory = new DirectoryInfo(backupPath);
                if ( directory.Exists )
                    incremental = true;

                var dumper = new SmugglerFilesApi { Options = { Incremental = incremental } };                
                await dumper.ImportData(new SmugglerImportOptions<FilesConnectionStringOptions>
                {
                    FromFile = backupPath,
                    To = new FilesConnectionStringOptions
                    {
                        Url = store.Url,
                        DefaultFileSystem = store.DefaultFileSystem,
                    }
                });

                action(store);
            }
            catch (Exception e)
            {
                throw e.SimplifyException();
            }
        }
Example #31
0
        public void SecurityForDatabasesCountersAndFileSystemsShouldBeConfiguredInOnePlaceAndWorkByName()
        {
            Authentication.EnableOnce();
            using (var server = GetNewServer(enableAuthentication: true, runInMemory: false))
            {
                server
                    .SystemDatabase
                    .Documents
                    .Put(
                        "Raven/Databases/DB1",
                        null,
                        RavenJObject.FromObject(
                            new DatabaseDocument
                            {
                                Id = "DB1",
                                Settings =
                                {
                                    {"Raven/ActiveBundles", "PeriodicBackup"},
                                    {"Raven/DataDir", "~\\Databases\\DB1"}
                                }
                            }),
                        new RavenJObject(),
                        null);

                server
                    .SystemDatabase
                    .Documents
                    .Put(
                        "Raven/ApiKeys/key1",
                        null,
                        RavenJObject.FromObject(
                            new ApiKeyDefinition
                            {
                                Name = "key1", 
                                Secret = "ThisIsMySecret", 
                                Enabled = true, 
                                Databases = new List<ResourceAccess>
                                            {
                                                new ResourceAccess { TenantId = Constants.SystemDatabase, Admin = true },
                                                new ResourceAccess { TenantId = "DB1", Admin = true }
                                            }
                            }),
                        new RavenJObject(),
                        null);

                server
                    .SystemDatabase
                    .Documents
                    .Put(
                        "Raven/ApiKeys/key2",
                        null,
                        RavenJObject.FromObject(
                            new ApiKeyDefinition
                            {
                                Name = "key2",
                                Secret = "ThisIsMySecret2",
                                Enabled = true,
                                Databases = new List<ResourceAccess>
                                            {
                                                new ResourceAccess { TenantId = Constants.SystemDatabase, Admin = true },
                                                new ResourceAccess { TenantId = "DB2", Admin = true }
                                            }
                            }),
                        new RavenJObject(),
                        null);

                using (var store = new FilesStore
                                   {
                                       Url = server.Options.SystemDatabase.ServerUrl,
                                       DefaultFileSystem = "DB1",
                                       ApiKey = "key1/ThisIsMySecret"
                                   }.Initialize(ensureFileSystemExists: true))
                {
                    var files = AsyncHelpers.RunSync(() => store.AsyncFilesCommands.BrowseAsync());
                }

                using (var store = new DocumentStore
                                   {
                                       Url = server.Options.SystemDatabase.ServerUrl,
                                       DefaultDatabase = "DB1",
                                       ApiKey = "key1/ThisIsMySecret"
                                   }.Initialize())
                {
                    var indexes = store.DatabaseCommands.GetIndexNames(0, 10);
                }

                using (var store = new FilesStore
                {
                    Url = server.Options.SystemDatabase.ServerUrl,
                    DefaultFileSystem = "DB1",
                    ApiKey = "key2/ThisIsMySecret2"
                }.Initialize())
                {
                    var exception = Assert.Throws<ErrorResponseException>(() => AsyncHelpers.RunSync(() => store.AsyncFilesCommands.BrowseAsync()));
                    Assert.Equal(HttpStatusCode.Forbidden, exception.StatusCode);
                }

                using (var store = new DocumentStore
                {
                    Url = server.Options.SystemDatabase.ServerUrl,
                    DefaultDatabase = "DB1",
                    ApiKey = "key2/ThisIsMySecret2"
                }.Initialize())
                {
                    var exception = Assert.Throws<ErrorResponseException>(() => store.DatabaseCommands.GetIndexNames(0, 10));
                    Assert.Equal(HttpStatusCode.Forbidden, exception.StatusCode);
                }
            }
            
        }
 protected override void ModifyStore(FilesStore store)
 {
     store.Conventions.FailoverBehavior = FailoverBehavior.ReadFromAllServers;
 }