Beispiel #1
0
        /// <summary>
        /// Creates an instance of a database with a given data.
        /// </summary>
        public static LocalRedisProcessDatabase CreateAndStart(
            LocalRedisFixture redisFixture,
            ILogger logger,
            IClock clock,
            IDictionary <RedisKey, RedisValue> initialData,
            IDictionary <RedisKey, DateTime> expiryData,
            IDictionary <RedisKey, RedisValue[]> setData)
        {
            logger.Debug($"Fixture '{redisFixture.Id}' has {redisFixture.DatabasePool.ObjectsInPool} available redis databases.");
            var instance = redisFixture.DatabasePool.GetInstance();
            var oldOrNew = instance.Instance._process != null ? "an old" : "a new";

            logger.Debug($"LocalRedisProcessDatabase: got {oldOrNew} instance from the pool.");

            var result = instance.Instance;

            if (result.Closed)
            {
                throw new ObjectDisposedException("instance", "The instance is already closed!");
            }

            result.Init(logger, clock, redisFixture);
            try
            {
                result.Start(initialData, expiryData, setData);
                return(result);
            }
            catch (Exception e)
            {
                logger.Error("Failed to start a local database. Exception=" + e);
                result.Dispose();
                throw;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates an empty instance of a database.
 /// </summary>
 public static LocalRedisProcessDatabase CreateAndStartEmpty(
     LocalRedisFixture redisFixture,
     ILogger logger,
     IClock clock)
 {
     return(CreateAndStart(redisFixture, logger, clock, initialData: null, expiryData: null, setData: null));
 }
        /// <summary>
        /// Creates an instance of a database with a given data.
        /// </summary>
        public static AzuriteStorageProcess CreateAndStart(
            LocalRedisFixture storageFixture,
            ILogger logger,
            IClock clock)
        {
            logger.Debug($"Fixture '{storageFixture.Id}' has {storageFixture.DatabasePool.ObjectsInPool} available storage databases.");
            var instance = storageFixture.EmulatorPool.GetInstance();
            var oldOrNew = instance.Instance._process != null ? "an old" : "a new";

            logger.Debug($"LocalStorageProcessDatabase: got {oldOrNew} instance from the pool.");

            var result = instance.Instance;

            if (result.Closed)
            {
                throw new ObjectDisposedException("instance", "The instance is already closed!");
            }

            result.Init(logger, clock, storageFixture);
            try
            {
                result.Start();
                return(result);
            }
            catch (Exception e)
            {
                logger.Error("Failed to start a local database. Exception=" + e);
                result.Dispose();
                throw;
            }
        }
 /// <summary>
 /// Creates an empty instance of a database.
 /// </summary>
 public static AzuriteStorageProcess CreateAndStartEmpty(
     LocalRedisFixture storageFixture,
     ILogger logger,
     IClock clock)
 {
     return(CreateAndStart(storageFixture, logger, clock));
 }
 private void Init(ILogger logger, IClock clock, LocalRedisFixture redisFixture)
 {
     _fileSystem    = new PassThroughFileSystem(logger);
     _logger        = logger;
     _tempDirectory = new DisposableDirectory(_fileSystem, "RedisTests");
     _clock         = clock;
     _redisFixture  = redisFixture;
     _disposed      = false;
 }
Beispiel #6
0
        private void Init(ILogger logger, IClock clock, LocalRedisFixture redisFixture)
        {
            _fileSystem    = new PassThroughFileSystem(logger);
            _logger        = logger;
            _tempDirectory = new DisposableDirectory(_fileSystem, "RedisTests");
            _clock         = clock;
            _redisFixture  = redisFixture;
            _disposed      = false;

            // The instance is re-initialized, so we need to re-register it for finalization to detect resource leaks.
            GC.ReRegisterForFinalize(this);
        }