public void Same_type_receives_same_logger_instance()
        {
            var repository = new ContextLoggerRepository("foo");
            var logger     = repository.Get <A>();

            Assert.AreSame(logger, repository.Get <A>(), "logger instances were not the same");
        }
Ejemplo n.º 2
0
 public void Loggers_for_same_class_but_different_context_share_same_base() {
     var r1 = new ContextLoggerRepository("foo");
     var r2 = new ContextLoggerRepository("bar");
     var logger1 = r1.Get<A>() as ContextLogger;
     var logger2 = r2.Get<A>() as ContextLogger;
     Assert.AreSame(logger1.Logger, logger2.Logger);
 }
Ejemplo n.º 3
0
 public void Loggers_for_same_class_but_different_context_are_not_the_same() {
     var r1 = new ContextLoggerRepository("foo");
     var r2 = new ContextLoggerRepository("bar");
     var logger1 = r1.Get<A>() as ContextLogger;
     var logger2 = r2.Get<A>() as ContextLogger;
     Assert.AreNotSame(logger1, logger2);
 }
Ejemplo n.º 4
0
 public void Can_get_logger() {
     var repository = new ContextLoggerRepository("foo");
     var logger = repository.Get<A>();
     Assert.IsNotNull(logger,"could not get a logger from repository");
     var contextLogger = logger as ContextLogger;
     Assert.IsNotNull(contextLogger,"logger could not be cast to context logger");
 }
        public void Loggers_from_same_repository_share_context()
        {
            var repository = new ContextLoggerRepository("foo");
            var loggerA    = repository.Get <A>() as ContextLogger;
            var loggerB    = repository.Get <B>() as ContextLogger;

            Assert.AreEqual(loggerA.Context, loggerB.Context, "loggers had different contexts from same repository");
        }
        public void Loggers_for_same_class_but_different_context_share_same_base()
        {
            var r1      = new ContextLoggerRepository("foo");
            var r2      = new ContextLoggerRepository("bar");
            var logger1 = r1.Get <A>() as ContextLogger;
            var logger2 = r2.Get <A>() as ContextLogger;

            Assert.AreSame(logger1.Logger, logger2.Logger);
        }
        public void Loggers_for_same_class_but_different_context_are_not_the_same()
        {
            var r1      = new ContextLoggerRepository("foo");
            var r2      = new ContextLoggerRepository("bar");
            var logger1 = r1.Get <A>() as ContextLogger;
            var logger2 = r2.Get <A>() as ContextLogger;

            Assert.AreNotSame(logger1, logger2);
        }
        public void Can_get_logger()
        {
            var repository = new ContextLoggerRepository("foo");
            var logger     = repository.Get <A>();

            Assert.IsNotNull(logger, "could not get a logger from repository");
            var contextLogger = logger as ContextLogger;

            Assert.IsNotNull(contextLogger, "logger could not be cast to context logger");
        }
Ejemplo n.º 9
0
        protected DekiInstance CreateWikiInstance(string wikiId, XDoc instanceConfig)
        {
            List <DekiInstance> instances = null;
            DekiInstance        instance;

            lock (_instances) {
                instance = GetWikiInstance(wikiId);
                if (instance == null)
                {
                    var licenseStoragePlug = _dekiService.Storage;
                    _loggerRepositories[wikiId] = new ContextLoggerRepository("[" + wikiId + "] ");
                    var licenseController = GetLicenseController(wikiId, licenseStoragePlug);
                    _instances[wikiId] = instance = new DekiInstance(_dekiService, wikiId, instanceConfig, licenseController);
                }

                // Schedule new instance for shutdown if inactive-instance-timeout enabled.
                if (InactiveInstanceTimeOut != TimeSpan.MaxValue)
                {
                    var timer = _timerFactory.New(OnInstanceExpireTimer, wikiId);
                    _instanceExpireTimers[wikiId] = timer;
                }
                if (_instances.Count > _maxInstances)
                {
                    instances = _instances.Values.ToList();
                }
            }

            // Hit the instance number limit? Look for least recently accessed wiki and shut it down.
            if (instances != null)
            {
                Async.Fork(() => {
                    _log.DebugFormat("looking for excess instances to shut down");
                    var excessInstances = (from candidate in instances
                                           where DateTime.UtcNow - candidate.InstanceLastUpdateTime >= _minInstanceIdletime
                                           orderby candidate.InstanceLastUpdateTime
                                           select candidate.Id)
                                          .Take(instances.Count - _maxInstances);
                    foreach (var shutdownId in excessInstances)
                    {
                        _log.DebugFormat("shutting down instance '{0}'", shutdownId);
                        OutOfContextShutdown(shutdownId);
                    }
                });
            }
            return(instance);
        }
Ejemplo n.º 10
0
        protected DekiInstance CreateWikiInstance(string wikiId, XDoc instanceConfig) {
            List<DekiInstance> instances = null;
            DekiInstance instance;

            lock(_instances) {
                instance = GetWikiInstance(wikiId);
                if(instance == null) {
                    var licenseStoragePlug = _dekiService.Storage;
                    _loggerRepositories[wikiId] = new ContextLoggerRepository("[" + wikiId + "] ");
                    var licenseController = GetLicenseController(wikiId, licenseStoragePlug);
                    _instances[wikiId] = instance = new DekiInstance(_dekiService, wikiId, instanceConfig, licenseController);
                }

                // Schedule new instance for shutdown if inactive-instance-timeout enabled.
                if(InactiveInstanceTimeOut != TimeSpan.MaxValue) {
                    var timer = _timerFactory.New(OnInstanceExpireTimer, wikiId);
                    _instanceExpireTimers[wikiId] = timer;
                }
                if(_instances.Count > _maxInstances) {
                    instances = _instances.Values.ToList();
                }
            }

            // Hit the instance number limit? Look for least recently accessed wiki and shut it down.
            if(instances != null) {
                Async.Fork(() => {
                    _log.DebugFormat("looking for excess instances to shut down");
                    var excessInstances = (from candidate in instances
                                           where DateTime.UtcNow - candidate.InstanceLastUpdateTime >= _minInstanceIdletime
                                           orderby candidate.InstanceLastUpdateTime
                                           select candidate.Id)
                        .Take(instances.Count - _maxInstances);
                    foreach(var shutdownId in excessInstances) {
                        _log.DebugFormat("shutting down instance '{0}'", shutdownId);
                        OutOfContextShutdown(shutdownId);
                    }
                });
            }
            return instance;
        }
Ejemplo n.º 11
0
 public void Loggers_from_same_repository_share_context() {
     var repository = new ContextLoggerRepository("foo");
     var loggerA = repository.Get<A>() as ContextLogger;
     var loggerB = repository.Get<B>() as ContextLogger;
     Assert.AreEqual(loggerA.Context,loggerB.Context,"loggers had different contexts from same repository");
 }
Ejemplo n.º 12
0
 public void Same_type_receives_same_logger_instance() {
     var repository = new ContextLoggerRepository("foo");
     var logger = repository.Get<A>();
     Assert.AreSame(logger, repository.Get<A>(),"logger instances were not the same");
 }