Exemple #1
0
        public void can_get_container_not_found()
        {
            var containerName = Guid.NewGuid().ToString();

            using (var client = new RavenAzureClient(Azure.GetAzureSettings(containerName)))
            {
                var containerNames = client.GetContainerNames(500);
                Assert.False(containerNames.Exists(x => x.Equals(containerName)));

                var e = Assert.Throws <ContainerNotFoundException>(() => client.TestConnection());
                Assert.Equal($"Container '{containerName}' wasn't found!", e.Message);

                containerNames = client.GetContainerNames(500);
                Assert.False(containerNames.Exists(x => x.Equals(containerName)));
            }
        }
Exemple #2
0
        public async Task can_get_container_not_found()
        {
            var containerName = Guid.NewGuid().ToString();

            using (var client = new RavenAzureClient(AzureAccountName, AzureAccountKey, containerName, isTest: true))
            {
                var containerNames = await client.GetContainerNames(500);

                Assert.False(containerNames.Exists(x => x.Equals(containerName)));

                var e = await Assert.ThrowsAsync <ContainerNotFoundException>(async() => await client.TestConnection());

                Assert.Equal($"Container '{containerName}' not found!", e.Message);

                containerNames = await client.GetContainerNames(500);

                Assert.False(containerNames.Exists(x => x.Equals(containerName)));
            }
        }
Exemple #3
0
        public async Task TestPeriodicBackupCredentials()
        {
            var type = GetQueryStringValueAndAssertIfSingleAndNotEmpty("type");

            if (Enum.TryParse(type, out PeriodicBackupConnectionType connectionType) == false)
            {
                throw new ArgumentException($"Unknown backup connection: {type}");
            }

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
            {
                DynamicJsonValue result;
                try
                {
                    var connectionInfo = await context.ReadForMemoryAsync(RequestBodyStream(), "test-connection");

                    switch (connectionType)
                    {
                    case PeriodicBackupConnectionType.S3:
                        var s3Settings = JsonDeserializationClient.S3Settings(connectionInfo);
                        using (var awsClient = new RavenAwsS3Client(s3Settings, cancellationToken: ServerStore.ServerShutdown))
                        {
                            awsClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.Glacier:
                        var glacierSettings = JsonDeserializationClient.GlacierSettings(connectionInfo);
                        using (var glacierClient = new RavenAwsGlacierClient(glacierSettings, cancellationToken: ServerStore.ServerShutdown))
                        {
                            glacierClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.Azure:
                        var azureSettings = JsonDeserializationClient.AzureSettings(connectionInfo);
                        using (var azureClient = new RavenAzureClient(azureSettings, cancellationToken: ServerStore.ServerShutdown))
                        {
                            azureClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.GoogleCloud:
                        var googleCloudSettings = JsonDeserializationClient.GoogleCloudSettings(connectionInfo);
                        using (var googleCloudClient = new RavenGoogleCloudClient(googleCloudSettings, cancellationToken: ServerStore.ServerShutdown))
                        {
                            await googleCloudClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.FTP:
                        var ftpSettings = JsonDeserializationClient.FtpSettings(connectionInfo);
                        using (var ftpClient = new RavenFtpClient(ftpSettings))
                        {
                            ftpClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.Local:
                    case PeriodicBackupConnectionType.None:
                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    result = new DynamicJsonValue
                    {
                        [nameof(NodeConnectionTestResult.Success)] = true,
                    };
                }
                catch (Exception e)
                {
                    result = new DynamicJsonValue
                    {
                        [nameof(NodeConnectionTestResult.Success)] = false,
                        [nameof(NodeConnectionTestResult.Error)]   = e.ToString()
                    };
                }

                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    context.Write(writer, result);
                }
            }
        }