Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adding test
- Loading branch information
Showing
6 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
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,10 @@ | ||
using System; | ||
|
||
namespace Raven.Tests.MailingList.RobStats { | ||
public class Entity { | ||
public string Id { get; set; } | ||
public string DisplayName { get; set; } | ||
public string Visibility { get; set; } | ||
public DateTimeOffset UpdatedAt { get; set; } | ||
} | ||
} |
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,6 @@ | ||
namespace Raven.Tests.MailingList.RobStats { | ||
public class Opinion { | ||
public string EntityId { get; set; } | ||
public bool IsFavorite { get; set; } | ||
} | ||
} |
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,76 @@ | ||
// //----------------------------------------------------------------------- | ||
// // <copyright company="Hibernating Rhinos LTD"> | ||
// // Copyright (c) Hibernating Rhinos LTD. All rights reserved. | ||
// // </copyright> | ||
// //----------------------------------------------------------------------- | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Raven.Client.Document; | ||
using Raven.Client.Indexes; | ||
using Raven.Client.Linq; | ||
using Xunit; | ||
|
||
namespace Raven.Tests.MailingList.RobStats | ||
{ | ||
public class StatisticsBug : RavenTest | ||
{ | ||
[Fact] | ||
public void Should_get_stats_whe_using_lazy() | ||
{ | ||
using (GetNewServer()) | ||
using (var store = new DocumentStore | ||
{ | ||
Url = "http://localhost:8080" | ||
}.Initialize()) | ||
{ | ||
new TheIndex().Execute(store); | ||
using (var session = store.OpenSession()) | ||
{ | ||
for (var i = 0; i < 15; i++) | ||
{ | ||
var entity = new Entity | ||
{ | ||
DisplayName = "Entity " + i, | ||
UpdatedAt = DateTimeOffset.Now, | ||
Visibility = "Visible" | ||
}; | ||
|
||
session.Store(entity); | ||
|
||
var opinion = new Opinion | ||
{ | ||
EntityId = entity.Id, | ||
IsFavorite = i%2 == 0 | ||
}; | ||
|
||
session.Store(opinion); | ||
} | ||
|
||
session.SaveChanges(); | ||
} | ||
|
||
using (var session = store.OpenSession()) | ||
{ | ||
RavenQueryStatistics stats; | ||
var query = session.Query<Summary, TheIndex>() | ||
.Customize(x => x.WaitForNonStaleResults()) | ||
.Statistics(out stats) | ||
.Where(x => x.Visibility == "Visible") | ||
.OrderByDescending(x => x.UpdatedAt); | ||
|
||
var pagedQuery = query | ||
.Skip(0) | ||
.Take(10) | ||
.Lazily(); | ||
|
||
|
||
var items = pagedQuery.Value.ToArray(); | ||
Assert.Equal(15, stats.TotalResults); | ||
Assert.Equal(10, items.Length); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
|
||
namespace Raven.Tests.MailingList.RobStats { | ||
public class Summary { | ||
public string EntityId { get; set; } | ||
public string DisplayName { get; set; } | ||
public string Visibility { get; set; } | ||
public DateTimeOffset UpdatedAt { get; set; } | ||
public int NumberOfFavorites { get; set; } | ||
} | ||
} |
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,40 @@ | ||
using System; | ||
using System.Linq; | ||
using Raven.Client.Indexes; | ||
|
||
namespace Raven.Tests.MailingList.RobStats { | ||
class TheIndex : AbstractMultiMapIndexCreationTask<Summary> { | ||
public TheIndex() { | ||
AddMap<Opinion>( | ||
opinions => from opinion in opinions | ||
select new { | ||
opinion.EntityId, | ||
DisplayName = (string)null, | ||
Visibility = (string)null, | ||
UpdatedAt = DateTimeOffset.MinValue, | ||
NumberOfFavorites = opinion.IsFavorite ? 1 : 0, | ||
}); | ||
|
||
AddMap<Entity>( | ||
entities => from entity in entities | ||
select new { | ||
EntityId = entity.Id, | ||
entity.DisplayName, | ||
entity.Visibility, | ||
entity.UpdatedAt, | ||
NumberOfFavorites = 0, | ||
}); | ||
|
||
Reduce = results => from result in results | ||
group result by result.EntityId | ||
into g | ||
select new { | ||
EntityId = g.Key, | ||
DisplayName = g.Select(x => x.DisplayName).Where(x => x != null).FirstOrDefault(), | ||
Visibility = g.Select(x => x.Visibility).Where(x => x != null).FirstOrDefault(), | ||
UpdatedAt = g.Max(x => (DateTimeOffset)x.UpdatedAt), | ||
NumberOfFavorites = g.Sum(x => x.NumberOfFavorites), | ||
}; | ||
} | ||
} | ||
} |
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