forked from ravendb/ravendb.contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paging expands the session request limit
- Loading branch information
1 parent
bc3f8db
commit 0453ab7
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Raven.Client.Contrib.Tests/ExtensionTests/PagingExtensionTests.cs
This file contains 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,46 @@ | ||
using System.Linq; | ||
using Raven.Client.Contrib.Extensions; | ||
using Raven.Client.Contrib.Tests.TestEntities; | ||
using Raven.Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace Raven.Client.Contrib.Tests.ExtensionTests | ||
{ | ||
public class PagingExtensionTests : RavenTestBase | ||
{ | ||
[Fact] | ||
public void GetAllResultsWithPaging_Expands_Request_Limit() | ||
{ | ||
using (var documentStore = NewDocumentStore()) | ||
{ | ||
using (var session = documentStore.OpenSession()) | ||
{ | ||
for (int i = 0; i < 1000; i++) | ||
session.Store(Ball.Random); | ||
|
||
session.SaveChanges(); | ||
} | ||
|
||
using (var session = documentStore.OpenSession()) | ||
{ | ||
var originalLimit = session.Advanced.MaxNumberOfRequestsPerSession; | ||
|
||
var allBalls = session.Query<Ball>() | ||
.Customize(x => x.WaitForNonStaleResults()) | ||
.GetAllResultsWithPaging(pageSize: 25) | ||
.ToList(); | ||
|
||
Assert.Equal(1000, allBalls.Count); | ||
|
||
// 1000 items, 25 per page = 40 pages, which exceeds the default 30 request max. | ||
|
||
// The above query should have only taken one away from the limit, regardless of how many pages there were. | ||
// The request limit should have been expanded to account for this. | ||
var newLimit = session.Advanced.MaxNumberOfRequestsPerSession; | ||
var numRequests = session.Advanced.NumberOfRequests; | ||
Assert.Equal(originalLimit + numRequests - 1, newLimit); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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,26 @@ | ||
using System; | ||
|
||
namespace Raven.Client.Contrib.Tests.TestEntities | ||
{ | ||
public class Ball | ||
{ | ||
public string Id { get; set; } | ||
public string Color { get; set; } | ||
|
||
public static string[] Colors = new[] | ||
{ | ||
"red", "orange", "yellow", "green", "blue", "indigo", | ||
"violet", "brown", "black", "white", "silver", "gold" | ||
}; | ||
|
||
private static readonly Random RandomNumber = new Random(); | ||
public static Ball Random | ||
{ | ||
get | ||
{ | ||
var color = Colors[RandomNumber.Next(Colors.Length)]; | ||
return new Ball { Color = color }; | ||
} | ||
} | ||
} | ||
} |
This file contains 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