-
Notifications
You must be signed in to change notification settings - Fork 934
Added support for the CancelQuery() method in IStatelessSession #3074
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
Merged
fredericDelaporte
merged 18 commits into
nhibernate:master
from
SoftStoneDevelop:master
Sep 27, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2ef030b
Added support for the CancelQuery() method in IStatelessSession (#809)
b2840fd
CancelQuery has been moved from an interface to the StatelessSessionE…
8e97f1d
Added tests for the CancelQuery method(#809)
275fa67
Make tests database agnostic
fredericDelaporte f512fef
Improve the MySql cancelation case
fredericDelaporte dcbff97
Fixed failed test on Oracle.
ddfbde4
Regenerate async code
6b24c04
Merge branch 'master' into master
hazzik 67efb6c
Merge branch 'master' into master
SoftStoneDevelop 590c250
Merge branch 'master' into master
hazzik c894fe6
Merge branch 'master' into master
hazzik 07a6cc6
Merge branch 'master' into master
SoftStoneDevelop 9a1aa68
Merge branch 'master' into master
SoftStoneDevelop 057eff2
Merge branch 'master' into master
SoftStoneDevelop 66fbf1c
Merge branch 'master' into master
SoftStoneDevelop e7e0eff
Merge branch 'master' into master
SoftStoneDevelop cbced3f
Merge branch 'master' into master
SoftStoneDevelop 9ac65b2
Ignore cancel query test under linux for Sql Server and Oracle
fredericDelaporte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
src/NHibernate.Test/Async/Stateless/StatelessSessionCancelQueryFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NHibernate.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Stateless | ||
{ | ||
[TestFixture] | ||
public class StatelessSessionCancelQueryFixtureAsync : TestCase | ||
{ | ||
protected override string MappingsAssembly | ||
{ | ||
get { return "NHibernate.Test"; } | ||
} | ||
|
||
protected override string[] Mappings | ||
{ | ||
get { return new[] { "Stateless.Document.hbm.xml" }; } | ||
} | ||
|
||
private const string _documentName = "SomeDocument"; | ||
private CultureInfo _backupCulture; | ||
private CultureInfo _backupUICulture; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName != CultureInfo.InvariantCulture.TwoLetterISOLanguageName) | ||
{ | ||
// This test needs to run in English | ||
_backupCulture = CultureInfo.CurrentCulture; | ||
_backupUICulture = CultureInfo.CurrentUICulture; | ||
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; | ||
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; | ||
} | ||
|
||
using (var s = Sfi.OpenStatelessSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Insert(new Document("Some text", _documentName)); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = Sfi.OpenStatelessSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.CreateQuery("delete Document").ExecuteUpdate(); | ||
t.Commit(); | ||
} | ||
|
||
if (_backupCulture != null) | ||
{ | ||
CultureInfo.CurrentCulture = _backupCulture; | ||
CultureInfo.CurrentUICulture = _backupUICulture; | ||
} | ||
} | ||
|
||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return TestDialect.SupportsCancelQuery && | ||
TestDialect.SupportsSelectForUpdate; | ||
} | ||
|
||
private async Task CancelQueryTestAsync(Action<IStatelessSession> queryAction, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
using (var s1 = Sfi.OpenStatelessSession()) | ||
using (var t1 = s1.BeginTransaction()) | ||
{ | ||
await (s1.GetAsync<Document>(_documentName, LockMode.Upgrade, cancellationToken)); | ||
|
||
using (var s2 = Sfi.OpenStatelessSession()) | ||
using (var t2 = s2.BeginTransaction()) | ||
{ | ||
var queryTask = Task.Factory.StartNew(() => queryAction(s2)); | ||
|
||
await (Task.Delay(200, cancellationToken)); | ||
s2.CancelQuery(); | ||
Assert.That(() => queryTask, | ||
Throws.InnerException.TypeOf(typeof(OperationCanceledException)) | ||
.Or.InnerException.Message.Contains("cancel")); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task CancelHqlQueryAsync() | ||
{ | ||
await (CancelQueryTestAsync(s => s.CreateQuery("from Document d").SetLockMode("d", LockMode.Upgrade).List<Document>())); | ||
} | ||
|
||
[Test] | ||
public async Task CancelLinqQueryAsync() | ||
{ | ||
await (CancelQueryTestAsync(s => s.Query<Document>().WithLock(LockMode.Upgrade).ToList())); | ||
} | ||
|
||
[Test] | ||
public async Task CancelQueryOverQueryAsync() | ||
{ | ||
await (CancelQueryTestAsync(s => s.QueryOver<Document>().Lock().Upgrade.List())); | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/NHibernate.Test/Stateless/StatelessSessionCancelQueryFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NHibernate.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Stateless | ||
{ | ||
[TestFixture] | ||
public class StatelessSessionCancelQueryFixture : TestCase | ||
{ | ||
protected override string MappingsAssembly | ||
{ | ||
get { return "NHibernate.Test"; } | ||
} | ||
|
||
protected override string[] Mappings | ||
{ | ||
get { return new[] { "Stateless.Document.hbm.xml" }; } | ||
} | ||
|
||
private const string _documentName = "SomeDocument"; | ||
private CultureInfo _backupCulture; | ||
private CultureInfo _backupUICulture; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName != CultureInfo.InvariantCulture.TwoLetterISOLanguageName) | ||
{ | ||
// This test needs to run in English | ||
_backupCulture = CultureInfo.CurrentCulture; | ||
_backupUICulture = CultureInfo.CurrentUICulture; | ||
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; | ||
CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; | ||
} | ||
|
||
using (var s = Sfi.OpenStatelessSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Insert(new Document("Some text", _documentName)); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = Sfi.OpenStatelessSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.CreateQuery("delete Document").ExecuteUpdate(); | ||
t.Commit(); | ||
} | ||
|
||
if (_backupCulture != null) | ||
{ | ||
CultureInfo.CurrentCulture = _backupCulture; | ||
CultureInfo.CurrentUICulture = _backupUICulture; | ||
} | ||
} | ||
|
||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return TestDialect.SupportsCancelQuery && | ||
TestDialect.SupportsSelectForUpdate; | ||
} | ||
|
||
private void CancelQueryTest(Action<IStatelessSession> queryAction) | ||
{ | ||
using (var s1 = Sfi.OpenStatelessSession()) | ||
using (var t1 = s1.BeginTransaction()) | ||
{ | ||
s1.Get<Document>(_documentName, LockMode.Upgrade); | ||
|
||
using (var s2 = Sfi.OpenStatelessSession()) | ||
using (var t2 = s2.BeginTransaction()) | ||
{ | ||
var queryTask = Task.Factory.StartNew(() => queryAction(s2)); | ||
|
||
Thread.Sleep(200); | ||
s2.CancelQuery(); | ||
Assert.That(() => queryTask, | ||
Throws.InnerException.TypeOf(typeof(OperationCanceledException)) | ||
.Or.InnerException.Message.Contains("cancel")); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void CancelHqlQuery() | ||
{ | ||
CancelQueryTest(s => s.CreateQuery("from Document d").SetLockMode("d", LockMode.Upgrade).List<Document>()); | ||
} | ||
|
||
[Test] | ||
public void CancelLinqQuery() | ||
{ | ||
CancelQueryTest(s => s.Query<Document>().WithLock(LockMode.Upgrade).ToList()); | ||
} | ||
|
||
[Test] | ||
public void CancelQueryOverQuery() | ||
{ | ||
CancelQueryTest(s => s.QueryOver<Document>().Lock().Upgrade.List()); | ||
} | ||
fredericDelaporte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.