Skip to content

Commit

Permalink
Merge pull request #125 from CoreyKaylor/cursor-api-changes
Browse files Browse the repository at this point in the history
Reworked api to be more in line with native lib, exposed 0-copy read options.
  • Loading branch information
CoreyKaylor authored Jul 30, 2020
2 parents 46432b4 + 14cbb67 commit b6db0b4
Show file tree
Hide file tree
Showing 22 changed files with 975 additions and 979 deletions.
432 changes: 273 additions & 159 deletions src/LightningDB.Tests/CursorTests.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/LightningDB.Tests/DatabaseIOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void DatabaseGetShouldNotThrowExceptions()
}

[Fact]
public void DatabaseInsertedValueShouldBeRetrivedThen()
public void DatabaseInsertedValueShouldBeRetrievedThen()
{
var key = "key";
var value = "value";
Expand Down
6 changes: 3 additions & 3 deletions src/LightningDB.Tests/DatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void NamedDatabaseNameExistsInMaster()
var db = tx.OpenDatabase();
using (var cursor = tx.CreateCursor(db))
{
cursor.MoveNext();
Assert.Equal("customdb", UTF8.GetString(cursor.Current.Key.CopyToNewArray()));
cursor.Next();
Assert.Equal("customdb", UTF8.GetString(cursor.GetCurrent().key.CopyToNewArray()));
}
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public void TruncatingTheDatabase()
db = _txn.OpenDatabase();
var result = _txn.Get(db, UTF8.GetBytes("hello"));

Assert.Null(result);
Assert.Equal(MDBResultCode.NotFound, result.resultCode);
}
}
}
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.

28 changes: 24 additions & 4 deletions src/LightningDB.Tests/TestHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using System.Linq;
using System;
using System.Linq;
using System.Collections.Generic;

namespace LightningDB.Tests
{
public static class TestHelperExtensions
{
public static void Put(this LightningTransaction tx, LightningDatabase db, string key, string value)
public static MDBResultCode Put(this LightningTransaction tx, LightningDatabase db, string key, string value)
{
var enc = System.Text.Encoding.UTF8;
tx.Put(db, enc.GetBytes(key), enc.GetBytes(value));
return tx.Put(db, enc.GetBytes(key), enc.GetBytes(value));
}

public static string Get(this LightningTransaction tx, LightningDatabase db, string key)
{
var enc = System.Text.Encoding.UTF8;
var result = tx.Get(db, enc.GetBytes(key));
return enc.GetString(result);
return enc.GetString(result.value.CopyToNewArray());
}

public static void Delete(this LightningTransaction tx, LightningDatabase db, string key)
Expand Down Expand Up @@ -46,5 +47,24 @@ 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);
}

public static void RunTransactionScenario(this LightningEnvironment env,
Action<LightningTransaction, LightningDatabase> 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 });
scenario(tx, db);
}
}
}
Loading

0 comments on commit b6db0b4

Please sign in to comment.