public void Changes_CS_configuration_when_primary_server_is_available()
        {
            A.CallTo(() => backupServers.GetNextPrimaryServer()).Returns(BackupServer);

            handler.Handle(new ServerStoppedResponding());

            A.CallTo(() => cfgProvider.ChangeConfiguration(BackupServer.Address, BackupServer.Port))
            .MustHaveHappened();
        }
Exemple #2
0
        public TConfig Load <TConfig>(Func <TConfig, string> addressGetter, Func <TConfig, int> portGetter,
                                      string filename = Constants.ConfigFileName)
            where TConfig : class, new()
        {
            var cfg     = configProvider.LoadConfiguration <TConfig>(filename, Environment.GetCommandLineArgs());
            var address = IPAddress.Parse(addressGetter(cfg));
            var port    = portGetter(cfg);

            csConfigProvider.ChangeConfiguration(address, port);
            return(cfg);
        }
Exemple #3
0
        public void Handle(ServerStoppedResponding notification)
        {
            var server = backupManager.GetNextPrimaryServer();

            if (server != null)
            {
                logger.Error($"Primary CS is down, restoring connection to {server.Address}:{server.Port}.");
                cfgProvider.ChangeConfiguration(server.Address, server.Port);
                mediator.Publish(new ConnectionRestored());
            }
            else
            {
                logger.Error("Primary CS is down, notifying system we need to work as primary");
                mediator.Publish(new SwitchedToPrimary());
            }
        }
Exemple #4
0
        public void Handle(ServerStoppedResponding notification)
        {
            // TODO: should we wait a little bit more just to let CS start its work?
            var server = backupManager.GetNextServer();

            if (server != null)
            {
                logger.Error($"Primary CS is down, restoring connection to {server.Address}:{server.Port}.");
                cfgProvider.ChangeConfiguration(server.Address, server.Port);

                Task.Factory.StartNew(async() =>
                {
                    await Task.Delay(2000);
                    mediator.Publish(new ConnectionRestored());
                });
            }
            else
            {
                logger.Error("Primary CS is down but we don't have other backup servers, forcing exit");
                mediator.Send(new ShutdownSystem());
            }
        }