Skip to content

Commit

Permalink
Fixing an issue with raven documents not being exported
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Sep 11, 2010
1 parent 0c367f5 commit 9993235
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Raven.Database/DocumentDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,10 @@ public JArray GetDocuments(int start, int pageSize, Guid? etag)
var documentRetriever = new DocumentRetriever(actions, ReadTriggers);
foreach (var doc in documents.Take(pageSize))
{
var document = documentRetriever.ExecuteReadTriggers(doc, null, ReadOperation.Query);
var document = documentRetriever.ExecuteReadTriggers(doc, null,
// here we want to have the Load semantic, not Query, because we need this to be
// as close as possible to the full database contents
ReadOperation.Load);
if (document == null)
continue;
if (document.Metadata.Property("@id") == null)
Expand Down
2 changes: 1 addition & 1 deletion Raven.Smuggler/Smuggler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Optional arguments (after required arguments):
}
}

private static void ExportData(string instanceUrl, string file, bool exportIndexesOnly)
public static void ExportData(string instanceUrl, string file, bool exportIndexesOnly)
{
using (var streamWriter = new StreamWriter(new GZipStream(File.Create(file), CompressionMode.Compress)))
{
Expand Down
90 changes: 90 additions & 0 deletions Raven.Tests/Bugs/HiLoServerKeysNotExported.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;
using Raven.Client.Document;
using Raven.Client.Indexes;
using Raven.Database;
using Raven.Server;
using Xunit;

namespace Raven.Tests.Bugs
{
public class HiLoServerKeysNotExported : IDisposable
{
private DocumentStore documentStore;
private RavenDbServer server;

public HiLoServerKeysNotExported()
{
CreateServer(true);


}

private void CreateServer(bool initDocStore = false)
{
if (Directory.Exists("HiLoData")) Directory.Delete("HiLoData", true);
server = new RavenDbServer(new RavenConfiguration { Port = 8080, DataDirectory = "HiLoData", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true });

if (initDocStore) {
documentStore = new DocumentStore() { Url = "http://localhost:8080/" };
documentStore.Initialize();
}
}

[Fact]
public void Export_And_Import_Retains_HiLoState()
{
using (var session = documentStore.OpenSession()) {
var foo = new Foo() { Something = "something2" };
Assert.Null(foo.Id);
session.Store(foo);
Assert.NotNull(foo.Id);
session.SaveChanges();
}

if (File.Exists("hilo-export.dump"))
File.Delete("hilo-export.dump");
Smuggler.Smuggler.ExportData("http://localhost:8080/", "hilo-export.dump", false);
Assert.True(File.Exists("hilo-export.dump"));

using (var session = documentStore.OpenSession()) {
var hilo = session.Load<HiLoKey>("Raven/Hilo/foos");
Assert.NotNull(hilo);
Assert.Equal(2, hilo.ServerHi);
}

server.Dispose();
CreateServer();

Smuggler.Smuggler.ImportData("http://localhost:8080/", "hilo-export.dump");

using (var session = documentStore.OpenSession()) {
var hilo = session.Load<HiLoKey>("Raven/Hilo/foos");
Assert.NotNull(hilo);
Assert.Equal(2, hilo.ServerHi);
}
}

public class Foo
{
public string Id { get; set; }
public string Something { get; set; }
}

private class HiLoKey
{
public long ServerHi { get; set; }

}

public void Dispose()
{
documentStore.Dispose();
server.Dispose();
if (Directory.Exists("HiLoData")) Directory.Delete("HiLoData", true);
}

}
}
1 change: 1 addition & 0 deletions Raven.Tests/Raven.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bugs\HierarchicalData.cs" />
<Compile Include="Bugs\HiLoServerKeysNotExported.cs" />
<Compile Include="Bugs\IndexingBehavior.cs" />
<Compile Include="Bugs\OverwriteDocuments.cs" />
<Compile Include="Bugs\ReadDataFromServer.cs" />
Expand Down

0 comments on commit 9993235

Please sign in to comment.