Пример #1
0
        public void TestAddIndex()
        {
            var indexConfig = new IndexConfig
            {
                IndexName     = "ABC",
                MonitorFolder = MonitorFolder
            };

            using var management = new IndexManagement(Config, Log);
            CollectionAssert.IsEmpty(management.GetIndexList().Result);

            Assert.IsTrue(management.AddIndex(indexConfig).Status.Success);
            CollectionAssert.AreEquivalent(new[] { indexConfig.ToString() }, management.GetIndexList().Result.Select(u => u.IndexConfig.ToString()));

            Assert.IsFalse(management.AddIndex(indexConfig).Status.Success);
            Assert.IsFalse(management.AddIndex(indexConfig with {
                IndexName = null
            }).Status.Success);
            Assert.IsFalse(management.AddIndex(indexConfig with {
                IndexName = "BBB"
            }).Status.Success);
            Assert.IsFalse(management.AddIndex(indexConfig with {
                IndexName = "A".PadLeft(101, 'C')
            }).Status.Success);
            Assert.IsFalse(management.AddIndex(indexConfig with {
                Pk = Guid.NewGuid(), IndexName = "BBB", MonitorFolder = string.Empty
            }).Status.Success);
            Assert.IsFalse(management.AddIndex(indexConfig with {
                Pk = Guid.NewGuid(), IndexName = "BBB"
            }).Status.Success);
            Assert.IsFalse(management.AddIndex(indexConfig with {
                Pk = Guid.NewGuid(), IndexName = "BBB", MonitorFolder = "Dummy"
            }).Status.Success);
            CollectionAssert.AreEquivalent(new[] { indexConfig.ToString() }, management.GetIndexList().Result.Select(u => u.IndexConfig.ToString()));
        }
Пример #2
0
        public InitManagement(string monitorFolder, CodeIndexConfiguration codeIndexConfiguration, bool initFiles = false, int maxContentHighlightLength = Constants.DefaultMaxContentHighlightLength)
        {
            indexConfig = new IndexConfig
            {
                IndexName                 = "ABC",
                MonitorFolder             = monitorFolder,
                MaxContentHighlightLength = maxContentHighlightLength
            };

            if (initFiles)
            {
                var fileName1 = Path.Combine(monitorFolder, "A.txt");
                var fileName2 = Path.Combine(monitorFolder, "B.txt");
                var fileName3 = Path.Combine(monitorFolder, "C.txt");
                File.AppendAllText(fileName1, "ABCD");
                File.AppendAllText(fileName2, "ABCD EFGH");
                File.AppendAllText(fileName3, "ABCD EFGH IJKL" + Environment.NewLine + "ABCD ABCE");
            }

            management = new IndexManagement(codeIndexConfiguration, log1);
            management.AddIndex(indexConfig);
            var maintainer = management.GetIndexMaintainerWrapperAndInitializeIfNeeded(indexConfig.Pk);

            // Wait initialized finished
            while (maintainer.Result.Status == IndexStatus.Initializing_ComponentInitializeFinished || maintainer.Result.Status == IndexStatus.Initialized)
            {
                Thread.Sleep(100);
            }
        }
Пример #3
0
        public void TestConstructor_InitializeMaintainerPool()
        {
            var indexConfig = new IndexConfig
            {
                IndexName     = "ABC",
                MonitorFolder = MonitorFolder
            };

            using var management1 = new IndexManagement(Config, Log);
            CollectionAssert.IsEmpty(management1.GetIndexList().Result);

            management1.AddIndex(indexConfig);

            management1.Dispose();
            using var management2 = new IndexManagement(Config, Log);
            CollectionAssert.AreEquivalent(new[] { indexConfig.ToString() }, management2.GetIndexList().Result.Select(u => u.IndexConfig.ToString()));
        }
Пример #4
0
 public async Task <FetchResult <bool> > AddIndex(IndexConfig indexConfig, [FromServices] IndexManagement indexManagement)
 {
     return(await Task.FromResult(indexManagement.AddIndex(indexConfig)));
 }