@@ -0,0 +1,3187 @@
+/*%0A * Licensed to Elasticsearch under one or more contributor%0A * license agreements. See the NOTICE file distributed with%0A * this work for additional information regarding copyright%0A * ownership. Elasticsearch licenses this file to you under%0A * the Apache License, Version 2.0 (the %22License%22); you may%0A * not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage org.elasticsearch.common.lucene.index;%0A%0Aimport org.apache.lucene.document.Document;%0Aimport org.apache.lucene.document.Field;%0Aimport org.apache.lucene.document.StringField;%0Aimport org.apache.lucene.index.DirectoryReader;%0Aimport org.apache.lucene.index.IndexWriter;%0Aimport org.apache.lucene.index.IndexWriterConfig;%0Aimport org.apache.lucene.index.NoMergePolicy;%0Aimport org.apache.lucene.index.Term;%0Aimport org.apache.lucene.store.Directory;%0Aimport org.apache.lucene.util.IOUtils;%0Aimport org.elasticsearch.index.Index;%0Aimport org.elasticsearch.index.shard.ShardId;%0Aimport org.elasticsearch.test.ElasticsearchLuceneTestCase;%0A%0A/** Simple tests for this filterreader */%0Apublic class ElasticsearchDirectoryReaderTests extends ElasticsearchLuceneTestCase %7B%0A    %0A    /** Test that core cache key (needed for NRT) is working */%0A    public void testCoreCacheKey() throws Exception %7B%0A        Directory dir = newDirectory();%0A        IndexWriterConfig iwc = new IndexWriterConfig(null);%0A        iwc.setMaxBufferedDocs(100);%0A        iwc.setMergePolicy(NoMergePolicy.INSTANCE);%0A        IndexWriter iw = new IndexWriter(dir, iwc);%0A        %0A        // add two docs, id:0 and id:1%0A        Document doc = new Document();%0A        Field idField = new StringField(%22id%22, %22%22, Field.Store.NO);%0A        doc.add(idField);%0A        idField.setStringValue(%220%22);%0A        iw.addDocument(doc);%0A        idField.setStringValue(%221%22);%0A        iw.addDocument(doc);%0A        %0A        // open reader%0A        ShardId shardId = new ShardId(new Index(%22fake%22), 1);%0A        DirectoryReader ir = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(iw, true), shardId);%0A        assertEquals(2, ir.numDocs());%0A        assertEquals(1, ir.leaves().size());%0A%0A        // delete id:0 and reopen%0A        iw.deleteDocuments(new Term(%22id%22, %220%22));%0A        DirectoryReader ir2 = DirectoryReader.openIfChanged(ir);%0A        %0A        // we should have the same cache key as before%0A        assertEquals(1, ir2.numDocs());%0A        assertEquals(1, ir2.leaves().size());%0A        assertSame(ir.leaves().get(0).reader().getCoreCacheKey(), ir2.leaves().get(0).reader().getCoreCacheKey());%0A        %0A        // this is kind of stupid, but for now its here%0A        assertNotSame(ir.leaves().get(0).reader().getCombinedCoreAndDeletesKey(), ir2.leaves().get(0).reader().getCombinedCoreAndDeletesKey());%0A        %0A        IOUtils.close(ir, ir2, iw, dir);%0A    %7D%0A%7D%0A

Add test that ES filterreader getCoreCacheKey() behaves correctly.