Example #1
0
        public void TestRevisionRelease()
        {
            Directory         indexDir = NewDirectory();
            IndexWriterConfig conf     = new IndexWriterConfig(TEST_VERSION_CURRENT, null);

            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            IndexWriter indexWriter = new IndexWriter(indexDir, conf);

            Directory taxoDir = NewDirectory();

            IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter taxoWriter = new IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter(taxoDir);
            try
            {
                indexWriter.AddDocument(NewDocument(taxoWriter));
                indexWriter.Commit();
                taxoWriter.Commit();
                IRevision rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
                // releasing that revision should not delete the files
                rev1.Release();
                assertTrue(SlowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
                assertTrue(SlowFileExists(taxoDir, IndexFileNames.SEGMENTS + "_1"));

                rev1 = new IndexAndTaxonomyRevision(indexWriter, taxoWriter); // create revision again, so the files are snapshotted
                indexWriter.AddDocument(NewDocument(taxoWriter));
                indexWriter.Commit();
                taxoWriter.Commit();
                assertNotNull(new IndexAndTaxonomyRevision(indexWriter, taxoWriter));
                rev1.Release(); // this release should trigger the delete of segments_1
                assertFalse(SlowFileExists(indexDir, IndexFileNames.SEGMENTS + "_1"));
            }
            finally
            {
                IOUtils.Dispose(indexWriter, taxoWriter, taxoDir, indexDir);
            }
        }
Example #2
0
        public void TestSegmentsFileLast()
        {
            Directory         indexDir = NewDirectory();
            IndexWriterConfig conf     = new IndexWriterConfig(TEST_VERSION_CURRENT, null);

            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            IndexWriter indexWriter = new IndexWriter(indexDir, conf);

            Directory taxoDir = NewDirectory();

            IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter taxoWriter = new IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter(taxoDir);
            try
            {
                indexWriter.AddDocument(NewDocument(taxoWriter));
                indexWriter.Commit();
                taxoWriter.Commit();
                IRevision rev         = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
                var       sourceFiles = rev.SourceFiles;
                assertEquals(2, sourceFiles.Count);
                foreach (var files in sourceFiles.Values)
                {
                    string lastFile = files.Last().FileName;
                    assertTrue(lastFile.StartsWith(IndexFileNames.SEGMENTS, StringComparison.Ordinal) && !lastFile.Equals(IndexFileNames.SEGMENTS_GEN, StringComparison.Ordinal));
                }
            }
            finally
            {
                IOUtils.Dispose(indexWriter, taxoWriter, taxoDir, indexDir);
            }
        }
Example #3
0
        public void TestNoCommit()
        {
            Directory         indexDir = NewDirectory();
            IndexWriterConfig conf     = new IndexWriterConfig(TEST_VERSION_CURRENT, null);

            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            IndexWriter indexWriter = new IndexWriter(indexDir, conf);

            Directory taxoDir = NewDirectory();

            IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter taxoWriter = new IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter(taxoDir);
            try
            {
                assertNotNull(new IndexAndTaxonomyRevision(indexWriter, taxoWriter));
                fail("should have failed when there are no commits to snapshot");
            }
            catch (InvalidOperationException)
            {
                // expected
            }
            finally
            {
                IOUtils.Dispose(indexWriter, taxoWriter, taxoDir, indexDir);
            }
        }
        public void TestOpen()
        {
            Directory         indexDir = NewDirectory();
            IndexWriterConfig conf     = new IndexWriterConfig(TEST_VERSION_CURRENT, null);

            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            IndexWriter indexWriter = new IndexWriter(indexDir, conf);

            Directory taxoDir = NewDirectory();

            IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter taxoWriter = new IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter(taxoDir);
            try
            {
                indexWriter.AddDocument(NewDocument(taxoWriter));
                indexWriter.Commit();
                taxoWriter.Commit();
                IRevision rev = new IndexAndTaxonomyRevision(indexWriter, taxoWriter);
                foreach (var e in rev.SourceFiles)
                {
                    string    source = e.Key;
                    Directory dir    = source.Equals(IndexAndTaxonomyRevision.INDEX_SOURCE, StringComparison.Ordinal) ? indexDir : taxoDir;
                    foreach (RevisionFile file in e.Value)
                    {
                        using (IndexInput src = dir.OpenInput(file.FileName, IOContext.READ_ONCE))
                            using (System.IO.Stream @in = rev.Open(source, file.FileName))
                            {
                                assertEquals(src.Length, @in.Length);
                                byte[] srcBytes = new byte[(int)src.Length];
                                byte[] inBytes  = new byte[(int)src.Length];
                                int    offset   = 0;
                                if (Random.nextBoolean())
                                {
                                    int skip = Random.Next(10);
                                    if (skip >= src.Length)
                                    {
                                        skip = 0;
                                    }
                                    @in.Seek(skip, SeekOrigin.Current);
                                    src.Seek(skip);
                                    offset = skip;
                                }
                                src.ReadBytes(srcBytes, offset, srcBytes.Length - offset);
                                @in.Read(inBytes, offset, inBytes.Length - offset);
                                assertArrayEquals(srcBytes, inBytes);
                            }
                    }
                }
            }
            finally
            {
                IOUtils.Dispose(indexWriter, taxoWriter, taxoDir, indexDir);
            }
        }
        public override void SetUp()
        {
            base.SetUp();

            publishIndexDir = NewDirectory();
            publishTaxoDir = NewDirectory();
            handlerIndexDir = NewMockDirectory();
            handlerTaxoDir = NewMockDirectory();
            clientWorkDir = CreateTempDir("replicationClientTest");
            sourceDirFactory = new PerSessionDirectoryFactory(clientWorkDir.FullName);
            replicator = new LocalReplicator();
            callback = new IndexAndTaxonomyReadyCallback(handlerIndexDir, handlerTaxoDir);
            handler = new IndexAndTaxonomyReplicationHandler(handlerIndexDir, handlerTaxoDir, callback.Call);
            client = new ReplicationClient(replicator, handler, sourceDirFactory);

            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, null);
            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            publishIndexWriter = new IndexWriter(publishIndexDir, conf);
            publishTaxoWriter = new IndexAndTaxonomyRevision.SnapshotDirectoryTaxonomyWriter(publishTaxoDir);
            config = new FacetsConfig();
            config.SetHierarchical("A", true);
        }