public void Can_resolve_index_services_when_processing_index_queue()
        {
            var t1 = new EntityUpdateTask<Product>(new Product(), new ProductIndexDefinition(), new TestIndexLocation("products"));
            var t2 = new EntityUpdateTask<Product>(new Product(), new ProductIndexDefinition(), new TestIndexLocation("products"));
            var t3 = new EntityUpdateTask<Product>(new Product(), new ProductIndexDefinition(), new TestIndexLocation("products2"));

            Action<IIndexTask> queue = t => IndexQueue.Instance.Queue(t);

            queue(t1);
            queue(t2);
            queue(t3);

            var services = new HashSet<IIndexService>();

            IIndexTask task;
            while (IndexQueue.Instance.TryDequeue(out task))
            {
                var service = services.FindWithOptions(task.IndexOptions);

                if (service == null) {
                    service = new IndexService(new DirectoryIndexWriter(task.IndexOptions.IndexLocation.GetDirectory(), task.IndexOptions.RecreateIndex));
                    services.Add(service);
                }

                // process the task
            }

            Assert.IsTrue(services.Count == 2);
        }
        public void Can_resolve_index_services_when_processing_index_queue()
        {
            var t1 = new EntityUpdateTask <Product>(new Product(), new ProductIndexDefinition(), new TestIndexLocation("products"));
            var t2 = new EntityUpdateTask <Product>(new Product(), new ProductIndexDefinition(), new TestIndexLocation("products"));
            var t3 = new EntityUpdateTask <Product>(new Product(), new ProductIndexDefinition(), new TestIndexLocation("products2"));

            Action <IIndexTask> queue = t => IndexQueue.Instance.Queue(t);

            queue(t1);
            queue(t2);
            queue(t3);

            var services = new HashSet <IIndexService>();

            IIndexTask task;

            while (IndexQueue.Instance.TryDequeue(out task))
            {
                var service = services.FindWithOptions(task.IndexOptions);

                if (service == null)
                {
                    service = new IndexService(new DirectoryIndexWriter(task.IndexOptions.IndexLocation.GetDirectory(), task.IndexOptions.RecreateIndex));
                    services.Add(service);
                }

                // process the task
            }

            Assert.IsTrue(services.Count == 2);
        }
        public void Two_different_task_types_with_same_entity_should_not_be_equal()
        {
            var p1 = new Product { Id = 1 };

            var task1 = new ProductUpdateTask(p1);
            var task2 = new EntityUpdateTask<Product>(p1, new ProductIndexDefinition(), new TestIndexLocation());

            Assert.AreNotEqual(task1, task2);
        }
        private static EntityUpdateTask<Page> CreateEntityUpdateTask(Page page)
        {
            FileSystemIndexLocation indexLocation = new FileSystemIndexLocation(IndexDirectoryInfo);
            PageIndexDefinition definition = new PageIndexDefinition();
            EntityUpdateTask<Page> entityUpdateTask = new EntityUpdateTask<Page>(page, definition, indexLocation);

            IndexQueue.Instance.Queue(entityUpdateTask);
            return entityUpdateTask;
        }
Пример #5
0
        public void Two_different_task_types_with_same_entity_should_not_be_equal()
        {
            var p1 = new Product {
                Id = 1
            };

            var task1 = new ProductUpdateTask(p1);
            var task2 = new EntityUpdateTask <Product>(p1, new ProductIndexDefinition(), new TestIndexLocation());

            Assert.AreNotEqual(task1, task2);
        }
        public void Can_add_index_task_to_queue()
        {
            var task = new EntityUpdateTask<Product>(new Product(),
                new ProductIndexDefinition(), new TestIndexLocation());

            IndexQueue.Instance.Queue(task);

            Assert.IsTrue(IndexQueue.Instance.Contains(task));

            IIndexTask fromQueue;
            IndexQueue.Instance.TryDequeue(out fromQueue);

            Assert.AreEqual(task, fromQueue);
        }
        public void Can_add_index_task_to_queue()
        {
            var task = new EntityUpdateTask <Product>(new Product(),
                                                      new ProductIndexDefinition(), new TestIndexLocation());

            IndexQueue.Instance.Queue(task);

            Assert.IsTrue(IndexQueue.Instance.Contains(task));

            IIndexTask fromQueue;

            IndexQueue.Instance.TryDequeue(out fromQueue);

            Assert.AreEqual(task, fromQueue);
        }
Пример #8
0
        public void CreateIndex(Offers newOffer)
        {
            // index location
            var indexLocation = new FileSystemIndexLocation(new DirectoryInfo(Server.MapPath("~/Index")));
            var definition    = new OfferIndexDefinition();
            var task          = new EntityUpdateTask <Offers>(newOffer, definition, indexLocation);

            task.IndexOptions.RecreateIndex = false;
            task.IndexOptions.OptimizeIndex = true;
            //IndexQueue.Instance.Queue(task);
            var indexWriter = new DirectoryIndexWriter(new DirectoryInfo(Server.MapPath("~/Index")), false);

            using (var indexService = new IndexService(indexWriter))
            {
                task.Execute(indexService);
            }
        }
        public void CreateIndex(Offers newOffer)
        {
            // index location
            var indexLocation = new FileSystemIndexLocation(new DirectoryInfo(Server.MapPath("~/Index")));
            var definition = new OfferIndexDefinition();
            var task = new EntityUpdateTask<Offers>(newOffer, definition, indexLocation);
            task.IndexOptions.RecreateIndex = false;
            task.IndexOptions.OptimizeIndex = true;
            //IndexQueue.Instance.Queue(task);
            var indexWriter = new DirectoryIndexWriter(new DirectoryInfo(Server.MapPath("~/Index")), false);

            using (var indexService = new IndexService(indexWriter))
            {
                task.Execute(indexService);
            }
        }