Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked api to be more in line with native lib #125

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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