Skip to content

Commit

Permalink
Reworked cursor api to be more in line with native lib
Browse files Browse the repository at this point in the history
Added Span<byte> overloads for cursor methods
Added more test coverage
  • Loading branch information
CoreyKaylor committed Jul 18, 2020
1 parent 46432b4 commit 4f3d0dd
Show file tree
Hide file tree
Showing 18 changed files with 668 additions and 585 deletions.
391 changes: 231 additions & 160 deletions src/LightningDB.Tests/CursorTests.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/LightningDB.Tests/DatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void NamedDatabaseNameExistsInMaster()
using (var cursor = tx.CreateCursor(db))
{
cursor.MoveNext();
Assert.Equal("customdb", UTF8.GetString(cursor.Current.Key.CopyToNewArray()));
Assert.Equal("customdb", UTF8.GetString(cursor.GetCurrent().key.CopyToNewArray()));
}
}
}
Expand Down
38 changes: 0 additions & 38 deletions src/LightningDB.Tests/HelperTests.cs

This file was deleted.

58 changes: 0 additions & 58 deletions src/LightningDB.Tests/ProfilingTests.cs

This file was deleted.

13 changes: 12 additions & 1 deletion src/LightningDB.Tests/TestHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Collections.Generic;

namespace LightningDB.Tests
Expand Down Expand Up @@ -46,5 +47,15 @@ public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> list, int
.GroupBy(x => x.Index / parts)
.Select(x => x.Select(v => v.Value));
}

public static void RunCursorScenario(this LightningEnvironment env,
Action<LightningTransaction, LightningDatabase, LightningCursor> scenario,
DatabaseOpenFlags flags = DatabaseOpenFlags.Create, TransactionBeginFlags transactionFlags = TransactionBeginFlags.None)
{
using var tx = env.BeginTransaction(transactionFlags);
using var db = tx.OpenDatabase(configuration: new DatabaseConfiguration { Flags = flags });
using var cursor = tx.CreateCursor(db);
scenario(tx, db, cursor);
}
}
}
11 changes: 5 additions & 6 deletions src/LightningDB.Tests/TransactionTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using LightningDB.Native;
using Xunit;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -53,7 +52,7 @@ public void CanCountTransactionEntries()
}


[Collection("SharedFileSystem")]
[Collection("SharedFileSystem")]
public class TransactionTests : IDisposable
{
private LightningEnvironment _env;
Expand Down Expand Up @@ -216,8 +215,8 @@ public void TransactionShouldSupportCustomComparer()
using (var c = txn.CreateCursor(db))
{
int order = 0;
while (c.MoveNext())
Assert.Equal(keysSorted[order++], BitConverter.ToInt32(c.Current.Key.CopyToNewArray(), 0));
while (c.MoveNext() == MDBResultCode.Success)
Assert.Equal(keysSorted[order++], BitConverter.ToInt32(c.GetCurrent().key.CopyToNewArray(), 0));
}
}

Expand All @@ -243,8 +242,8 @@ public void TransactionShouldSupportCustomDupSorter()
{
int order = 0;

while (c.MoveNext())
Assert.Equal(valuesSorted[order++], BitConverter.ToInt32(c.Current.Value.CopyToNewArray(), 0));
while (c.MoveNext() == MDBResultCode.Success)
Assert.Equal(valuesSorted[order++], BitConverter.ToInt32(c.GetCurrent().value.CopyToNewArray(), 0));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/LightningDB/CursorOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ public enum CursorOperation
/// <summary>
/// Position at first key greater than or equal to specified key.
/// </summary>
SetRange
SetRange,
}
}
4 changes: 2 additions & 2 deletions src/LightningDB/GetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum GetResultCode

/// <summary>
/// Failure. The requested key was found, but the provided buffer was
/// too small to contain the full value. No data has been retrived.
/// too small to contain the full value. No data has been retrieved.
/// The Get operation should be retried with a buffer at least the
/// length represented in GetResult.Length
/// <para>
Expand All @@ -58,7 +58,7 @@ public enum GetResultCode

/// <summary>
/// Failure. The requested key was not found in the database. No data has
/// been retrived.
/// been retrieved.
/// <para>
/// GetResult.Length has no meaning for this result. It's value
/// is set to zero.
Expand Down
17 changes: 0 additions & 17 deletions src/LightningDB/HelperExtensions.cs

This file was deleted.

Loading

0 comments on commit 4f3d0dd

Please sign in to comment.