예제 #1
0
        protected async Task UpgradeServerAsync(
            string toVersion,
            ProcessNode node,
            CancellationToken token = default)
        {
            KillSlavedServerProcess(node.Process);

            if (toVersion == "current")
            {
                RunLocalServer(node);
                return;
            }

            var serverBuildInfo = ServerBuildDownloadInfo.Create(toVersion);
            var serverPath      = await _serverBuildRetriever.GetServerPath(serverBuildInfo, token);

            CopyFilesRecursively(new DirectoryInfo(serverPath), new DirectoryInfo(node.ServerPath));

            var locator = new ConfigurableRavenServerLocator(Path.Combine(node.ServerPath, "Server"), toVersion, node.DataDir, node.Url);

            var result = await RunServer(locator);

            Assert.Equal(node.Url, result.ServerUrl);

            node.Process = result.ServerProcess;
            node.Version = toVersion;
        }
예제 #2
0
        protected async Task <ProcessNode> GetServerAsync(
            string serverVersion,
            InterversionTestOptions options    = null,
            [CallerMemberName] string database = null,
            CancellationToken token            = default)
        {
            var serverBuildInfo = ServerBuildDownloadInfo.Create(serverVersion);
            var serverPath      = await _serverBuildRetriever.GetServerPath(serverBuildInfo, token);

            var testServerPath = NewDataPath(prefix: serverVersion);

            CopyFilesRecursively(new DirectoryInfo(serverPath), new DirectoryInfo(testServerPath));

            var locator = new ConfigurableRavenServerLocator(Path.Combine(testServerPath, "Server"), serverVersion);

            var result = await RunServer(locator);

            return(new ProcessNode
            {
                Process = result.ServerProcess,
                Url = result.ServerUrl,
                Version = serverVersion,
                ServerPath = testServerPath,
                DataDir = locator.DataDir
            });
        }
예제 #3
0
        private Process RunServerProcess(ConfigurableRavenServerLocator locator)
        {
            var process = RavenServerRunner <ConfigurableRavenServerLocator> .Run(locator);

            _allLaunchedServerProcesses.Add(process);
            _testInstanceServerProcesses.Add(process);
            return(process);
        }
        protected async Task <(Uri ServerUrl, Process ServerProcess)> GetServerAsync(
            string serverVersion,
            InterversionTestOptions options    = null,
            [CallerMemberName] string database = null,
            CancellationToken token            = default(CancellationToken))
        {
            var serverBuildInfo = ServerBuildDownloadInfo.Create(serverVersion);
            var serverPath      = await _serverBuildRetriever.GetServerPath(serverBuildInfo);

            var testServerPath = NewDataPath(prefix: serverVersion);

            CopyFilesRecursively(new DirectoryInfo(serverPath), new DirectoryInfo(testServerPath));

            var locator = new ConfigurableRavenServerLocator(testServerPath);

            return(await RunServer(locator));
        }
예제 #5
0
        private async Task <(Uri ServerUrl, Process ServerProcess)> RunServer(ConfigurableRavenServerLocator locator)
        {
            var process = RunServerProcess(locator);

            string url             = null;
            var    startupDuration = Stopwatch.StartNew();

            var outputString = await ReadOutput(process.StandardOutput, startupDuration, async (line, builder) =>
            {
                if (line == null)
                {
                    var errorString = await ReadOutput(process.StandardError, startupDuration, null).ConfigureAwait(false);

                    KillSlavedServerProcess(process);

                    throw new InvalidOperationException(BuildStartupExceptionMessage(builder.ToString(), errorString));
                }

                const string prefix = "Server available on: ";
                if (line.StartsWith(prefix))
                {
                    url = line.Substring(prefix.Length);
                    return(true);
                }

                return(false);
            }).ConfigureAwait(false);

            if (url == null)
            {
                var errorString = await ReadOutput(process.StandardError, startupDuration, null).ConfigureAwait(false);

                KillSlavedServerProcess(process);

                throw new InvalidOperationException(BuildStartupExceptionMessage(outputString, errorString));
            }

            return(new Uri(url), process);
        }
예제 #6
0
        protected async Task <DocumentStore> GetDocumentStoreAsync(
            string serverVersion,
            InterversionTestOptions options    = null,
            [CallerMemberName] string database = null,
            CancellationToken token            = default)
        {
            var serverBuildInfo = ServerBuildDownloadInfo.Create(serverVersion);
            var serverPath      = await _serverBuildRetriever.GetServerPath(serverBuildInfo, token);

            var testServerPath = NewDataPath(prefix: serverVersion);

            CopyFilesRecursively(new DirectoryInfo(serverPath), new DirectoryInfo(testServerPath));

            var locator = new ConfigurableRavenServerLocator(testServerPath);

            var(serverUrl, serverProcess) = await RunServer(locator);

            options = options ?? InterversionTestOptions.Default;
            var name = GetDatabaseName(database);

            if (options.ModifyDatabaseName != null)
            {
                name = options.ModifyDatabaseName(name) ?? name;
            }

            var doc = new DatabaseRecord(name)
            {
                Settings =
                {
                    [RavenConfiguration.GetKey(x => x.Replication.ReplicationMinimalHeartbeat)] = "1",
                    [RavenConfiguration.GetKey(x => x.Replication.RetryReplicateAfter)]         = "1",
                    [RavenConfiguration.GetKey(x => x.Core.RunInMemory)] = "true",
                    [RavenConfiguration.GetKey(x => x.Core.ThrowIfAnyIndexCannotBeOpened)] = "true",
                    [RavenConfiguration.GetKey(x => x.Indexing.MinNumberOfMapAttemptsAfterWhichBatchWillBeCanceledIfRunningLowOnMemory)] = int.MaxValue.ToString()
                }
            };

            options.ModifyDatabaseRecord?.Invoke(doc);

            var store = new DocumentStore
            {
                Urls     = new[] { serverUrl.ToString() },
                Database = name
            };

            options.ModifyDocumentStore?.Invoke(store);

            store.Initialize();

            if (options.CreateDatabase)
            {
                await store.Maintenance.Server.SendAsync(new CreateDatabaseOperation(doc, options.ReplicationFactor), token);
            }

            store.AfterDispose += (sender, e) =>
            {
                KillSlavedServerProcess(serverProcess);
            };

            return(store);
        }