forked from ravendb/ravendb
-
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.
RavenDB-22953 Fixing sorting edge case in Corax where all matches hav…
…e been found already so there is no need to fallback to normal sorting (which expected to get non empty batch of results)
- Loading branch information
1 parent
316ab31
commit a9e1cbb
Showing
2 changed files
with
129 additions
and
4 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
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,121 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using FastTests; | ||
using Raven.Client.Documents.Indexes; | ||
using Tests.Infrastructure; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SlowTests.Corax; | ||
|
||
public class RavenDB_22953 : RavenTestBase | ||
{ | ||
public RavenDB_22953(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[RavenTheory(RavenTestCategory.Corax)] | ||
[RavenData(SearchEngineMode = RavenSearchEngineMode.Corax)] | ||
public void StreamingQueryMustNotThrowIndexOutOfRangeException(Options options) | ||
{ | ||
using (var store = GetDocumentStore(options)) | ||
{ | ||
var timestamps = new[] | ||
{ | ||
new DateTimeOffset(new DateTime(2024, 9, 2), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 3), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 5), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 12), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 13), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 15), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 17), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 20), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 21), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 22), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 22), TimeSpan.Zero), | ||
new DateTimeOffset(new DateTime(2024, 9, 27), TimeSpan.Zero), | ||
}; | ||
|
||
using (var bulk = store.BulkInsert()) | ||
{ | ||
for (int i = 0; i < 10000; i++) | ||
{ | ||
bulk.Store(new Entry | ||
{ | ||
Timestamp = timestamps[i % timestamps.Length], | ||
Schema = "foo", | ||
Name = "bar" | ||
}); | ||
} | ||
} | ||
|
||
using (var bulk = store.BulkInsert()) | ||
{ | ||
for (int i = 0; i < 11000; i++) | ||
{ | ||
bulk.Store(new Entry | ||
{ | ||
Timestamp = timestamps[i % timestamps.Length], | ||
Schema = "zzz", | ||
Name = "bar" | ||
}); | ||
} | ||
} | ||
|
||
new Entries_ByTimestampAndQualifiedName().Execute(store); | ||
|
||
Indexes.WaitForIndexing(store); | ||
|
||
using (var session = store.OpenSession()) | ||
{ | ||
var count = 0; | ||
|
||
var q = session.Advanced.DocumentQuery<Entries_ByTimestampAndQualifiedName.IndexEntry, Entries_ByTimestampAndQualifiedName>() | ||
.WhereGreaterThanOrEqual(x => x.Timestamp, new DateTimeOffset(new DateTime(2024, 9, 2), TimeSpan.Zero)) | ||
.WhereLessThanOrEqual(x => x.Timestamp, new DateTimeOffset(new DateTime(2024, 9, 27), TimeSpan.Zero)) | ||
.WhereIn(x => x.QualifiedName, new[] { "foo:bar" }) | ||
.OrderBy(x => x.Timestamp); | ||
|
||
var s = session.Advanced.Stream(q); | ||
|
||
while (s.MoveNext()) | ||
{ | ||
count++; | ||
} | ||
|
||
Assert.Equal(10000, count); | ||
} | ||
} | ||
} | ||
|
||
private class Entry | ||
{ | ||
public DateTimeOffset? Timestamp { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public string Schema { get; set; } | ||
} | ||
|
||
private class Entries_ByTimestampAndQualifiedName : AbstractIndexCreationTask<Entry> | ||
{ | ||
public class IndexEntry | ||
{ | ||
public DateTimeOffset Timestamp { get; set; } | ||
|
||
public string QualifiedName { get; set; } | ||
} | ||
|
||
public Entries_ByTimestampAndQualifiedName() | ||
{ | ||
Map = entries => from entry in entries | ||
select new IndexEntry | ||
{ | ||
Timestamp = entry.Timestamp ?? | ||
default(DateTimeOffset), | ||
QualifiedName = string.Format("{0}:{1}", entry.Schema, entry.Name), | ||
}; | ||
} | ||
} | ||
} |