Esempio n. 1
0
        public async Task It_logs_error_when_file_access_fails_during_runtime()
        {
            var errorCallbackInvoked = false;
            var timer = new FakeTimer(ex =>
            {
                errorCallbackInvoked = true;
            });
            var fail   = false;
            var loader = new FakeLoader(() =>
            {
                if (fail)
                {
                    throw new Exception("Simulated");
                }
                return(XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>"));
            });

            var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, timer, loader, new EndpointInstances());
            await monitor.Start(null);

            fail = true;
            await timer.Trigger();

            Assert.IsTrue(errorCallbackInvoked);
        }
        public async Task It_logs_error_when_file_access_fails_during_runtime()
        {
            var errorCallbackInvoked = false;
            var timer = new FakeTimer(ex =>
            {
                errorCallbackInvoked = true;
            });
            var fail = false;
            var fileAccess = new FakeFileAccess(() =>
            {
                // ReSharper disable once AccessToModifiedClosure
                if (fail)
                {
                    throw new Exception("Simulated");
                }
                return XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>");
            });

            var monitor = new InstanceMappingFileMonitor("unused", TimeSpan.Zero, timer, fileAccess, new EndpointInstances());
            await monitor.PerformStartup(null);

            fail = true;
            await timer.Trigger();

            Assert.IsTrue(errorCallbackInvoked);
        }
Esempio n. 3
0
        public async Task It_logs_error_when_file_access_fails_during_runtime()
        {
            var errorCallbackInvoked = false;
            var timer = new FakeTimer(ex =>
            {
                errorCallbackInvoked = true;
            });
            var fail       = false;
            var fileAccess = new FakeFileAccess(() =>
            {
                // ReSharper disable once AccessToModifiedClosure
                if (fail)
                {
                    throw new Exception("Simulated");
                }
                return(XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>"));
            });

            var monitor = new InstanceMappingFileMonitor("unused", TimeSpan.Zero, timer, fileAccess, new EndpointInstances());
            await monitor.PerformStartup(null);

            fail = true;
            await timer.Trigger();

            Assert.IsTrue(errorCallbackInvoked);
        }
Esempio n. 4
0
        public void Should_log_added_endpoints()
        {
            var loader  = new FakeLoader(() => XDocument.Parse(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>"));
            var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, new FakeTimer(), loader, new EndpointInstances());

            monitor.ReloadData();

            Assert.That(logOutput.ToString(), Does.Contain(@"Added endpoint 'A' with 2 instances"));
        }
        public void Should_log_added_endpoints()
        {
            var fileAccess = new FakeFileAccess(() => XDocument.Parse(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>"));
            var monitor    = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances());

            monitor.ReloadData();

            Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath':
Added endpoint 'A' with 2 instances"));
        }
        public void Should_log_added_endpoints()
        {
            var fileAccess = new FakeFileAccess(() => XDocument.Parse(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>"));
            var monitor = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances());

            monitor.ReloadData();

            Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath':
Added endpoint 'A' with 2 instances"));
        }
Esempio n. 7
0
        public void Reload_should_throw_when_file_does_not_exist()
        {
            var timer = new FakeTimer();
            var fileAccessException = new Exception("Simulated");
            var loader  = new FakeLoader(() => throw fileAccessException);
            var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, timer, loader, new EndpointInstances());

            var exception = Assert.Throws <Exception>(() => monitor.ReloadData());

            Assert.That(exception.Message, Does.Contain("An error occurred while reading the endpoint instance mapping (NServiceBus.Transport.Msmq.Tests.InstanceMappingFileMonitorTests+FakeLoader). See the inner exception for more details."));
            Assert.That(exception.InnerException, Is.EqualTo(fileAccessException));
        }
Esempio n. 8
0
        public void Should_log_removed_endpoints()
        {
            var fileData = new Queue <string>();

            fileData.Enqueue(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>");
            fileData.Enqueue("<endpoints></endpoints>");
            var loader  = new FakeLoader(() => XDocument.Parse(fileData.Dequeue()));
            var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, new FakeTimer(), loader, new EndpointInstances());

            monitor.ReloadData();
            logOutput.Clear();
            monitor.ReloadData();

            Assert.That(logOutput.ToString(), Does.Contain(@"Removed all instances of endpoint 'A'"));
        }
        public void Reload_should_throw_when_file_does_not_exist()
        {
            const string filePath            = "some file path";
            var          timer               = new FakeTimer();
            var          fileAccessException = new Exception("Simulated");
            var          fileAccess          = new FakeFileAccess(() =>
            {
                throw fileAccessException;
            });
            var monitor = new InstanceMappingFileMonitor(filePath, TimeSpan.Zero, timer, fileAccess, new EndpointInstances());

            var exception = Assert.Throws <Exception>(() => monitor.ReloadData());

            Assert.That(exception.Message, Does.Contain($"An error occurred while reading the endpoint instance mapping file at {filePath}. See the inner exception for more details."));
            Assert.That(exception.InnerException, Is.EqualTo(fileAccessException));
        }
        public void Should_log_changed_instances()
        {
            var fileData = new Queue <string>();

            fileData.Enqueue(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>");
            fileData.Enqueue(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""3"" /><instance discriminator=""4"" /></endpoint></endpoints>");
            var fileAccess = new FakeFileAccess(() => XDocument.Parse(fileData.Dequeue()));
            var monitor    = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances());

            monitor.ReloadData();
            logOutput.Clear();
            monitor.ReloadData();

            Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath':
Updated endpoint 'A': +2 instances, -1 instance"));
        }
        public void Reload_should_throw_when_file_does_not_exist()
        {
            const string filePath = "some file path";
            var timer = new FakeTimer();
            var fileAccessException = new Exception("Simulated");
            var fileAccess = new FakeFileAccess(() =>
            {
                throw fileAccessException;
            });
            var monitor = new InstanceMappingFileMonitor(filePath, TimeSpan.Zero, timer, fileAccess, new EndpointInstances());

            var exception = Assert.Throws<Exception>(() => monitor.ReloadData());

            Assert.That(exception.Message, Does.Contain($"An error occurred while reading the endpoint instance mapping file at {filePath}. See the inner exception for more details."));
            Assert.That(exception.InnerException, Is.EqualTo(fileAccessException));
        }
        protected internal override void Setup(FeatureConfigurationContext context)
        {
            var filePath = GetRootedPath(context.Settings.Get<string>(FilePathSettingsKey));

            if (!File.Exists(filePath))
            {
                throw new Exception($"The specified instance mapping file '{filePath}' does not exist.");
            }

            var checkInterval = context.Settings.Get<TimeSpan>(CheckIntervalSettingsKey);
            var endpointInstances = context.Settings.Get<EndpointInstances>();

            var instanceMappingTable = new InstanceMappingFileMonitor(filePath, checkInterval, new AsyncTimer(), new InstanceMappingFileAccess(), endpointInstances);
            instanceMappingTable.ReloadData();
            context.RegisterStartupTask(instanceMappingTable);
        }
        protected internal override void Setup(FeatureConfigurationContext context)
        {
            var filePath = GetRootedPath(context.Settings.Get <string>(FilePathSettingsKey));

            if (!File.Exists(filePath))
            {
                throw new Exception($"The specified instance mapping file '{filePath}' does not exist.");
            }

            var checkInterval     = context.Settings.Get <TimeSpan>(CheckIntervalSettingsKey);
            var endpointInstances = context.Settings.Get <EndpointInstances>();

            var instanceMappingTable = new InstanceMappingFileMonitor(filePath, checkInterval, new AsyncTimer(), new InstanceMappingFileAccess(), endpointInstances);

            instanceMappingTable.ReloadData();
            context.RegisterStartupTask(instanceMappingTable);
        }
        public void Should_log_removed_endpoints()
        {
            var fileData = new Queue<string>();
            fileData.Enqueue(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>");
            fileData.Enqueue(@"<endpoints></endpoints>");
            var fileAccess = new FakeFileAccess(() => XDocument.Parse(fileData.Dequeue()));
            var monitor = new InstanceMappingFileMonitor("filepath", TimeSpan.Zero, new FakeTimer(), fileAccess, new EndpointInstances());

            monitor.ReloadData();
            logOutput.Clear();
            monitor.ReloadData();

            Assert.That(logOutput.ToString(), Does.Contain(@"Updating instance mapping table from 'filepath':
Removed all instances of endpoint 'A'"));
        }