Ejemplo n.º 1
0
            public void anonymous_cannot_retrieve_projection_query()
            {
                GetInputQueue()
                .Publish(
                    new ProjectionManagementMessage.GetQuery(
                        Envelope, _projectionName, ProjectionManagementMessage.RunAs.Anonymous));
                _queue.Process();

                Assert.IsTrue(HandledMessages.OfType <ProjectionManagementMessage.NotAuthorized>().Any());
            }
Ejemplo n.º 2
0
        public void publishes_partition_result_message()
        {
            var results =
                HandledMessages.OfType <PartitionProcessingResult>().ToArray();

            Assert.AreEqual(1, results.Length);
            var result = results[0];

            Assert.IsNull(result.Result);
        }
Ejemplo n.º 3
0
        public void publishes_partition_result_message()
        {
            var results =
                HandledMessages.OfType <PartitionProcessingResult>().ToArray();

            Assert.AreEqual(3, results.Length);
            Assert.AreEqual("{\"data\":1}", results[0].Result);
            Assert.AreEqual("{\"data\":2}", results[1].Result);
            Assert.IsNull(results[2].Result);
        }
            public void does_not_create_a_user_account()
            {
                _users.Handle(new UserManagementMessage.Get(Envelope, SystemAccount.Principal, "user1"));
                _queue.Process();
                var user = HandledMessages.OfType <UserManagementMessage.UserDetailsResult>().SingleOrDefault();

                Assert.NotNull(user);
                Assert.IsFalse(user.Success);
                Assert.AreEqual(UserManagementMessage.Error.NotFound, user.Error);
            }
        public void truncates_existing_stream_at_correct_position()
        {
            var writes =
                HandledMessages.OfType <ClientMessage.WriteEvents>()
                .OfEventType(SystemEventTypes.StreamMetadata)
                .ToArray();

            Assert.AreEqual(1, writes.Length);
            HelperExtensions.AssertJson(new { ___tb = 2 }, writes[0].Data.ParseJson <JObject>());
        }
 public void events_after_first_event_should_be_in_sequence()
 {
     Assert.Throws <InvalidOperationException>(() => {
         //_fromSequenceNumber+2 has been omitted
         HandleEvents(_streamNames[0], new long[] { _fromSequenceNumber, _fromSequenceNumber + 1, _fromSequenceNumber + 3, _fromSequenceNumber + 4 });
         //to trigger event delivery:
         HandleEvents(_streamNames[1], 100, 101);
     });
     Assert.AreEqual(1, HandledMessages.OfType <ReaderSubscriptionMessage.Faulted>().Count());
 }
Ejemplo n.º 7
0
        public void should_not_allow_first_event_to_be_greater_than_sequence_number()
        {
            long eventSequenceNumber = _fromSequenceNumber + 5;

            Assert.Throws <InvalidOperationException>(() => {
                HandleEvents(eventSequenceNumber, eventSequenceNumber);
            });

            Assert.AreEqual(1, HandledMessages.OfType <ReaderSubscriptionMessage.Faulted>().Count());
        }
        public void should_not_allow_first_event_to_be_less_than_sequence_number()
        {
            long eventSequenceNumber = _fromSequenceNumber - 1;

            HandleEvents(_streamNames[0], eventSequenceNumber, eventSequenceNumber);
            //to trigger event delivery:
            HandleEvents(_streamNames[1], 100, 101);

            Assert.AreEqual(1, HandledMessages.OfType <ReaderSubscriptionMessage.Faulted>().Count());
        }
Ejemplo n.º 9
0
            public void does_not_update_details()
            {
                _users.Handle(new UserManagementMessage.Get(Envelope, SystemAccounts.System, "user1"));
                _queue.Process();
                var user = HandledMessages.OfType <UserManagementMessage.UserDetailsResult>().SingleOrDefault();

                Assert.NotNull(user);
                Assert.AreEqual("John Doe", user.Data.FullName);
                Assert.AreEqual("user1", user.Data.LoginName);
                Assert.AreEqual(false, user.Data.Disabled);
            }
Ejemplo n.º 10
0
        public void publishesspool_stream_reading_message()
        {
            var spoolStreamReading =
                HandledMessages.OfType <ReaderSubscriptionManagement.SpoolStreamReadingCore>().LastOrDefault();

            Assert.IsNotNull(spoolStreamReading);
            Assert.AreEqual(Guid.ParseExact("4fb6aa53932045ce891752441a0fde5c", "N"), spoolStreamReading.SubscriptionId);
            Assert.AreEqual("streamId", spoolStreamReading.StreamId);
            Assert.AreEqual(100, spoolStreamReading.CatalogSequenceNumber);
            Assert.AreEqual(123456789123456789, spoolStreamReading.LimitingCommitPosition);
        }
        public void does_not_issue_a_new_read()
        {
            _commandReader.Handle(new ProjectionManagementMessage.Internal.ReadTimeout(_readStreamEventsCorrelationId,
                                                                                       _projectionsMasterStream));

            var response = HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                           .Last(x => x.EventStreamId == _projectionsMasterStream);

            Assert.IsNotNull(response);
            Assert.AreEqual(_readStreamEventsCorrelationId, response.CorrelationId);
        }
Ejemplo n.º 12
0
            public void creates_an_enabled_user_account_with_the_correct_password()
            {
                HandledMessages.Clear();
                _users.Handle(
                    new UserManagementMessage.ChangePassword(
                        Envelope, SystemAccounts.System, "user1", "Johny123!", "new-password"));
                _queue.Process();
                var updateResult = HandledMessages.OfType <UserManagementMessage.UpdateResult>().Last();

                Assert.NotNull(updateResult);
                Assert.IsTrue(updateResult.Success);
            }
Ejemplo n.º 13
0
        public void publishes_result_report_message()
        {
            var response =
                HandledMessages.OfType <CoreProjectionStatusMessage.ResultReport>().LastOrDefault();

            Assert.IsNotNull(response);
            Assert.AreEqual(_projectionId, response.ProjectionId);
            Assert.AreEqual(_correlationId, response.CorrelationId);
            Assert.AreEqual(_partition, response.Partition);
            Assert.AreEqual(_result, response.Result);
            Assert.AreEqual(_position, response.Position);
        }
Ejemplo n.º 14
0
 protected ClientMessage.WriteEvents[] HandledPasswordChangedNotificationMetaStreamWrites()
 {
     return
         (HandledMessages.OfType <ClientMessage.WriteEvents>()
          .Where(
              v =>
              v.EventStreamId
              == SystemStreams.MetastreamOf(
                  Core.Authentication.InternalAuthentication.UserManagementService
                  .UserPasswordNotificationsStreamId))
          .ToArray());
 }
Ejemplo n.º 15
0
            public void changes_password()
            {
                HandledMessages.Clear();
                _users.Handle(
                    new UserManagementMessage.ChangePassword(
                        Envelope, SystemAccounts.System, "user1", "new-password", "other-password"));
                _queue.Process();
                var updateResult = HandledMessages.OfType <UserManagementMessage.UpdateResult>().Last();

                Assert.NotNull(updateResult);
                Assert.IsTrue(updateResult.Success);
            }
        public void sends_committed_event_received_messages_in_correct_order()
        {
            var messages = HandledMessages.OfType <EventReaderSubscriptionMessage.CommittedEventReceived>().ToList();

            Assert.AreEqual(2, messages.Count);

            var message1 = messages[0];
            var message2 = messages[1];

            Assert.AreEqual(_tag1, message1.CheckpointTag);
            Assert.AreEqual(_tag2, message2.CheckpointTag);
        }
Ejemplo n.º 17
0
            public void does_not_override_user_password()
            {
                HandledMessages.Clear();
                _users.Handle(
                    new UserManagementMessage.ChangePassword(
                        Envelope, SystemAccount.Principal, "user1", "existing!", "new-password"));
                _queue.Process();
                var updateResult = HandledMessages.OfType <UserManagementMessage.UpdateResult>().Last();

                Assert.NotNull(updateResult);
                Assert.IsTrue(updateResult.Success);
            }
            public void projection_owner_can_retrieve_projection_query()
            {
                GetInputQueue()
                .Publish(
                    new ProjectionManagementMessage.Command.GetQuery(
                        Envelope, _projectionName, new ProjectionManagementMessage.RunAs(_testUserPrincipal)));
                _queue.Process();

                var query = HandledMessages.OfType <ProjectionManagementMessage.ProjectionQuery>().FirstOrDefault();

                Assert.NotNull(query);
                Assert.AreEqual(_projectionBody, query.Query);
            }
Ejemplo n.º 19
0
        public void reported_state_is_before_the_fault_position()
        {
            var states = HandledMessages.OfType <ProjectionManagementMessage.ProjectionState>().ToArray();

            Assert.AreEqual(1, states.Length);
            var state = states[0];

            Assert.That(state.Position.Streams.Count == 1);
            Assert.That(state.Position.Streams.Keys.First() == "message1");
            Assert.That(state.Position.Streams["message1"] == -1);
            Assert.That(
                state.Position.Position <= _message1Position, "{0} <= {1}", state.Position.Position, _message1Position);
        }
        public void events_fault_message_for_out_of_sequence_events_should_be()
        {
            //_fromSequenceNumber+2 has been omitted
            HandleEvents(_streamNames[0],
                         new long[] {
                _fromSequenceNumber, _fromSequenceNumber + 1, _fromSequenceNumber + 3, _fromSequenceNumber + 4
            });
            //to trigger event delivery:
            HandleEvents(_streamNames[1], 100, 101);

            Assert.IsTrue(HandledMessages.OfType <ReaderSubscriptionMessage.Faulted>().First().Reason
                          .Contains(" was expected in the stream "));
        }
Ejemplo n.º 21
0
            public void does_not_override_user_details()
            {
                _users.Handle(new UserManagementMessage.Get(Envelope, SystemAccount.Principal, "user1"));
                _queue.Process();
                var user = HandledMessages.OfType <UserManagementMessage.UserDetailsResult>().SingleOrDefault();

                Assert.NotNull(user);
                Assert.AreEqual("Existing John", user.Data.FullName);
                Assert.AreEqual("user1", user.Data.LoginName);
                Assert.NotNull(user.Data.Groups);
                Assert.That(user.Data.Groups.Any(v => v == "admin"));
                Assert.That(user.Data.Groups.Any(v => v == "other"));
                Assert.AreEqual(false, user.Data.Disabled);
            }
Ejemplo n.º 22
0
            public void creates_an_enabled_user_account_with_correct_details()
            {
                _users.Handle(new UserManagementMessage.Get(Envelope, SystemAccount.Principal, "user1"));
                _queue.Process();
                var user = HandledMessages.OfType <UserManagementMessage.UserDetailsResult>().SingleOrDefault();

                Assert.NotNull(user);
                Assert.AreEqual("John Doe", user.Data.FullName);
                Assert.AreEqual("user1", user.Data.LoginName);
                Assert.NotNull(user.Data.Groups);
                Assert.That(user.Data.Groups.Any(v => v == "admin"));
                Assert.That(user.Data.Groups.Any(v => v == "other"));
                Assert.AreEqual(false, user.Data.Disabled);
            }
Ejemplo n.º 23
0
 protected override IEnumerable<WhenStep> When()
 {
     foreach (var m in base.When()) yield return m;
     yield return new CoreProjectionManagementMessage.Start(_coreProjectionCorrelationId, Guid.NewGuid());
     var readerAssigned =
         HandledMessages.OfType<CoreProjectionManagementMessage.SlaveProjectionReaderAssigned>().LastOrDefault();
     Assert.IsNotNull(readerAssigned);
     _subscriptionId = readerAssigned.SubscriptionId;
     yield return
         new ReaderSubscriptionManagement.SpoolStreamReadingCore(_subscriptionId,
             "test-stream",
             0,
             10000);
 }
Ejemplo n.º 24
0
            public void details_are_not_changed()
            {
                _users.Handle(new UserManagementMessage.Get(Envelope, SystemAccounts.System, "user1"));
                _queue.Process();
                var user = HandledMessages.OfType <UserManagementMessage.UserDetailsResult>().SingleOrDefault();

                Assert.NotNull(user);
                Assert.AreEqual("John Doe", user.Data.FullName);
                Assert.AreEqual("user1", user.Data.LoginName);
                Assert.NotNull(user.Data.Groups);
                Assert.That(user.Data.Groups.Any(v => v == "admin"));
                Assert.That(user.Data.Groups.Any(v => v == "other"));
                Assert.AreEqual(false, user.Data.Disabled);
            }
Ejemplo n.º 25
0
        public void publishes_projection_create_prepapred_message()
        {
            var createPrepared =
                HandledMessages.OfType <CoreProjectionManagementMessage.CreatePrepared>().LastOrDefault();

            Assert.IsNotNull(createPrepared);
            Assert.AreEqual(_projectionId, createPrepared.ProjectionId);
            Assert.AreEqual("JS", createPrepared.HandlerType);
            Assert.AreEqual(Query, createPrepared.Query);
            Assert.AreEqual("test", createPrepared.Name);
            Assert.IsNotNull(createPrepared.Config);
            Assert.AreEqual("user", createPrepared.Config.RunAs.Identity.Name);
            Assert.That(createPrepared.Config.RunAs.IsInRole("b"));
            Assert.AreEqual(1000, createPrepared.Config.CheckpointHandledThreshold);
            Assert.AreEqual(10000, createPrepared.Config.CheckpointUnhandledBytesThreshold);
            Assert.AreEqual(5000, createPrepared.Config.PendingEventsThreshold);
            Assert.AreEqual(100, createPrepared.Config.MaxWriteBatchLength);
            Assert.AreEqual(true, createPrepared.Config.EmitEventEnabled);
            Assert.AreEqual(true, createPrepared.Config.CheckpointsEnabled);
            Assert.AreEqual(true, createPrepared.Config.CreateTempStreams);
            Assert.AreEqual(false, createPrepared.Config.StopOnEof);
            Assert.AreEqual(false, createPrepared.Config.IsSlaveProjection);
            var projectionSourceDefinition = createPrepared.SourceDefinition as IQuerySources;

            Assert.IsNotNull(projectionSourceDefinition);
            Assert.AreEqual(false, projectionSourceDefinition.AllEvents);
            Assert.AreEqual(false, projectionSourceDefinition.AllStreams);
            Assert.AreEqual(true, projectionSourceDefinition.ByStreams);
            Assert.AreEqual(false, projectionSourceDefinition.ByCustomPartitions);
            Assert.That(new[] { "account" }.SequenceEqual(projectionSourceDefinition.Categories));
            Assert.That(new[] { "added", "removed" }.SequenceEqual(projectionSourceDefinition.Events));
            Assert.That(new string[] {}.SequenceEqual(projectionSourceDefinition.Streams));
            Assert.AreEqual("", projectionSourceDefinition.CatalogStream);
            Assert.AreEqual(100000, projectionSourceDefinition.LimitingCommitPosition);
            Assert.AreEqual("ResultStreamName", projectionSourceDefinition.ResultStreamNameOption);
            Assert.AreEqual(
                "PartitionResultStreamNamePattern",
                projectionSourceDefinition.PartitionResultStreamNamePatternOption);
            Assert.AreEqual("ForceProjectionName", projectionSourceDefinition.ForceProjectionNameOption);
            Assert.AreEqual(false, projectionSourceDefinition.ReorderEventsOption);
            Assert.AreEqual(0, projectionSourceDefinition.ProcessingLagOption);
            Assert.AreEqual(false, projectionSourceDefinition.IsBiState);
            Assert.AreEqual(false, projectionSourceDefinition.DefinesStateTransform);
            Assert.AreEqual(false, projectionSourceDefinition.DefinesCatalogTransform);
            Assert.AreEqual(true, projectionSourceDefinition.ProducesResults);
            Assert.AreEqual(false, projectionSourceDefinition.DefinesFold);
            Assert.AreEqual(false, projectionSourceDefinition.HandlesDeletedNotifications);
            Assert.AreEqual(false, projectionSourceDefinition.IncludeLinksOption);
            Assert.AreEqual(false, projectionSourceDefinition.DisableParallelismOption);
        }
Ejemplo n.º 26
0
            public void writes_both_stream_and_shared_partition_checkpoints()
            {
                var writeProjectionCheckpoints =
                    HandledMessages.OfType <ClientMessage.WriteEvents>().OfEventType(ProjectionEventTypes.ProjectionCheckpoint).ToArray();
                var writeCheckpoints =
                    HandledMessages.OfType <ClientMessage.WriteEvents>().OfEventType(ProjectionEventTypes.PartitionCheckpoint).ToArray();

                Assert.AreEqual(1, writeProjectionCheckpoints.Length);
                Assert.AreEqual(@"[{""data"": 2}]", Encoding.UTF8.GetString(writeProjectionCheckpoints[0].Data));
                Assert.AreEqual(2, writeCheckpoints.Length);

                Assert.That(
                    writeCheckpoints.All(
                        v => Encoding.UTF8.GetString(v.Data) == @"[{""data"": 1},{""data"": 1}]"));
            }
Ejemplo n.º 27
0
        public void cannot_handle_repeated_read_events_completed()
        {
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last().CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        10, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "stream", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type", new byte[0], new byte[0]))
            }, null, false, "", 11, 10, true, 100));
            Assert.AreEqual(1, HandledMessages.OfType <ReaderSubscriptionMessage.Faulted>().Count());
        }
Ejemplo n.º 28
0
            protected override IEnumerable <WhenStep> When()
            {
                var fromZeroPosition = CheckpointTag.FromByStreamPosition(0, "", -1, null, -1, 10000);

                yield return
                    (new ReaderSubscriptionManagement.Subscribe(
                         _subscriptionId, fromZeroPosition, _readerStrategy, _readerSubscriptionOptions));

                yield return
                    (new ReaderSubscriptionManagement.SpoolStreamReading(_subscriptionId, Guid.NewGuid(), "test-stream", 0, 10000));

                yield return(Yield);

                Assert.AreEqual(
                    2, HandledMessages.OfType <EventReaderSubscriptionMessage.CommittedEventReceived>().Count());

                yield return
                    (new ReaderSubscriptionManagement.SpoolStreamReading(_subscriptionId, Guid.NewGuid(), "test-stream2", 1, 10000));
            }
        public void sends_correct_commited_event_received_messages()
        {
            var messages = HandledMessages.OfType <EventReaderSubscriptionMessage.CommittedEventReceived>().ToList();

            Assert.AreEqual(3, messages.Count);

            var message1 = messages[0];
            var message2 = messages[1];
            var message3 = messages[2];

            Assert.AreEqual(@"{""data"":""d""", message1.Data.Data);
            Assert.AreEqual(@"{""data"":""a""", message2.Data.Data);
            Assert.AreEqual(@"{""data"":""b""", message3.Data.Data);

            Assert.AreEqual(@"dd", message1.Data.Metadata);
            Assert.IsNull(message2.Data.Metadata);
            Assert.AreEqual(@"bb", message3.Data.Metadata);

            Assert.AreEqual("{$o:\"org\"}", message1.Data.PositionMetadata);
            Assert.IsNull(message2.Data.PositionMetadata);
            Assert.IsNull(message3.Data.PositionMetadata);

            Assert.AreEqual("Event", message1.Data.EventType);
            Assert.AreEqual("Event", message2.Data.EventType);
            Assert.AreEqual("Event", message3.Data.EventType);

            Assert.AreEqual("c", message1.Data.PositionStreamId);
            Assert.AreEqual("a", message2.Data.PositionStreamId);
            Assert.AreEqual("b", message3.Data.PositionStreamId);

            Assert.AreEqual("d", message1.Data.EventStreamId);
            Assert.AreEqual("a", message2.Data.EventStreamId);
            Assert.AreEqual("b", message3.Data.EventStreamId);

            Assert.AreEqual(_projectionCorrelationId, message1.SubscriptionId);
            Assert.AreEqual(_projectionCorrelationId, message2.SubscriptionId);
            Assert.AreEqual(_projectionCorrelationId, message3.SubscriptionId);

            Assert.AreEqual(true, message1.Data.ResolvedLinkTo);
            Assert.AreEqual(false, message2.Data.ResolvedLinkTo);
            Assert.AreEqual(false, message3.Data.ResolvedLinkTo);
        }
        public void publishes_projection_create_prepapre_message()
        {
            var createPrepare =
                HandledMessages.OfType <CoreProjectionManagementMessage.CreateAndPrepare>().LastOrDefault();

            Assert.IsNotNull(createPrepare);
            Assert.AreEqual(_projectionId, createPrepare.ProjectionId);
            Assert.AreEqual("JS", createPrepare.HandlerType);
            Assert.AreEqual(Query, createPrepare.Query);
            Assert.AreEqual("test", createPrepare.Name);
            Assert.IsNotNull(createPrepare.Config);
            Assert.AreEqual("user", createPrepare.Config.RunAs.Identity.Name);
            Assert.That(createPrepare.Config.RunAs.IsInRole("b"));
            Assert.AreEqual(1000, createPrepare.Config.CheckpointHandledThreshold);
            Assert.AreEqual(10000, createPrepare.Config.CheckpointUnhandledBytesThreshold);
            Assert.AreEqual(5000, createPrepare.Config.PendingEventsThreshold);
            Assert.AreEqual(100, createPrepare.Config.MaxWriteBatchLength);
            Assert.AreEqual(1, createPrepare.Config.MaximumAllowedWritesInFlight);
            Assert.AreEqual(true, createPrepare.Config.EmitEventEnabled);
            Assert.AreEqual(true, createPrepare.Config.CheckpointsEnabled);
            Assert.AreEqual(true, createPrepare.Config.CreateTempStreams);
            Assert.AreEqual(false, createPrepare.Config.StopOnEof);
        }