Skip to content

Commit

Permalink
bug filesnapshot filename parsing error
Browse files Browse the repository at this point in the history
file snapshots weren't deriving the revision from the file name
  • Loading branch information
rofr committed Apr 30, 2014
1 parent d1f878f commit 06e59f7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
13 changes: 12 additions & 1 deletion src/OrigoDB.Core.UnitTests/SnapshotTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Linq;
using System;
using System.Linq;
using NUnit.Framework;
using OrigoDB.Core.Storage;

namespace OrigoDB.Core.Test
{
Expand All @@ -26,5 +28,14 @@ public void Snapshots_are_numbered_correctly()
Assert.AreEqual(2, store.Snapshots.Count());

}

[Test]
public void Entry_id_is_extracted_from_snapshot_filename()
{
var dt = DateTime.Now;
Snapshot ss = FileSnapshot.FromFileInfo("000467000.snapshot", dt);
Assert.AreEqual(dt,ss.Created);
Assert.AreEqual(467000, ss.LastEntryId);
}
}
}
1 change: 1 addition & 0 deletions src/OrigoDB.Core/OrigoDB.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Compile Include="Proxy\NoProxyAttribute.cs" />
<Compile Include="Proxy\ProxyAttribute.cs" />
<Compile Include="Proxy\QueryAttribute.cs" />
<Compile Include="Storage\FileSnapshot.cs" />
<Compile Include="Storage\StoreExtensions.cs" />
<Compile Include="Transactions\Command[M].cs" />
<Compile Include="Transactions\Command[M,R].cs" />
Expand Down
33 changes: 33 additions & 0 deletions src/OrigoDB.Core/Storage/FileSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Text.RegularExpressions;

namespace OrigoDB.Core.Storage
{
public class FileSnapshot : Snapshot
{
public string Name { get { return ToString(); } }


public FileSnapshot(DateTime created, ulong lastEntryId) : base(created, lastEntryId)
{

}

const string Pattern = @"^(?<entryNr>\d{9}).snapshot$";

readonly private static Regex _parser = new Regex(Pattern);

public static FileSnapshot FromFileInfo(string fileName, DateTime created)
{
Match m = _parser.Match(fileName);
if (!m.Success) throw new ArgumentException("Invalid snapshot filename");
ulong entryNr = m.Groups["entryNr"].Value.ParsePadded();
return new FileSnapshot(created, entryNr);
}

public override string ToString()
{
return String.Format("{0:000000000}.snapshot", LastEntryId);
}
}
}
2 changes: 1 addition & 1 deletion src/OrigoDB.Core/Storage/FileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected override IEnumerable<Snapshot> ReadSnapshotMetaData()
foreach (var file in Directory.GetFiles(_config.Location.OfSnapshots, "*.snapshot"))
{
var fileInfo = new FileInfo(file);
snapshots.Add(FileSnapshot.FromFileInfo(fileInfo));
snapshots.Add(FileSnapshot.FromFileInfo(fileInfo.Name, fileInfo.CreationTime));
}

snapshots.Sort((a, b) => a.LastEntryId.CompareTo(b.LastEntryId));
Expand Down
32 changes: 0 additions & 32 deletions src/OrigoDB.Core/Storage/Snapshot.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Text.RegularExpressions;
using System.IO;

namespace OrigoDB.Core.Storage
{

/// <summary>
///
/// </summary>
public class Snapshot
{

Expand All @@ -29,31 +24,4 @@ public Snapshot(DateTime created, ulong lastEntryId)
LastEntryId = lastEntryId;
}
}

public class FileSnapshot : Snapshot
{
public string Name { get { return ToString(); } }


public FileSnapshot(DateTime created, ulong lastEntryId) : base(created, lastEntryId)
{

}


const string Pattern = @"^(?<lastEntryNr>\d{9}).snapshot$";
private static Regex _parser = new Regex(Pattern);
public static FileSnapshot FromFileInfo(FileInfo fileInfo)
{
Match m = _parser.Match(fileInfo.Name);
if (!m.Success) throw new ArgumentException("Invalid snapshot filename");
ulong entryNr = m.Groups["entryNr"].Value.ParsePadded();
return new FileSnapshot(fileInfo.CreationTime, entryNr);
}

public override string ToString()
{
return String.Format("{0:000000000}.snapshot", LastEntryId);
}
}
}
3 changes: 0 additions & 3 deletions src/OrigoDB.Core/Utilities/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace OrigoDB.Core
{
Expand Down
4 changes: 2 additions & 2 deletions src/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
[assembly: ComVisible(false)]


[assembly: AssemblyVersion("0.12.0")]
[assembly: AssemblyFileVersion("0.12.0")]
[assembly: AssemblyVersion("0.12.1")]
[assembly: AssemblyFileVersion("0.12.1")]

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OrigoDB.Enterprise")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OrigoDB.Core.Test")]
Expand Down

0 comments on commit 06e59f7

Please sign in to comment.