示例#1
0
        protected override void Given()
        {
            Subsystem.Handle(new SystemMessage.SystemCoreReady());
            Subsystem.Handle(new SystemMessage.BecomeMaster(Guid.NewGuid()));

            var startMsg = WaitForStartMessage();

            _instanceCorrelation = startMsg.InstanceCorrelationId;

            Subsystem.Handle(new ProjectionSubsystemMessage.ComponentStarted(
                                 ProjectionManager.ServiceName, _instanceCorrelation));
            Subsystem.Handle(new ProjectionSubsystemMessage.ComponentStarted(
                                 ProjectionCoreCoordinator.ComponentName, _instanceCorrelation));

            ResetMessageEvents();
            Subsystem.Handle(new ProjectionSubsystemMessage.RestartSubsystem(new NoopEnvelope()));

            _stopMsg = WaitForStopMessage();

            // Become unknown before components stopped
            Subsystem.Handle(new SystemMessage.BecomeUnknown(Guid.NewGuid()));

            Subsystem.Handle(new ProjectionSubsystemMessage.ComponentStopped(
                                 ProjectionManager.ServiceName, _instanceCorrelation));
            Subsystem.Handle(new ProjectionSubsystemMessage.ComponentStopped(
                                 ProjectionCoreCoordinator.ComponentName, _instanceCorrelation));
        }
        public void SetUp()
        {
            _standardComponents = CreateStandardComponents();

            Subsystem = new ProjectionsSubsystem(1, ProjectionType.All, true, TimeSpan.FromSeconds(3), true);
            Subsystem.Register(_standardComponents);

            // Unsubscribe from the actual components so we can test in isolation
            Subsystem.MasterMainBus.Unsubscribe <ProjectionSubsystemMessage.ComponentStarted>(Subsystem);
            Subsystem.MasterMainBus.Unsubscribe <ProjectionSubsystemMessage.ComponentStopped>(Subsystem);

            Subsystem.MasterMainBus.Subscribe(new AdHocHandler <Message>(
                                                  msg => {
                switch (msg)
                {
                case ProjectionSubsystemMessage.StartComponents start: {
                    _lastStartMessage = start;
                    _startReceived.Set();
                    break;
                }

                case ProjectionSubsystemMessage.StopComponents stop: {
                    _lastStopMessage = stop;
                    _stopReceived.Set();
                    break;
                }
                }
            }));

            Subsystem.Start();

            Given();
        }
        private void Stop(ProjectionSubsystemMessage.StopComponents message)
        {
            if (_currentState != CoreCoordinatorState.Started)
            {
                Log.Debug("PROJECTIONS: Projections Core Coordinator trying to stop when not started. " +
                          "Current state: {currentState}. StopCorrelation: {correlation}", _currentState,
                          message.InstanceCorrelationId);
                return;
            }

            Log.Debug("PROJECTIONS: Stopping Projections Core Coordinator");
            _currentState = CoreCoordinatorState.Stopping;
            foreach (var queue in _queues)
            {
                if (_runProjections >= ProjectionType.System)
                {
                    queue.Value.Publish(new ProjectionCoreServiceMessage.StopCore(queue.Key));
                }
                else
                {
                    // TODO: Find out why projections still run even when ProjectionType.None
                    queue.Value.Publish(new ReaderCoreServiceMessage.StopReader(queue.Key));
                }
            }
        }
 protected void ResetMessageEvents()
 {
     _stopReceived.Reset();
     _startReceived.Reset();
     _lastStopMessage  = null;
     _lastStartMessage = null;
 }
 public void Handle(ProjectionSubsystemMessage.StopComponents message)
 {
     if (_currentState != CoreCoordinatorState.Started)
     {
         Log.Debug("PROJECTIONS: Projection Core Coordinator cannot stop components as it's not started. Correlation: {correlation}",
                   message.InstanceCorrelationId);
         return;
     }
     if (_instanceCorrelationId != message.InstanceCorrelationId)
     {
         Log.Debug("PROJECTIONS: Projection Core Coordinator received stop request for incorrect correlation id." +
                   "Current: {correlationId}. Requested: {requestedCorrelationId}", _instanceCorrelationId, message.InstanceCorrelationId);
         return;
     }
     Stop(message);
 }