示例#1
0
        /// <summary>
        /// usage: local debugging
        /// </summary>
        private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, string dataDirectory)
        {
            _fileSystem = fileSystem;
            _port       = MongoDbDefaults.DefaultPort;
            _mongoBin   = mongoBin;

            MakeMongoBinarysExecutable();

            ConnectionString = "mongodb://*****:*****@"{0}{1}{2}".Formatted(dataDirectory, System.IO.Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.Lockfile));
            _mongoDbProcess = processStarter.Start(_mongoBin.Directory, dataDirectory, _port, true);

            State = State.Running;
        }
示例#2
0
        /// <summary>
        /// usage: local debugging
        /// </summary>
        private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, string dataDirectory)
        {
            _fileSystem = fileSystem;
            _port = MongoDbDefaults.DefaultPort;
            _mongoBin = mongoBin;

            MakeMongoBinarysExecutable();

            ConnectionString = "mongodb://*****:*****@"{0}{1}{2}".Formatted(dataDirectory, System.IO.Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.Lockfile));
            _mongoDbProcess = processStarter.Start(_mongoBin.Directory, dataDirectory, _port, true);

            State = State.Running;
        }
示例#3
0
        /// <summary>
        /// usage: local debugging
        /// </summary>
        private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, int port, string dataDirectory = null, bool singleNodeReplSet = false, string additionalMongodArguments = null)
        {
            _fileSystem = fileSystem;
            _mongoBin   = mongoBin;
            _port       = port;

            MakeMongoBinarysExecutable();

            ConnectionString = singleNodeReplSet? "mongodb://127.0.0.1:{0}/?connect=direct&replicaSet=singleNodeReplSet&readPreference=primary".Formatted(_port) :
                               "mongodb://127.0.0.1:{0}/".Formatted(_port);

            if (processWatcher.IsProcessRunning(MongoDbDefaults.ProcessName) && !portWatcher.IsPortAvailable(_port))
            {
                State = State.AlreadyRunning;
                return;
            }

            if (!portWatcher.IsPortAvailable(_port))
            {
                throw new MongoDbPortAlreadyTakenException("MongoDB can't be started. The TCP port {0} is already taken.".Formatted(_port));
            }

            if (dataDirectory == null)
            {
                dataDirectory = CreateTemporaryDataDirectory();
            }

            _fileSystem.CreateFolder(dataDirectory);
            _fileSystem.DeleteFile("{0}{1}{2}".Formatted(dataDirectory, Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.Lockfile));
            _mongoDbProcess = processStarter.Start(_mongoBin.Directory, dataDirectory, _port, true, singleNodeReplSet, additionalMongodArguments);

            State = State.Running;
        }
示例#4
0
        /// <summary>
        /// Returns and reserves a new port
        /// </summary>
        public int GetNextOpenPort()
        {
            lock (_lock)
            {
                IPortWatcher portWatcher      = PortWatcherFactory.CreatePortWatcher();
                int          newAvailablePort = portWatcher.FindOpenPort(_startPort);

                return(newAvailablePort);
            }
        }
示例#5
0
 public static MongoDbRunner StartForDebuggingUnitTest(
     IProcessWatcher processWatcher,
     IPortWatcher portWatcher,
     IFileSystem fileSystem,
     IMongoDbProcessStarter processStarter,
     IMongoBinaryLocator mongoBin,
     string dataDirectory = null)
 {
     return(new MongoDbRunner(
                processWatcher,
                portWatcher,
                fileSystem,
                processStarter,
                mongoBin,
                dataDirectory));
 }
示例#6
0
        public static IPortWatcher CreatePortWatcher()
        {
            IPortWatcher portwatcher = null;

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Unix:
                portwatcher = new UnixPortWatcher();
                break;

            default:
                portwatcher = new PortWatcher();
                break;
            }

            return(portwatcher);
        }
示例#7
0
        private RedisRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IRedisProcessStarter processStarter)
        {
            Port = RedisDefaults.DefaultPort;

            if (processWatcher.IsProcessRunning(RedisDefaults.ProcessName) && !portWatcher.IsPortAvailable(Port))
            {
                State = State.AlreadyRunning;
                return;
            }

            if (!portWatcher.IsPortAvailable(Port))
            {
                throw new PortTakenException(String.Format("Redis can't be started. The TCP port {0} is already taken.", this.Port));
            }

            _redisProcess = processStarter.Start(Port);

            State = State.Running;
        }
示例#8
0
 public static MongoDbRunner StartForDebuggingUnitTest(
     IProcessWatcher processWatcher,
     IPortWatcher portWatcher,
     IFileSystem fileSystem,
     IMongoDbProcessStarter processStarter,
     IMongoBinaryLocator mongoBin,
     string dataDirectory             = null,
     string additionalMongodArguments = null)
 {
     return(new MongoDbRunner(
                processWatcher,
                portWatcher,
                fileSystem,
                processStarter,
                mongoBin,
                MongoDbDefaults.DefaultPort,
                dataDirectory,
                additionalMongodArguments: additionalMongodArguments));
 }
示例#9
0
        /// <summary>
        /// usage: local debugging
        /// </summary>
        private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter)
        {
            _fileSystem = fileSystem;
            _port       = MongoDbDefaults.DefaultPort;

            ConnectionString = "mongodb://*****:*****@"{0}\{1}".Formatted(MongoDbDefaults.DataDirectory, MongoDbDefaults.Lockfile));
            _mongoDbProcess = processStarter.Start(BinariesDirectory, MongoDbDefaults.DataDirectory, _port, true);

            State = State.Running;
        }
示例#10
0
        /// <summary>
        /// usage: local debugging
        /// </summary>
        private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter)
        {
            _fileSystem = fileSystem;
            _port = MongoDbDefaults.DefaultPort;

            ConnectionString = "mongodb://*****:*****@"{0}\{1}".Formatted(MongoDbDefaults.DataDirectory, MongoDbDefaults.Lockfile));
            _mongoDbProcess = processStarter.Start(BinariesDirectory, MongoDbDefaults.DataDirectory, _port, true);

            State = State.Running;
        }
示例#11
0
        /// <summary>
        /// Returns and reserves a new port
        /// </summary>
        public int GetNextOpenPort()
        {
            IPortWatcher portWatcher = PortWatcherFactory.CreatePortWatcher();

            return(portWatcher.FindOpenPort());
        }
示例#12
0
 internal static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter)
 {
     return(new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter));
 }
示例#13
0
 public static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin)
 {
     return new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter, mongoBin, MongoDbDefaults.DataDirectory);
 }
示例#14
0
 internal static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter)
 {
     return new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter, MongoDbDefaults.DataDirectory);
 }
示例#15
0
 internal static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin)
 {
     return(new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter, mongoBin, MongoDbDefaults.DataDirectory));
 }