Skip to content

Commit

Permalink
Rename Bookmark to Bookmarks. (#609)
Browse files Browse the repository at this point in the history
* add + operator to Bookmark/Bookmarks and introduce LastBookmarks
* rename bookmark bookmarks internally
* use bookmarks in testkit backend
* add test
  • Loading branch information
thelonelyvulpes committed May 9, 2022
1 parent 1d5d279 commit 7573d93
Show file tree
Hide file tree
Showing 90 changed files with 609 additions and 520 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Neo4j dotnet Driver Change Log


## Version 5.0
- Change Transaction config timeout to accept null, Timeout.Zero explicitly.
- Zero removes timout.
- null uses server default timeout.
- null uses server default timeout.
- Change Bookmark to Bookmarks.
- replace all uses with pluralized Bookmarks.
10 changes: 9 additions & 1 deletion Neo4j.Driver/Neo4j.Driver.Reactive/IRxSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ public interface IRxSession : IRxRunnable
///
/// If no bookmark was received or if this transaction was rolled back, the bookmark value will not be changed.
/// </summary>
[Obsolete("Replaced with LastBookmarks. Will be removed in 6.0.")]
Bookmark LastBookmark { get; }

/// <summary>
/// Returns the bookmark received following the last successfully completed query, which is executed
/// either in an <see cref="IRxTransaction"/> obtained from this session instance or directly through one of
/// the <strong>Run</strong> overrides of this session instance.
///
/// If no bookmark was received or if this transaction was rolled back, the bookmark value will not be changed.
/// </summary>
Bookmarks LastBookmarks { get; }
/// <summary>
/// Begin a new <strong>explicit</strong> <see cref="IRxTransaction"/>.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public InternalRxSession(IInternalAsyncSession session, IRxRetryLogic retryLogic
}

public Bookmark LastBookmark => _session.LastBookmark;
public Bookmarks LastBookmarks => _session.LastBookmarks;

public SessionConfig SessionConfig => _session.SessionConfig;

#region Run Methods
Expand Down
2 changes: 1 addition & 1 deletion Neo4j.Driver/Neo4j.Driver.Simple/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface ISession : IQueryRunner
/// Gets the bookmark received following the last successfully completed <see cref="IAsyncTransaction"/>.
/// If no bookmark was received or if this transaction was rolled back, the bookmark value will not be changed.
/// </summary>
Bookmark LastBookmark { get; }
Bookmarks LastBookmarks { get; }


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public InternalSession(IInternalAsyncSession session, IRetryLogic retryLogic, Bl
}

public Bookmark LastBookmark => _session.LastBookmark;
public Bookmarks LastBookmarks => _session.LastBookmarks;
public SessionConfig SessionConfig => _session.SessionConfig;

public IResult Run(string Query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ private static async Task CreateNodeInTx(IAsyncSession session, int id)
}
}

private static async Task<int> CountNodeInTx(IDriver driver, int id, Bookmark bookmark = null)
private static async Task<int> CountNodeInTx(IDriver driver, int id, Bookmarks bookmarks = null)
{
var session = driver.AsyncSession(o => o.WithBookmarks(bookmark));
var session = driver.AsyncSession(o => o.WithBookmarks(bookmarks));
try
{
var tx = await session.BeginTransactionAsync();
Expand Down
6 changes: 3 additions & 3 deletions Neo4j.Driver/Neo4j.Driver.Tests.Integration/Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ private int PrintFriendships(ITransaction tx)
public void AddEmployAndMakeFriends()
{
// To collect the session bookmarks
var savedBookmarks = new List<Bookmark>();
var savedBookmarks = new List<Bookmarks>();

// Create the first person and employment relationship.
using (var session1 = Driver.Session(o => o.WithDefaultAccessMode(AccessMode.Write)))
Expand All @@ -990,7 +990,7 @@ public void AddEmployAndMakeFriends()
session1.WriteTransaction(tx => AddPerson(tx, "Alice"));
session1.WriteTransaction(tx => Employ(tx, "Alice", "Wayne Enterprises"));

savedBookmarks.Add(session1.LastBookmark);
savedBookmarks.Add(session1.LastBookmarks);
}

// Create the second person and employment relationship.
Expand All @@ -1000,7 +1000,7 @@ public void AddEmployAndMakeFriends()
session2.WriteTransaction(tx => AddPerson(tx, "Bob"));
session2.WriteTransaction(tx => Employ(tx, "Bob", "LexCorp"));

savedBookmarks.Add(session2.LastBookmark);
savedBookmarks.Add(session2.LastBookmarks);
}

// Create a friendship between the two people created above.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public TransactionIT(ITestOutputHelper output, StandAloneIntegrationTestFixture
[RequireServerFact("4.0.0", GreaterThanOrEqualTo)]
public void ShouldCommitEmptyTx()
{
var bookmarkBefore = session.LastBookmark;
var bookmarkBefore = session.LastBookmarks;

session.BeginTransaction()
.SelectMany(tx => tx.Commit<int>())
.WaitForCompletion()
.AssertEqual(
OnCompleted<int>(0));

var bookmarkAfter = session.LastBookmark;
var bookmarkAfter = session.LastBookmarks;

bookmarkBefore.Should().BeNull();
bookmarkAfter.Should().NotBe(bookmarkBefore);
Expand All @@ -71,15 +71,15 @@ public void ShouldCommitEmptyTx()
[RequireServerFact("4.0.0", GreaterThanOrEqualTo)]
public void ShouldRollbackEmptyTx()
{
var bookmarkBefore = session.LastBookmark;
var bookmarkBefore = session.LastBookmarks;

session.BeginTransaction()
.SelectMany(tx => tx.Rollback<int>())
.WaitForCompletion()
.AssertEqual(
OnCompleted<int>(0));

var bookmarkAfter = session.LastBookmark;
var bookmarkAfter = session.LastBookmarks;

bookmarkBefore.Should().BeNull();
bookmarkAfter.Should().Be(bookmarkBefore);
Expand Down Expand Up @@ -277,7 +277,7 @@ public void ShouldFailToBeginTxcWithInvalidBookmark()
{
Server.Driver
.RxSession(
o => o.WithDefaultAccessMode(AccessMode.Read).WithBookmarks(Bookmark.From("InvalidBookmark")))
o => o.WithDefaultAccessMode(AccessMode.Read).WithBookmarks(Bookmarks.From("InvalidBookmark")))
.BeginTransaction()
.WaitForCompletion()
.AssertEqual(
Expand Down Expand Up @@ -385,19 +385,19 @@ private async Task VerifyFailToRunQueryAfterCompletedTxc(bool commit)
[RequireServerFact("4.0.0", GreaterThanOrEqualTo)]
public async Task ShouldUpdateBookmark()
{
var bookmark1 = session.LastBookmark;
var bookmark1 = session.LastBookmarks;

var txc1 = await session.BeginTransaction().SingleAsync();
VerifyCanCreateNode(txc1, 20);
VerifyCanCommit(txc1);

var bookmark2 = session.LastBookmark;
var bookmark2 = session.LastBookmarks;

var txc2 = await session.BeginTransaction().SingleAsync();
VerifyCanCreateNode(txc2, 20);
VerifyCanCommit(txc2);

var bookmark3 = session.LastBookmark;
var bookmark3 = session.LastBookmarks;

bookmark1.Should().BeNull();
bookmark2.Should().NotBe(bookmark1);
Expand Down
18 changes: 9 additions & 9 deletions Neo4j.Driver/Neo4j.Driver.Tests.Integration/Routing/BoltV4IT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ public async Task ShouldReturnDatabaseInfoForDatabaseInAutoCommit()
{
string dbname = "foo";
var session = _driver.AsyncSession(ForDatabase("system"));
Bookmark bookmark;
Bookmarks bookmarks;

try
{

await session.RunAsync(new Query($"CREATE DATABASE { dbname }"));
bookmark = session.LastBookmark;
bookmarks = session.LastBookmarks;
}
finally
{
Expand All @@ -93,7 +93,7 @@ public async Task ShouldReturnDatabaseInfoForDatabaseInAutoCommit()
o.WithDatabase(dbname);
}
o.WithBookmarks(bookmark ?? Bookmark.Empty);
o.WithBookmarks(bookmarks ?? Bookmarks.Empty);
});

try
Expand Down Expand Up @@ -123,7 +123,7 @@ public void ShouldThrowWhenDatabaseIsSpecifiedInTxFunc()
.WithMessage("*to a server that does not support multiple databases.*");
}

private async Task VerifyDatabaseNameOnSummaryTxFunc(string name, string expected, Bookmark bookmark = null)
private async Task VerifyDatabaseNameOnSummaryTxFunc(string name, string expected, Bookmarks bookmarks = null)
{
var session = _driver.AsyncSession(o =>
{
Expand All @@ -132,7 +132,7 @@ private async Task VerifyDatabaseNameOnSummaryTxFunc(string name, string expecte
o.WithDatabase(name);
}
o.WithBookmarks(bookmark ?? Bookmark.Empty);
o.WithBookmarks(bookmarks ?? Bookmarks.Empty);
});

try
Expand All @@ -148,23 +148,23 @@ private async Task VerifyDatabaseNameOnSummaryTxFunc(string name, string expecte
}
}

private static async Task<Bookmark> CreateDatabase(IDriver driver, string name)
private static async Task<Bookmarks> CreateDatabase(IDriver driver, string name)
{
var session = driver.AsyncSession(ForDatabase("system"));
try
{
await session.WriteTransactionAsync(async txc => await txc.RunAndConsumeAsync($"CREATE DATABASE {name}"));
return session.LastBookmark;
return session.LastBookmarks;
}
finally
{
await session.CloseAsync();
}
}

private static async Task DropDatabase(IDriver driver, string name, Bookmark bookmark)
private static async Task DropDatabase(IDriver driver, string name, Bookmarks bookmarks)
{
var session = driver.AsyncSession(o => o.WithDatabase("system").WithBookmarks(bookmark));
var session = driver.AsyncSession(o => o.WithDatabase("system").WithBookmarks(bookmarks));
try
{
await session.WriteTransactionAsync(async txc => await txc.RunAndConsumeAsync($"DROP DATABASE {name}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public override async Task ExecuteAsync(TContext context)
var cursor = await session.RunAsync("CREATE ()");
summary = await cursor.ConsumeAsync();

if (session.LastBookmark != null)
if (session.LastBookmarks != null)
{
context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}
}
catch (Exception exc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override async Task ExecuteAsync(TContext context)
throw;
}

context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}
catch (Exception exc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ await session.WriteTransactionAsync(async tx =>
throw;
}
context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}).ConfigureAwait(false);
}
catch(Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IAsyncSession NewSession(AccessMode mode, TContext context)
{
return _driver.AsyncSession(o =>
o.WithDefaultAccessMode(mode)
.WithBookmarks(_useBookmark ? new[] {context.Bookmark} : Array.Empty<Bookmark>()));
.WithBookmarks(_useBookmark ? new[] {context.Bookmarks} : Array.Empty<Bookmarks>()));
}

public Task<IAsyncTransaction> BeginTransaction(IAsyncSession session, TContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public override void Execute(TContext context)
{
summary = session.Run("CREATE ()").Consume();

if (session.LastBookmark != null)
if (session.LastBookmarks != null)
{
context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Execute(TContext context)
txc.Commit();
}

context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}
}
catch (Exception exc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Execute(TContext context)
return summary;
});

context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}
catch (Exception exc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ISession NewSession(AccessMode mode, TContext context)
{
return _driver.Session(o =>
o.WithDefaultAccessMode(mode)
.WithBookmarks(_useBookmark ? new[] {context.Bookmark} : Array.Empty<Bookmark>()));
.WithBookmarks(_useBookmark ? new[] {context.Bookmarks } : Array.Empty<Bookmarks>()));
}

public ITransaction BeginTransaction(ISession session, TContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public override string ToString()
{
return new StringBuilder()
.Append("CausalClusterContext{")
.AppendFormat("Bookmark={0}, ", Bookmark)
.AppendFormat("Bookmark={0}, ", Bookmarks)
.AppendFormat("BookmarkFailures={0}, ", BookmarkFailures)
.AppendFormat("NodesCreated={0}, ", CreatedNodesCount)
.AppendFormat("NodesRead={0}, ", ReadNodesCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ await session
)
.Finally(() =>
{
if (session.LastBookmark != null)
if (session.LastBookmarks != null)
{
context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}
})
.SingleOrDefaultAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ await BeginTransaction(session, context)
})
.Finally(() =>
{
if (session.LastBookmark != null)
if (session.LastBookmarks != null)
{
context.Bookmark = session.LastBookmark;
context.Bookmarks = session.LastBookmarks;
}
})
).SingleOrDefaultAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public IRxSession NewSession(AccessMode mode, TContext context)
{
return _driver.RxSession(o =>
o.WithDefaultAccessMode(mode)
.WithBookmarks(_useBookmark ? new[] {context.Bookmark} : Array.Empty<Bookmark>()));
.WithBookmarks(_useBookmark ? new[] {context.Bookmarks } : Array.Empty<Bookmarks>()));
}

public IObservable<IRxTransaction> BeginTransaction(IRxSession session, TContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public override string ToString()
{
return new StringBuilder()
.Append("SingleInstanceContext{")
.AppendFormat("Bookmark={0}, ", Bookmark)
.AppendFormat("Bookmark={0}, ", Bookmarks)
.AppendFormat("BookmarkFailures={0}, ", BookmarkFailures)
.AppendFormat("NodesCreated={0}, ", CreatedNodesCount)
.AppendFormat("NodesRead={0}", ReadNodesCount)
Expand Down
Loading

0 comments on commit 7573d93

Please sign in to comment.