Skip to content

Commit 048dcea

Browse files
committed
Add test to check that we use corax by default
1 parent 4a27d32 commit 048dcea

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

src/ServiceControl.Audit.Persistence.RavenDB/DatabaseSetup.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ async Task CreateDatabase(IDocumentStore documentStore, string databaseName, Can
3636
try
3737
{
3838
var databaseRecord = new DatabaseRecord(databaseName);
39-
databaseRecord.Settings.Add("Indexing.Auto.SearchEngineType", configuration.SearchEngineType);
40-
databaseRecord.Settings.Add("Indexing.Static.SearchEngineType", configuration.SearchEngineType);
39+
databaseRecord.Settings.Add(AutoSearchEngineTypeKey, configuration.SearchEngineType);
40+
databaseRecord.Settings.Add(StaticSearchEngineTypeKey, configuration.SearchEngineType);
4141

4242
await documentStore.Maintenance.Server.SendAsync(new CreateDatabaseOperation(databaseRecord), cancellationToken);
4343
}
@@ -95,19 +95,19 @@ async Task UpdateDatabaseSettings(IDocumentStore documentStore, string databaseN
9595
}
9696
}
9797

98-
public static async Task DeleteLegacySagaDetailsIndex(IDocumentStore documentStore, CancellationToken cancellationToken)
98+
internal static async Task DeleteLegacySagaDetailsIndex(IDocumentStore documentStore, CancellationToken cancellationToken)
9999
{
100100
// If the SagaDetailsIndex exists but does not have a .Take(50000), then we remove the current SagaDetailsIndex and
101101
// create a new one. If we do not remove the current one, then RavenDB will attempt to do a side-by-side migration.
102102
// Doing a side-by-side migration results in the index never swapping if there is constant ingestion as RavenDB will wait.
103103
// for the index to not be stale before swapping to the new index. Constant ingestion means the index will never be not-stale.
104104
// This needs to stay in place until the next major version as the user could upgrade from an older version of the current
105105
// Major (v5.x.x) which might still have the incorrect index.
106-
var sagaDetailsIndexOperation = new GetIndexOperation("SagaDetailsIndex");
106+
var sagaDetailsIndexOperation = new GetIndexOperation(SagaDetailsIndexName);
107107
var sagaDetailsIndexDefinition = await documentStore.Maintenance.SendAsync(sagaDetailsIndexOperation, cancellationToken);
108108
if (sagaDetailsIndexDefinition != null && !sagaDetailsIndexDefinition.Reduce.Contains("Take(50000)"))
109109
{
110-
await documentStore.Maintenance.SendAsync(new DeleteIndexOperation("SagaDetailsIndex"), cancellationToken);
110+
await documentStore.Maintenance.SendAsync(new DeleteIndexOperation(SagaDetailsIndexName), cancellationToken);
111111
}
112112
}
113113

@@ -120,12 +120,12 @@ async Task CreateIndexes(IDocumentStore documentStore, CancellationToken cancell
120120
if (configuration.EnableFullTextSearch)
121121
{
122122
indexList.Add(new MessagesViewIndexWithFullTextSearch());
123-
await documentStore.Maintenance.SendAsync(new DeleteIndexOperation("MessagesViewIndex"), cancellationToken);
123+
await documentStore.Maintenance.SendAsync(new DeleteIndexOperation(MessagesViewIndexName), cancellationToken);
124124
}
125125
else
126126
{
127127
indexList.Add(new MessagesViewIndex());
128-
await documentStore.Maintenance.SendAsync(new DeleteIndexOperation("MessagesViewIndexWithFullTextSearch"), cancellationToken);
128+
await documentStore.Maintenance.SendAsync(new DeleteIndexOperation(MessagesViewIndexWithFullTextSearchIndexName), cancellationToken);
129129
}
130130

131131
await IndexCreation.CreateIndexesAsync(indexList, documentStore, null, null, cancellationToken);
@@ -144,5 +144,8 @@ async Task ConfigureExpiration(IDocumentStore documentStore, CancellationToken c
144144

145145
const string AutoSearchEngineTypeKey = "Indexing.Auto.SearchEngineType";
146146
const string StaticSearchEngineTypeKey = "Indexing.Static.SearchEngineType";
147+
internal const string MessagesViewIndexName = "MessagesViewIndex";
148+
internal const string MessagesViewIndexWithFullTextSearchIndexName = "MessagesViewIndexWithFullTextSearch";
149+
internal const string SagaDetailsIndexName = "SagaDetailsIndex";
147150
}
148151
}

src/ServiceControl.Audit.Persistence.Tests.RavenDB/SagaDetailsIndexTests.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using NUnit.Framework;
7+
using Persistence.RavenDB;
78
using Raven.Client.Documents.Indexes;
89
using Raven.Client.Documents.Operations.Indexes;
910
using ServiceControl.SagaAudit;
@@ -14,14 +15,14 @@ class SagaDetailsIndexTests : PersistenceTestFixture
1415
[Test]
1516
public async Task Deletes_index_that_does_not_have_cap_of_50000()
1617
{
17-
await configuration.DocumentStore.Maintenance.SendAsync(new DeleteIndexOperation("SagaDetailsIndex"));
18+
await configuration.DocumentStore.Maintenance.SendAsync(new DeleteIndexOperation(DatabaseSetup.SagaDetailsIndexName));
1819

1920
var indexWithout50000capDefinition = new IndexDefinition
2021
{
21-
Name = "SagaDetailsIndex",
22+
Name = DatabaseSetup.SagaDetailsIndexName,
2223
Maps =
23-
[
24-
@"from doc in docs
24+
[
25+
@"from doc in docs
2526
select new
2627
{
2728
doc.SagaId,
@@ -41,7 +42,7 @@ public async Task Deletes_index_that_does_not_have_cap_of_50000()
4142
}
4243
}
4344
}"
44-
],
45+
],
4546
Reduce = @"from result in results
4647
group result by result.SagaId
4748
into g
@@ -61,12 +62,12 @@ into g
6162

6263
await configuration.DocumentStore.Maintenance.SendAsync(putIndexesOp);
6364

64-
var sagaDetailsIndexOperation = new GetIndexOperation("SagaDetailsIndex");
65+
var sagaDetailsIndexOperation = new GetIndexOperation(DatabaseSetup.SagaDetailsIndexName);
6566
var sagaDetailsIndexDefinition = await configuration.DocumentStore.Maintenance.SendAsync(sagaDetailsIndexOperation);
6667

6768
Assert.That(sagaDetailsIndexDefinition, Is.Not.Null);
6869

69-
await Persistence.RavenDB.DatabaseSetup.DeleteLegacySagaDetailsIndex(configuration.DocumentStore, CancellationToken.None);
70+
await DatabaseSetup.DeleteLegacySagaDetailsIndex(configuration.DocumentStore, CancellationToken.None);
7071

7172
sagaDetailsIndexDefinition = await configuration.DocumentStore.Maintenance.SendAsync(sagaDetailsIndexOperation);
7273

@@ -76,9 +77,9 @@ into g
7677
[Test]
7778
public async Task Does_not_delete_index_that_does_have_cap_of_50000()
7879
{
79-
await Persistence.RavenDB.DatabaseSetup.DeleteLegacySagaDetailsIndex(configuration.DocumentStore, CancellationToken.None);
80+
await DatabaseSetup.DeleteLegacySagaDetailsIndex(configuration.DocumentStore, CancellationToken.None);
8081

81-
var sagaDetailsIndexOperation = new GetIndexOperation("SagaDetailsIndex");
82+
var sagaDetailsIndexOperation = new GetIndexOperation(DatabaseSetup.SagaDetailsIndexName);
8283
var sagaDetailsIndexDefinition = await configuration.DocumentStore.Maintenance.SendAsync(sagaDetailsIndexOperation);
8384

8485
Assert.That(sagaDetailsIndexDefinition, Is.Not.Null);
@@ -100,13 +101,10 @@ await IngestSagaAudits(new SagaSnapshot
100101

101102
await configuration.CompleteDBOperation();
102103

103-
using (var session = configuration.DocumentStore.OpenAsyncSession())
104-
{
105-
var sagaDetailsIndexOperation = new GetIndexOperation("SagaDetailsIndex");
106-
var sagaDetailsIndexDefinition = await configuration.DocumentStore.Maintenance.SendAsync(sagaDetailsIndexOperation);
104+
var sagaDetailsIndexOperation = new GetIndexOperation(DatabaseSetup.SagaDetailsIndexName);
105+
var sagaDetailsIndexDefinition = await configuration.DocumentStore.Maintenance.SendAsync(sagaDetailsIndexOperation);
107106

108-
Assert.That(sagaDetailsIndexDefinition.Reduce, Does.Contain("Take(50000)"), "The SagaDetails index definition does not contain a .Take(50000) to limit the number of saga state changes that are reduced by the map/reduce");
109-
}
107+
Assert.That(sagaDetailsIndexDefinition.Reduce, Does.Contain("Take(50000)"), "The SagaDetails index definition does not contain a .Take(50000) to limit the number of saga state changes that are reduced by the map/reduce");
110108
}
111109

112110
async Task IngestSagaAudits(params SagaSnapshot[] snapshots)
@@ -116,6 +114,7 @@ async Task IngestSagaAudits(params SagaSnapshot[] snapshots)
116114
{
117115
await unitOfWork.RecordSagaSnapshot(snapshot);
118116
}
117+
119118
await unitOfWork.DisposeAsync();
120119
await configuration.CompleteDBOperation();
121120
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace ServiceControl.Audit.Persistence.Tests;
2+
3+
using System.Threading.Tasks;
4+
using NUnit.Framework;
5+
using Persistence.RavenDB;
6+
using Raven.Client.Documents.Indexes;
7+
using Raven.Client.Documents.Operations.Indexes;
8+
9+
[TestFixture]
10+
class SearchEngineTypeTests : PersistenceTestFixture
11+
{
12+
[Test]
13+
public async Task Free_text_search_should_be_on_using_corax_by_default()
14+
{
15+
var index = await configuration.DocumentStore.Maintenance.SendAsync(new GetIndexStatisticsOperation(DatabaseSetup.MessagesViewIndexWithFullTextSearchIndexName));
16+
17+
Assert.That(index, Is.Not.Null);
18+
Assert.That(index.SearchEngineType, Is.EqualTo(SearchEngineType.Corax));
19+
}
20+
}

0 commit comments

Comments
 (0)