Skip to content

Commit 111d718

Browse files
committed
Render index definitions with the conventions the instances deploy with
1 parent 830ec9c commit 111d718

7 files changed

Lines changed: 25 additions & 23 deletions

File tree

‎src/ServiceControl.Audit.Persistence.RavenDB/RavenExternalPersistenceLifecycle.cs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace ServiceControl.Audit.Persistence.RavenDB
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Raven.Client.Documents;
9-
using Raven.Client.Documents.Conventions;
109
using ServiceControl.RavenDB;
1110

1211
sealed class RavenExternalPersistenceLifecycle(DatabaseConfiguration configuration) : IRavenPersistenceLifecycle, IRavenDocumentStoreProvider, IDisposable
@@ -40,10 +39,7 @@ public async Task Initialize(CancellationToken cancellationToken = default)
4039
Database = configuration.Name,
4140
Urls = [configuration.ServerConfiguration.ConnectionString],
4241
Certificate = RavenClientCertificate.FindClientCertificate(configuration.ServerConfiguration),
43-
Conventions = new DocumentConventions
44-
{
45-
SaveEnumsAsIntegers = true
46-
}
42+
Conventions = DocumentStoreConventions.Create()
4743
};
4844

4945
documentStore = store.Initialize();

‎src/ServiceControl.Audit.Persistence.Tests.RavenDB/ApprovalFiles/IndexDefinitionApprovals.Verify_index_definitions_are_unchanged.approved.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MessagesViewIndex
1010
MessageId = ((string) message.MessageMetadata["MessageId"]),
1111
MessageType = ((string) message.MessageMetadata["MessageType"]),
1212
IsSystemMessage = ((bool) message.MessageMetadata["IsSystemMessage"]),
13-
Status = ((bool) message.MessageMetadata["IsRetried"]) ? "ResolvedSuccessfully" : "Successful",
13+
Status = ((bool) message.MessageMetadata["IsRetried"]) ? 4 : 3,
1414
TimeSent = ((DateTime) message.MessageMetadata["TimeSent"]),
1515
ProcessedAt = message.ProcessedAt,
1616
ReceivingEndpointName = ((message.MessageMetadata["ReceivingEndpoint"])).Name,
@@ -32,7 +32,7 @@ MessagesViewIndexWithFullTextSearch
3232
MessageId = ((string) message.MessageMetadata["MessageId"]),
3333
MessageType = ((string) message.MessageMetadata["MessageType"]),
3434
IsSystemMessage = ((bool) message.MessageMetadata["IsSystemMessage"]),
35-
Status = ((bool) message.MessageMetadata["IsRetried"]) ? "ResolvedSuccessfully" : "Successful",
35+
Status = ((bool) message.MessageMetadata["IsRetried"]) ? 4 : 3,
3636
TimeSent = ((DateTime) message.MessageMetadata["TimeSent"]),
3737
ProcessedAt = message.ProcessedAt,
3838
ReceivingEndpointName = ((message.MessageMetadata["ReceivingEndpoint"])).Name,

‎src/ServiceControl.Persistence.RavenDB/RavenExternalPersistenceLifecycle.cs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace ServiceControl.Persistence.RavenDB
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Raven.Client.Documents;
9-
using Raven.Client.Documents.Conventions;
109
using ServiceControl.RavenDB;
1110

1211
sealed class RavenExternalPersistenceLifecycle(RavenPersisterSettings settings) : IRavenPersistenceLifecycle, IRavenDocumentStoreProvider, IDisposable
@@ -40,10 +39,7 @@ public async Task Initialize(CancellationToken cancellationToken = default)
4039
Database = settings.DatabaseName,
4140
Urls = [settings.ConnectionString],
4241
Certificate = RavenClientCertificate.FindClientCertificate(settings),
43-
Conventions = new DocumentConventions
44-
{
45-
SaveEnumsAsIntegers = true
46-
}
42+
Conventions = DocumentStoreConventions.Create()
4743
};
4844

4945
documentStore = store.Initialize();

‎src/ServiceControl.Persistence.Tests.RavenDB/ApprovalFiles/IndexDefinitionApprovals.Verify_index_definitions_are_unchanged.approved.txt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ArchivedGroupsViewIndex
22
Maps:
3-
docs.FailedMessages.Where(doc => doc.Status == "Archived").Select(doc => new {
3+
docs.FailedMessages.Where(doc => doc.Status == 4).Select(doc => new {
44
doc = doc,
55
failureTimes = doc.ProcessingAttempts.Select(x => x.FailureDetails.TimeOfFailure)
66
}).SelectMany(this0 => this0.doc.FailureGroups, (this0, failureGroup) => new {
@@ -49,7 +49,7 @@ FailedErrorImportIndex
4949

5050
FailedMessageFacetsIndex
5151
Maps:
52-
docs.FailedMessages.Where(failure => failure.Status == "Unresolved").Select(failure => new {
52+
docs.FailedMessages.Where(failure => failure.Status == 1).Select(failure => new {
5353
failure = failure,
5454
t = ((DynamicEnumerable.LastOrDefault(failure.ProcessingAttempts)).MessageMetadata["ReceivingEndpoint"])
5555
}).Select(this0 => new {
@@ -105,7 +105,7 @@ FailedMessages/ByGroup
105105

106106
FailureGroupsViewIndex
107107
Maps:
108-
docs.FailedMessages.Where(doc => doc.Status == "Unresolved").Select(doc => new {
108+
docs.FailedMessages.Where(doc => doc.Status == 1).Select(doc => new {
109109
doc = doc,
110110
failureTimes = doc.ProcessingAttempts.Select(x => x.FailureDetails.TimeOfFailure)
111111
}).SelectMany(this0 => this0.doc.FailureGroups, (this0, failureGroup) => new {
@@ -155,7 +155,7 @@ MessagesViewIndex
155155
MessageId = this0.last.MessageId,
156156
MessageType = ((string) this0.last.MessageMetadata["MessageType"]),
157157
IsSystemMessage = ((bool) this0.last.MessageMetadata["IsSystemMessage"]),
158-
Status = this0.message.Status == "Archived" ? "ArchivedFailure" : (this0.message.Status == "Resolved" ? "ResolvedSuccessfully" : (this0.message.ProcessingAttempts.Count == 1 ? "Failed" : "RepeatedFailure")),
158+
Status = this0.message.Status == 4 ? 5 : (this0.message.Status == 2 ? 4 : (this0.message.ProcessingAttempts.Count == 1 ? 1 : 2)),
159159
TimeSent = ((DateTime) this0.last.MessageMetadata["TimeSent"]),
160160
ProcessedAt = this0.last.AttemptedAt,
161161
ReceivingEndpointName = ((this0.last.MessageMetadata["ReceivingEndpoint"])).Name,
@@ -190,8 +190,8 @@ RetryBatches/ByStatus/ReduceInitialBatchSize
190190
docs.RetryBatches.Select(doc => new {
191191
RequestId = doc.RequestId,
192192
RetryType = doc.RetryType,
193-
HasStagingBatches = doc.Status == "Staging",
194-
HasForwardingBatches = doc.Status == "Forwarding",
193+
HasStagingBatches = doc.Status == 2,
194+
HasForwardingBatches = doc.Status == 3,
195195
InitialBatchSize = doc.InitialBatchSize,
196196
Originator = doc.Originator,
197197
Classifier = doc.Classifier,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace ServiceControl.RavenDB
2+
{
3+
using Raven.Client.Documents.Conventions;
4+
5+
public static class DocumentStoreConventions
6+
{
7+
// The conventions are part of every deployed index definition: a change rebuilds every index. The index
8+
// definition approval tests render the definitions with the same conventions, so keep them in one place.
9+
public static DocumentConventions Create() => new() { SaveEnumsAsIntegers = true };
10+
}
11+
}

‎src/ServiceControl.RavenDB/EmbeddedDatabase.cs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace ServiceControl.RavenDB
1212
using Microsoft.Extensions.Hosting;
1313
using Microsoft.Extensions.Logging;
1414
using Raven.Client.Documents;
15-
using Raven.Client.Documents.Conventions;
1615
using Raven.Embedded;
1716
using ServiceControl.Infrastructure;
1817
using Sparrow.Logging;
@@ -171,10 +170,7 @@ public async Task<IDocumentStore> Connect(CancellationToken cancellationToken =
171170
{
172171
var dbOptions = new DatabaseOptions(configuration.Name)
173172
{
174-
Conventions = new DocumentConventions
175-
{
176-
SaveEnumsAsIntegers = true
177-
},
173+
Conventions = DocumentStoreConventions.Create(),
178174
SkipCreatingDatabase = true
179175
};
180176

‎src/TestHelper/IndexDefinitionText.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace TestHelper;
66
using System.Reflection;
77
using System.Text;
88
using Raven.Client.Documents.Indexes;
9+
using ServiceControl.RavenDB;
910

1011
/// <summary>
1112
/// Renders the parts of an index definition that RavenDB compares when ServiceControl deploys its indexes at
@@ -29,6 +30,8 @@ public static string Render(IEnumerable<AbstractIndexCreationTask> indexes)
2930

3031
foreach (var index in indexes.OrderBy(i => i.IndexName, StringComparer.Ordinal))
3132
{
33+
// The conventions change the rendered definition, for example how enum literals appear in a map.
34+
index.Conventions = DocumentStoreConventions.Create();
3235
Render(builder, index.CreateIndexDefinition());
3336
builder.AppendLine();
3437
}

0 commit comments

Comments
 (0)