Skip to content

Commit

Permalink
RavenDB-3742 Raven.Backup.exe reports an error when backing up a file…
Browse files Browse the repository at this point in the history
…system
  • Loading branch information
Arkadiusz Palinski committed Aug 3, 2015
1 parent 4c27929 commit b7767d6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 32 deletions.
45 changes: 13 additions & 32 deletions Raven.Backup/FilesystemBackupOperation.cs
@@ -1,23 +1,16 @@
using System.Collections.Generic;
using System;
using System.Net;
using Raven.Abstractions.Connection;
using Raven.Abstractions.Data;
using Raven.Abstractions.Util;
using Raven.Client.Connection;
using Raven.Client.Connection.Implementation;
using Raven.Client.Document;
using Raven.Client.FileSystem;
using Raven.Json.Linq;
using System;
using System.Net;
using System.Threading;

using System.Linq;

using Raven.Abstractions.Extensions;

namespace Raven.Backup
{
using Raven.Abstractions.Connection;

public class FilesystemBackupOperation : AbstractBackupOperation
public class FilesystemBackupOperation : AbstractBackupOperation
{
private FilesStore store;

Expand Down Expand Up @@ -89,27 +82,15 @@ protected override HttpJsonRequest CreateRequest(string url, string method)

public override BackupStatus GetStatusDoc()
{
using (var req = CreateRequest("/fs/" + parameters.Filesystem + "/config/" + BackupStatus.RavenBackupStatusDocumentKey, "GET"))
try
{
var backupStatus = AsyncHelpers.RunSync(() => store.AsyncFilesCommands.Configuration.GetKeyAsync<BackupStatus>(BackupStatus.RavenBackupStatusDocumentKey));

return backupStatus;
}
catch (Exception ex)
{
try
{
var json = (RavenJObject)req.ReadResponseJson();
return json.JsonDeserialization<BackupStatus>();
}
catch (WebException ex)
{
var res = ex.Response as HttpWebResponse;
if (res == null)
{
throw new Exception("Network error");
}
if (res.StatusCode == HttpStatusCode.NotFound)
{
return null;
}
}

return null;
throw new Exception("Network error", ex);
}
}

Expand Down
42 changes: 42 additions & 0 deletions Raven.Tests.FileSystem/Issues/RavenDB_3742.cs
@@ -0,0 +1,42 @@
// -----------------------------------------------------------------------
// <copyright file="RavenDB_3742.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using Raven.Backup;
using Raven.Tests.Helpers;
using Xunit;
using Xunit.Extensions;

namespace Raven.Tests.FileSystem.Issues
{
public class RavenDB_3742 : RavenFilesTestBase
{
private readonly string BackupDir;

public RavenDB_3742()
{
BackupDir = NewDataPath("RavenDB_3742_Backup");
}

[Theory]
[PropertyData("Storages")]
public void file_system_backup_operation_sucessfully_waits_for_backup_to_complete(string requestedStorage)
{
using (var store = NewStore(runInMemory: false, requestedStorage: "esent"))
{
using (var operation = new FilesystemBackupOperation(new BackupParameters
{
BackupPath = BackupDir,
ServerUrl = store.Url,
Filesystem = store.DefaultFileSystem
}))
{

Assert.True(operation.InitBackup());
Assert.DoesNotThrow(() => operation.WaitForBackup());
}
}
}
}
}
5 changes: 5 additions & 0 deletions Raven.Tests.FileSystem/Raven.Tests.FileSystem.csproj
Expand Up @@ -139,6 +139,7 @@
<Compile Include="Issues\RavenDB_3268_ConcurrencyChecks.cs" />
<Compile Include="Issues\RavenDB_3499.cs" />
<Compile Include="Issues\RavenDB_3692.cs" />
<Compile Include="Issues\RavenDB_3742.cs" />
<Compile Include="Migration\MigrationTests.cs" />
<Compile Include="Synchronization\FailoverReadFromAllServers.cs" />
<Compile Include="Synchronization\RavenSynchronizationTestBase.cs" />
Expand Down Expand Up @@ -215,6 +216,10 @@
<Project>{41AC479E-1EB2-4D23-AAF2-E4C8DF1BC2BA}</Project>
<Name>Raven.Abstractions</Name>
</ProjectReference>
<ProjectReference Include="..\Raven.Backup\Raven.Backup.csproj">
<Project>{DBB6561C-6264-430D-8F3C-E11C6268981E}</Project>
<Name>Raven.Backup</Name>
</ProjectReference>
<ProjectReference Include="..\Raven.Client.Lightweight\Raven.Client.Lightweight.csproj">
<Project>{4e087ecb-e7ca-4891-ac3c-3c76702715b6}</Project>
<Name>Raven.Client.Lightweight</Name>
Expand Down

0 comments on commit b7767d6

Please sign in to comment.