Original commit: elastic/x-pack-elasticsearch@862180a169
This commit is contained in:
Martijn van Groningen 2017-04-26 11:27:48 +02:00
parent aa421af2fc
commit c6c63c471c
2 changed files with 14 additions and 5 deletions

View File

@ -25,6 +25,7 @@ import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.Bits; import org.apache.lucene.util.Bits;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
@ -34,6 +35,8 @@ import org.elasticsearch.test.IndexSettingsModule;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import java.io.IOException;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -91,7 +94,7 @@ public class DocumentSubsetReaderTests extends ESTestCase {
iw.forceMerge(1); iw.forceMerge(1);
iw.deleteDocuments(new Term("field", "value3")); iw.deleteDocuments(new Term("field", "value3"));
iw.close(); iw.close();
directoryReader = DirectoryReader.open(directory); openDirectoryReader();
IndexSearcher indexSearcher = new IndexSearcher(DocumentSubsetReader.wrap(directoryReader, bitsetFilterCache, IndexSearcher indexSearcher = new IndexSearcher(DocumentSubsetReader.wrap(directoryReader, bitsetFilterCache,
new TermQuery(new Term("field", "value1")))); new TermQuery(new Term("field", "value1"))));
@ -138,7 +141,7 @@ public class DocumentSubsetReaderTests extends ESTestCase {
iw.forceMerge(1); iw.forceMerge(1);
iw.close(); iw.close();
directoryReader = DirectoryReader.open(directory); openDirectoryReader();
assertThat("should have one segment after force merge", directoryReader.leaves().size(), equalTo(1)); assertThat("should have one segment after force merge", directoryReader.leaves().size(), equalTo(1));
for (int i = 0; i < numDocs; i++) { for (int i = 0; i < numDocs; i++) {
@ -207,7 +210,8 @@ public class DocumentSubsetReaderTests extends ESTestCase {
iw.addDocument(doc); iw.addDocument(doc);
// open reader // open reader
DirectoryReader ir = DocumentSubsetReader.wrap(DirectoryReader.open(iw), bitsetFilterCache, new MatchAllDocsQuery()); DirectoryReader ir = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(iw), new ShardId("_index", "_na_", 0));
ir = DocumentSubsetReader.wrap(ir, bitsetFilterCache, new MatchAllDocsQuery());
assertEquals(2, ir.numDocs()); assertEquals(2, ir.numDocs());
assertEquals(1, ir.leaves().size()); assertEquals(1, ir.leaves().size());
@ -224,4 +228,9 @@ public class DocumentSubsetReaderTests extends ESTestCase {
TestUtil.checkReader(ir); TestUtil.checkReader(ir);
IOUtils.close(ir, ir2, iw, dir); IOUtils.close(ir, ir2, iw, dir);
} }
private void openDirectoryReader() throws IOException {
directoryReader = DirectoryReader.open(directory);
directoryReader = ElasticsearchDirectoryReader.wrap(directoryReader, new ShardId("_index", "_na_", 0));
}
} }

View File

@ -597,8 +597,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
} }
w.deleteDocuments(new Term("delete", "yes")); w.deleteDocuments(new Term("delete", "yes"));
DirectoryReader reader = DirectoryReader.open(w); IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY);
IndexSettings settings = IndexSettingsModule.newIndexSettings("index", Settings.EMPTY);
BitsetFilterCache.Listener listener = new BitsetFilterCache.Listener() { BitsetFilterCache.Listener listener = new BitsetFilterCache.Listener() {
@Override @Override
public void onCache(ShardId shardId, Accountable accountable) { public void onCache(ShardId shardId, Accountable accountable) {
@ -610,6 +609,7 @@ public class SecurityIndexSearcherWrapperUnitTests extends ESTestCase {
} }
}; };
DirectoryReader reader = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(w), new ShardId(indexSettings.getIndex(), 0));
BitsetFilterCache cache = new BitsetFilterCache(settings, listener); BitsetFilterCache cache = new BitsetFilterCache(settings, listener);
Query roleQuery = new TermQuery(new Term("allowed", "yes")); Query roleQuery = new TermQuery(new Term("allowed", "yes"));
BitSet bitSet = cache.getBitSetProducer(roleQuery).getBitSet(reader.leaves().get(0)); BitSet bitSet = cache.getBitSetProducer(roleQuery).getBitSet(reader.leaves().get(0));