@Test public void testSegments() throws Exception { List<Segment> segments = engine.segments(); assertThat(segments.isEmpty(), equalTo(true)); final boolean defaultCompound = defaultSettings.getAsBoolean(RobinEngine.INDEX_COMPOUND_ON_FLUSH, true); // create a doc and refresh ParsedDocument doc = testParsedDocument( "1", "1", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_1, false); engine.create(new Engine.Create(null, newUid("1"), doc)); ParsedDocument doc2 = testParsedDocument( "2", "2", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_2, false); engine.create(new Engine.Create(null, newUid("2"), doc2)); engine.refresh(new Engine.Refresh(true)); segments = engine.segments(); assertThat(segments.size(), equalTo(1)); assertThat(segments.get(0).isCommitted(), equalTo(false)); assertThat(segments.get(0).isSearch(), equalTo(true)); assertThat(segments.get(0).getNumDocs(), equalTo(2)); assertThat(segments.get(0).getDeletedDocs(), equalTo(0)); assertThat(segments.get(0).isCompound(), equalTo(defaultCompound)); engine.flush(new Engine.Flush()); segments = engine.segments(); assertThat(segments.size(), equalTo(1)); assertThat(segments.get(0).isCommitted(), equalTo(true)); assertThat(segments.get(0).isSearch(), equalTo(true)); assertThat(segments.get(0).getNumDocs(), equalTo(2)); assertThat(segments.get(0).getDeletedDocs(), equalTo(0)); assertThat(segments.get(0).isCompound(), equalTo(defaultCompound)); engineSettingsService.refreshSettings( ImmutableSettings.builder().put(RobinEngine.INDEX_COMPOUND_ON_FLUSH, false).build()); ParsedDocument doc3 = testParsedDocument( "3", "3", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_3, false); engine.create(new Engine.Create(null, newUid("3"), doc3)); engine.refresh(new Engine.Refresh(true)); segments = engine.segments(); assertThat(segments.size(), equalTo(2)); assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true)); assertThat(segments.get(0).isCommitted(), equalTo(true)); assertThat(segments.get(0).isSearch(), equalTo(true)); assertThat(segments.get(0).getNumDocs(), equalTo(2)); assertThat(segments.get(0).getDeletedDocs(), equalTo(0)); assertThat(segments.get(0).isCompound(), equalTo(defaultCompound)); assertThat(segments.get(1).isCommitted(), equalTo(false)); assertThat(segments.get(1).isSearch(), equalTo(true)); assertThat(segments.get(1).getNumDocs(), equalTo(1)); assertThat(segments.get(1).getDeletedDocs(), equalTo(0)); assertThat(segments.get(1).isCompound(), equalTo(false)); engine.delete(new Engine.Delete("test", "1", newUid("1"))); engine.refresh(new Engine.Refresh(true)); segments = engine.segments(); assertThat(segments.size(), equalTo(2)); assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true)); assertThat(segments.get(0).isCommitted(), equalTo(true)); assertThat(segments.get(0).isSearch(), equalTo(true)); assertThat(segments.get(0).getNumDocs(), equalTo(1)); assertThat(segments.get(0).getDeletedDocs(), equalTo(1)); assertThat(segments.get(0).isCompound(), equalTo(defaultCompound)); assertThat(segments.get(1).isCommitted(), equalTo(false)); assertThat(segments.get(1).isSearch(), equalTo(true)); assertThat(segments.get(1).getNumDocs(), equalTo(1)); assertThat(segments.get(1).getDeletedDocs(), equalTo(0)); assertThat(segments.get(1).isCompound(), equalTo(false)); engineSettingsService.refreshSettings( ImmutableSettings.builder().put(RobinEngine.INDEX_COMPOUND_ON_FLUSH, true).build()); ParsedDocument doc4 = testParsedDocument( "4", "4", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_3, false); engine.create(new Engine.Create(null, newUid("4"), doc4)); engine.refresh(new Engine.Refresh(true)); segments = engine.segments(); assertThat(segments.size(), equalTo(3)); assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true)); assertThat(segments.get(0).isCommitted(), equalTo(true)); assertThat(segments.get(0).isSearch(), equalTo(true)); assertThat(segments.get(0).getNumDocs(), equalTo(1)); assertThat(segments.get(0).getDeletedDocs(), equalTo(1)); assertThat(segments.get(0).isCompound(), equalTo(defaultCompound)); assertThat(segments.get(1).isCommitted(), equalTo(false)); assertThat(segments.get(1).isSearch(), equalTo(true)); assertThat(segments.get(1).getNumDocs(), equalTo(1)); assertThat(segments.get(1).getDeletedDocs(), equalTo(0)); assertThat(segments.get(1).isCompound(), equalTo(false)); assertThat(segments.get(2).isCommitted(), equalTo(false)); assertThat(segments.get(2).isSearch(), equalTo(true)); assertThat(segments.get(2).getNumDocs(), equalTo(1)); assertThat(segments.get(2).getDeletedDocs(), equalTo(0)); assertThat(segments.get(2).isCompound(), equalTo(true)); }
@Test public void testSegments() throws Exception { List<Segment> segments = engine.segments(); assertThat(segments.isEmpty(), equalTo(true)); // create a doc and refresh ParsedDocument doc = testParsedDocument( "1", "1", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_1, false); engine.create(new Engine.Create(null, newUid("1"), doc)); ParsedDocument doc2 = testParsedDocument( "2", "2", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_2, false); engine.create(new Engine.Create(null, newUid("2"), doc2)); engine.refresh(new Engine.Refresh(true)); segments = engine.segments(); assertThat(segments.size(), equalTo(1)); assertThat(segments.get(0).committed(), equalTo(false)); assertThat(segments.get(0).search(), equalTo(true)); assertThat(segments.get(0).numDocs(), equalTo(2)); assertThat(segments.get(0).deletedDocs(), equalTo(0)); engine.flush(new Engine.Flush()); segments = engine.segments(); assertThat(segments.size(), equalTo(1)); assertThat(segments.get(0).committed(), equalTo(true)); assertThat(segments.get(0).search(), equalTo(true)); assertThat(segments.get(0).numDocs(), equalTo(2)); assertThat(segments.get(0).deletedDocs(), equalTo(0)); ParsedDocument doc3 = testParsedDocument( "3", "3", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_3, false); engine.create(new Engine.Create(null, newUid("3"), doc3)); engine.refresh(new Engine.Refresh(true)); segments = engine.segments(); assertThat(segments.size(), equalTo(2)); assertThat(segments.get(0).generation() < segments.get(1).generation(), equalTo(true)); assertThat(segments.get(0).committed(), equalTo(true)); assertThat(segments.get(0).search(), equalTo(true)); assertThat(segments.get(0).numDocs(), equalTo(2)); assertThat(segments.get(0).deletedDocs(), equalTo(0)); assertThat(segments.get(1).committed(), equalTo(false)); assertThat(segments.get(1).search(), equalTo(true)); assertThat(segments.get(1).numDocs(), equalTo(1)); assertThat(segments.get(1).deletedDocs(), equalTo(0)); engine.delete(new Engine.Delete("test", "1", newUid("1"))); engine.refresh(new Engine.Refresh(true)); segments = engine.segments(); assertThat(segments.size(), equalTo(2)); assertThat(segments.get(0).generation() < segments.get(1).generation(), equalTo(true)); assertThat(segments.get(0).committed(), equalTo(true)); assertThat(segments.get(0).search(), equalTo(true)); assertThat(segments.get(0).numDocs(), equalTo(1)); assertThat(segments.get(0).deletedDocs(), equalTo(1)); assertThat(segments.get(1).committed(), equalTo(false)); assertThat(segments.get(1).search(), equalTo(true)); assertThat(segments.get(1).numDocs(), equalTo(1)); assertThat(segments.get(1).deletedDocs(), equalTo(0)); }