Пример #1
0
        public async Task Can_get_stats_for_all_active_file_systems()
        {
            var client = NewClient();
            var server = GetServer();

            using (var anotherClient = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "test"))
            {
                await anotherClient.EnsureFileSystemExistsAsync();

                await client.UploadAsync("test1", new RandomStream(10));        // will make it active

                await anotherClient.UploadAsync("test1", new RandomStream(10)); // will make it active

                await client.UploadAsync("test2", new RandomStream(10));

                var stats = await anotherClient.Admin.GetFileSystemsStats();

                var stats1 = stats.FirstOrDefault(x => x.Name == client.FileSystemName);
                Assert.NotNull(stats1);
                var stats2 = stats.FirstOrDefault(x => x.Name == anotherClient.FileSystemName);
                Assert.NotNull(stats2);

                Assert.Equal(2, stats1.Metrics.Requests.Count);
                Assert.Equal(1, stats2.Metrics.Requests.Count);

                Assert.Equal(0, stats1.ActiveSyncs.Count);
                Assert.Equal(0, stats1.PendingSyncs.Count);

                Assert.Equal(0, stats2.ActiveSyncs.Count);
                Assert.Equal(0, stats2.PendingSyncs.Count);
            }
        }
Пример #2
0
        public async Task ShouldThrowWhenUsedApiKeyDefinitionDoesNotContainFileSystem()
        {
            var client = NewClient(enableAuthentication: true, apiKey: apiKey);
            var server = GetServer();

            await client.UploadAsync("abc.bin", new RandomStream(3));

            using (var anotherClient = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_ApiKeyDoesnContainsThisFS", apiKey: apiKey))
            {
                await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database

                ErrorResponseException errorResponse = null;

                try
                {
                    await anotherClient.UploadAsync("def.bin", new RandomStream(1)); // should throw because a file system ShouldThrow_ApiKeyDoesnContainsThisFS isn't added to ApiKeyDefinition
                }
                catch (InvalidOperationException ex)
                {
                    errorResponse = ex.InnerException as ErrorResponseException;
                }

                Assert.NotNull(errorResponse);
                Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode);
            }
        }
Пример #3
0
        public async Task ShouldThrowWhenWindowsDocumentDoesNotContainFileSystem()
        {
            // in this test be careful if the specified credentials belong to admin user or not

            var client = NewClient(enableAuthentication: true, credentials: new NetworkCredential(username, password, domain));
            var server = GetServer();

            await client.UploadAsync("abc.bin", new RandomStream(3));

            using (var anotherClient = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_WindowsDocumentDoesnContainsThisFS",
                                                                 credentials: new NetworkCredential(username, password, domain)))
            {
                await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database

                ErrorResponseException errorResponse = null;

                try
                {
                    await anotherClient.UploadAsync("def.bin", new RandomStream(1)); // should throw because a file system ShouldThrow_ApiKeyDoesnContainsThisFS isn't added to ApiKeyDefinition
                }
                catch (InvalidOperationException ex)
                {
                    errorResponse = ex.InnerException as ErrorResponseException;
                }

                Assert.NotNull(errorResponse);
                Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode);
            }
        }
Пример #4
0
        protected virtual RavenFileSystemClient NewClient(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 client = new RavenFileSystemClient(GetServerUrl(fiddler, server.SystemDatabase.ServerUrl), fileSystemName, apiKey: apiKey, credentials: credentials);

            client.EnsureFileSystemExistsAsync().Wait();

            ravenFileSystemClients.Add(client);

            return(client);
        }
Пример #5
0
        public async Task ShouldThrowWhenUsedApiKeyDefinitionDoesNotContainFileSystem()
        {
            var client = NewClient(enableAuthentication: true, apiKey: apiKey);
            var server = GetServer();

            await client.UploadAsync("abc.bin", new RandomStream(3));

            using (var anotherClient = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_ApiKeyDoesnContainsThisFS", apiKey: apiKey))
            {
                await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database

                ErrorResponseException errorResponse = null;

                try
                {
                    await anotherClient.UploadAsync("def.bin", new RandomStream(1)); // should throw because a file system ShouldThrow_ApiKeyDoesnContainsThisFS isn't added to ApiKeyDefinition
                }
                catch (InvalidOperationException ex)
                {
                    errorResponse = ex.InnerException as ErrorResponseException;
                }
                
                Assert.NotNull(errorResponse);
                Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode);
            }
        }
Пример #6
0
        public async Task ShouldThrowWhenWindowsDocumentDoesNotContainFileSystem()
        {
            // in this test be careful if the specified credentials belong to admin user or not

            var client = NewClient(enableAuthentication: true, credentials: new NetworkCredential(username, password, domain));
            var server = GetServer();

            await client.UploadAsync("abc.bin", new RandomStream(3));

            using (var anotherClient = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "ShouldThrow_WindowsDocumentDoesnContainsThisFS", 
                credentials: new NetworkCredential(username, password, domain)))
            {
                await anotherClient.EnsureFileSystemExistsAsync(); // will pass because by using this api key we have access to <system> database

                ErrorResponseException errorResponse = null;

                try
                {
                    await anotherClient.UploadAsync("def.bin", new RandomStream(1)); // should throw because a file system ShouldThrow_ApiKeyDoesnContainsThisFS isn't added to ApiKeyDefinition
                }
                catch (InvalidOperationException ex)
                {
                    errorResponse = ex.InnerException as ErrorResponseException;
                }

                Assert.NotNull(errorResponse);
                Assert.Equal(HttpStatusCode.Forbidden, errorResponse.StatusCode);
            }
        }
Пример #7
0
        protected virtual RavenFileSystemClient NewClient(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 client = new RavenFileSystemClient(GetServerUrl(fiddler, server.SystemDatabase.ServerUrl), fileSystemName, apiKey: apiKey, credentials: credentials);

            client.EnsureFileSystemExistsAsync().Wait();

            ravenFileSystemClients.Add(client);

            return client;
        }
Пример #8
0
	    public async Task Can_get_stats_for_all_active_file_systems()
	    {
	        var client = NewClient();
	        var server = GetServer();

	        using (var anotherClient = new RavenFileSystemClient(GetServerUrl(false, server.SystemDatabase.ServerUrl), "test"))
	        {
	            await anotherClient.EnsureFileSystemExistsAsync();

                await client.UploadAsync("test1", new RandomStream(10)); // will make it active
	            await anotherClient.UploadAsync("test1", new RandomStream(10)); // will make it active

                await client.UploadAsync("test2", new RandomStream(10));

	            var stats = await anotherClient.Admin.GetFileSystemsStats();

	            var stats1 = stats.FirstOrDefault(x => x.Name == client.FileSystemName);
                Assert.NotNull(stats1);
	            var stats2 = stats.FirstOrDefault(x => x.Name == anotherClient.FileSystemName);
	            Assert.NotNull(stats2);

                Assert.Equal(2, stats1.Metrics.Requests.Count);
                Assert.Equal(1, stats2.Metrics.Requests.Count);

                Assert.Equal(0, stats1.ActiveSyncs.Count);
                Assert.Equal(0, stats1.PendingSyncs.Count);

                Assert.Equal(0, stats2.ActiveSyncs.Count);
                Assert.Equal(0, stats2.PendingSyncs.Count);
	        }
	    }