public void Should_Report_Unsuccessful_Connection_to_Nonexistant_Database()
        {
            //Create a connection string using a random guid as the name of a local database
            var connectionString = RavenConnectionStringBuilder.BuildConnectionString("http://localhost:8080",
                                                                                      Guid.NewGuid().ToString());
            //Build our command object
            var commandObject = new IndexBuildCommand()
            {
                AssemblyPaths = new string[] { TestHelper.ValidTestAssemblyPath },
                ConnectionStrings = new string[]{connectionString}
            };

            var indexManager = new IndexJobManager(commandObject);

            try
            {
                //Attempt to connect to our databases
                var connectionReport = indexManager.CanConnectToDbs();
                Assert.AreEqual(1, connectionReport.JobResults.Count);
                Assert.AreEqual(0, connectionReport.Successes);
                Assert.AreEqual(1, connectionReport.Failures);
            }
            catch (InvalidOperationException ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                indexManager.Dispose();
            }
        }
        public void Should_Report_Successful_Connection_to_Embedded_Database()
        {
            var commandObject = new IndexBuildCommand()
                                    {
                                        AssemblyPaths = new string[] {TestHelper.ValidTestAssemblyPath},
                                        UseEmbedded = true
                                    };

            var indexManager = new IndexJobManager(commandObject);

            try
            {
                //Attempt to connect to our databases
                var connectionReport = indexManager.CanConnectToDbs();
                Assert.AreEqual(1, connectionReport.JobResults.Count);
                Assert.AreEqual(connectionReport.JobResults.Count, connectionReport.Successes);
            }catch(InvalidOperationException ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                indexManager.Dispose();
            }
        }
        public void Should_Report_Unsuccessful_Load_For_NonExistant_Assembly()
        {
            var commandObject = new IndexBuildCommand()
            {
                AssemblyPaths = new string[] { TestHelper.InvalidAssemblyPath },
                UseEmbedded = true
            };

            var indexManager = new IndexJobManager(commandObject);
            try
            {
                var assemblyLoadReport = indexManager.CanLoadAssemblies();
                Assert.AreEqual(commandObject.AssemblyPaths.Count(), assemblyLoadReport.JobResults.Count);
                Assert.AreEqual(0, assemblyLoadReport.Successes);
                Assert.AreEqual(commandObject.AssemblyPaths.Count(), assemblyLoadReport.Failures);
                Assert.IsNotNull(assemblyLoadReport.JobResults.First().JobException);
                Assert.IsInstanceOf<FileNotFoundException>(assemblyLoadReport.JobResults.First().JobException);
            }
            catch (InvalidOperationException ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                indexManager.Dispose();
            }
        }
        public void Should_Report_Successful_Load_For_Valid_Assembly_Containing_RavenDB_Index_Definitions()
        {
            var commandObject = new IndexBuildCommand()
            {
                AssemblyPaths = new string[] { TestHelper.ValidTestAssemblyPath },
                UseEmbedded = true
            };

            var indexManager = new IndexJobManager(commandObject);
            try
            {
                var assemblyLoadReport = indexManager.CanLoadAssemblies();
                Assert.AreEqual(commandObject.AssemblyPaths.Count(), assemblyLoadReport.JobResults.Count);
                Assert.AreEqual(commandObject.AssemblyPaths.Count(), assemblyLoadReport.Successes);
            }catch(InvalidOperationException ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                indexManager.Dispose();
            }
        }
示例#5
0
        /// <summary>
        /// Asynchronous method for running a batch index creation job against a database
        /// </summary>
        /// <param name="progressCallBack">callback method for reporting on the progress of the job</param>
        /// <returns>A task which returns a completed IndexBuildReport covering all of the indexes found in the assembly</returns>
        public Task<IndexBuildReport> RunAsync(IndexBuildCommand buildInstructions, Action<IndexBuildResult> progressCallBack)
        {
            //Load our indexes
            var indexes = GetIndexesFromLoadedAssemblies();
            var tasks = new List<Task<IndexBuildResult>>();

            foreach (var index in indexes)
            {
                var indexInstance = (AbstractIndexCreationTask)Activator.CreateInstance(index);
                tasks.Add(BuildIndexAsync(indexInstance, progressCallBack));
            }

            if (buildInstructions.DropInactiveVersionedIndexes)
            {
                var versionedIndexes = GetVersionedIndexesFromLoadedAssemblies();
                foreach (var indexType in versionedIndexes)
                {
                    var index = (AbstractIndexCreationTask)Activator.CreateInstance(indexType);
                    var nonVersionedIndexName = ((IVersionedIndex)index).GetIndexNameWithoutVersion();
                    var inactiveIndexes = _documentStore.DatabaseCommands
                                            .GetStatistics()
                                            .Indexes
                                            .Where(x => x.Name.StartsWith(nonVersionedIndexName) &&
                                                        x.Name.Equals(index.IndexName) == false
                                            ).ToList();

                    foreach (var indexToDrop in inactiveIndexes)
                    {
                        tasks.Add(DropIndexAsync(indexToDrop.Name, progressCallBack));
                    }
                }
            }

            return Task.Factory.ContinueWhenAll(tasks.ToArray(), cont =>
            {
                var buildReport = new IndexBuildReport()
                {
                    BuildResults = tasks.Select(x => x.Result).ToList()
                };

                return buildReport;
            });
        }
示例#6
0
        /// <summary>
        /// Synchronous method for running a batch index creation job against a database
        /// </summary>
        /// <param name="progressCallBack">callback method for reporting on the progress of the job</param>
        /// <returns>A completed IndexBuildReport covering all of the indexes found in the assembly</returns>
        public IndexBuildReport Run(IndexBuildCommand buildInstructions, Action<IndexBuildResult> progressCallBack)
        {
            var task = RunAsync(buildInstructions, progressCallBack);

            //Wait out all of the tasks
            task.Wait();
            return task.Result;
        }