-
Notifications
You must be signed in to change notification settings - Fork 0
fix(projections): reject oversized definitions #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...Tests/Services/projections_manager/when_posting_a_projection_with_oversized_definition.cs
This file contains hidden or 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,67 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using EventStore.Core.Messages; | ||
| using EventStore.Core.Tests; | ||
| using EventStore.Core.TransactionLog.Chunks; | ||
| using EventStore.Projections.Core.Messages; | ||
| using EventStore.Projections.Core.Services; | ||
| using EventStore.Projections.Core.Services.Management; | ||
| using EventStore.Projections.Core.Services.Processing; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EventStore.Projections.Core.Tests.Services.projections_manager; | ||
|
|
||
| [TestFixture(typeof(LogFormat.V2), typeof(string))] | ||
| public class when_posting_a_projection_with_oversized_definition<TLogFormat, TStreamId> : TestFixtureWithProjectionCoreAndManagementServices<TLogFormat, TStreamId> | ||
| { | ||
| private string _projectionName; | ||
| private readonly string _oversizedQuery = new('a', TFConsts.EffectiveMaxLogRecordSize); | ||
|
|
||
| protected override void Given() | ||
| { | ||
| _projectionName = "test-projection"; | ||
| NoStream("$projections-test-projection"); | ||
| NoStream("$projections-test-projection-result"); | ||
| NoStream("$projections-test-projection-order"); | ||
| AllWritesToSucceed("$projections-test-projection-order"); | ||
| NoStream("$projections-test-projection-checkpoint"); | ||
| AllWritesSucceed(); | ||
| } | ||
|
|
||
| protected override IEnumerable<WhenStep> When() | ||
| { | ||
| yield return new ProjectionSubsystemMessage.StartComponents(Guid.NewGuid()); | ||
| yield return | ||
| new ProjectionManagementMessage.Command.Post( | ||
| _bus, ProjectionMode.Continuous, _projectionName, | ||
| ProjectionManagementMessage.RunAs.System, "JS", _oversizedQuery, | ||
| enabled: true, checkpointsEnabled: true, emitEnabled: true, trackEmittedStreams: true); | ||
| } | ||
|
|
||
| [Test, Category("v8")] | ||
| public void the_operation_fails_as_record_too_large() | ||
| { | ||
| var failure = _consumer.HandledMessages.OfType<ProjectionManagementMessage.RecordTooLarge>().Single(); | ||
| StringAssert.Contains("exceeds the maximum", failure.Reason); | ||
| } | ||
|
|
||
| [Test, Category("v8")] | ||
| public void no_definition_event_is_written() | ||
| { | ||
| var persistedStateStream = ProjectionNamesBuilder.ProjectionsStreamPrefix + _projectionName; | ||
| Assert.IsFalse(_consumer.HandledMessages.OfType<ClientMessage.WriteEvents>() | ||
| .Any(x => x.EventStreamId == persistedStateStream && | ||
| x.Events[0].EventType == ProjectionEventTypes.ProjectionUpdated)); | ||
| } | ||
|
|
||
| [Test, Category("v8")] | ||
| public void the_projection_is_faulted() | ||
| { | ||
| _manager.Handle(new ProjectionManagementMessage.Command.GetStatistics(_bus, null, _projectionName, true)); | ||
| Assert.AreEqual( | ||
| ManagedProjectionState.Faulted, | ||
| _consumer.HandledMessages.OfType<ProjectionManagementMessage.Statistics>().Last().Projections.Single() | ||
| .LeaderStatus); | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...ests/Services/projections_manager/when_updating_a_projection_with_oversized_definition.cs
This file contains hidden or 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,77 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using EventStore.Core.Messages; | ||
| using EventStore.Core.Tests; | ||
| using EventStore.Core.TransactionLog.Chunks; | ||
| using EventStore.Projections.Core.Messages; | ||
| using EventStore.Projections.Core.Services; | ||
| using EventStore.Projections.Core.Services.Management; | ||
| using EventStore.Projections.Core.Services.Processing; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace EventStore.Projections.Core.Tests.Services.projections_manager; | ||
|
|
||
| [TestFixture(typeof(LogFormat.V2), typeof(string))] | ||
| public class when_updating_a_projection_with_oversized_definition<TLogFormat, TStreamId> : TestFixtureWithProjectionCoreAndManagementServices<TLogFormat, TStreamId> | ||
| { | ||
| private string _projectionName; | ||
| private readonly string _oversizedQuery = new('a', TFConsts.EffectiveMaxLogRecordSize); | ||
|
|
||
| protected override void Given() | ||
| { | ||
| _projectionName = "test-projection"; | ||
| NoStream("$projections-test-projection"); | ||
| NoStream("$projections-test-projection-result"); | ||
| NoStream("$projections-test-projection-order"); | ||
| AllWritesToSucceed("$projections-test-projection-order"); | ||
| NoStream("$projections-test-projection-checkpoint"); | ||
| AllWritesSucceed(); | ||
| } | ||
|
|
||
| protected override IEnumerable<WhenStep> When() | ||
| { | ||
| yield return new ProjectionSubsystemMessage.StartComponents(Guid.NewGuid()); | ||
| yield return | ||
| new ProjectionManagementMessage.Command.Post( | ||
| _bus, ProjectionMode.Continuous, _projectionName, | ||
| ProjectionManagementMessage.RunAs.System, "JS", @"fromAll().when({$any:function(s,e){return s;}});", | ||
| enabled: true, checkpointsEnabled: true, emitEnabled: true, trackEmittedStreams: true); | ||
| yield return | ||
| new ProjectionManagementMessage.Command.UpdateQuery( | ||
| _bus, _projectionName, ProjectionManagementMessage.RunAs.System, | ||
| _oversizedQuery, emitEnabled: null); | ||
| } | ||
|
|
||
| [Test, Category("v8")] | ||
| public void the_operation_fails_as_record_too_large() | ||
| { | ||
| var failure = _consumer.HandledMessages.OfType<ProjectionManagementMessage.RecordTooLarge>().Single(); | ||
| StringAssert.Contains("exceeds the maximum", failure.Reason); | ||
| } | ||
|
|
||
| [Test, Category("v8")] | ||
| public void no_second_definition_event_is_written() | ||
| { | ||
| var persistedStateStream = ProjectionNamesBuilder.ProjectionsStreamPrefix + _projectionName; | ||
| Assert.AreEqual(1, _consumer.HandledMessages.OfType<ClientMessage.WriteEvents>() | ||
| .Count(x => x.EventStreamId == persistedStateStream && | ||
| x.Events[0].EventType == ProjectionEventTypes.ProjectionUpdated)); | ||
| } | ||
|
|
||
| [Test, Category("v8")] | ||
| public void the_projection_is_faulted() | ||
| { | ||
| _manager.Handle(new ProjectionManagementMessage.Command.GetStatistics(_bus, null, _projectionName, true)); | ||
| Assert.AreEqual( | ||
| ManagedProjectionState.Faulted, | ||
| _consumer.HandledMessages.OfType<ProjectionManagementMessage.Statistics>().Last().Projections.Single() | ||
| .LeaderStatus); | ||
| } | ||
|
|
||
| [Test, Category("v8")] | ||
| public void the_core_projection_is_disposed() | ||
| { | ||
| Assert.AreEqual(1, _consumer.HandledMessages.OfType<CoreProjectionManagementMessage.Dispose>().Count()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.