mirror of https://github.com/apache/lucene.git
LUCENE-5969: let AssertingCodec implement RandomAccessOrds, and test it directly too
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1626826 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8a69b1d6cb
commit
6efd37464f
|
@ -0,0 +1,31 @@
|
|||
package org.apache.lucene.codecs.asserting;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.index.BasePostingsFormatTestCase;
|
||||
|
||||
/** Test AssertingPostingsFormat directly */
|
||||
public class TestAssertingDocValuesFormat extends BasePostingsFormatTestCase {
|
||||
private final Codec codec = new AssertingCodec();
|
||||
|
||||
@Override
|
||||
protected Codec getCodec() {
|
||||
return codec;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.apache.lucene.codecs.asserting;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.index.BaseNormsFormatTestCase;
|
||||
|
||||
/** Test AssertingNormsFormat directly */
|
||||
public class TestAssertingNormsFormat extends BaseNormsFormatTestCase {
|
||||
private final Codec codec = new AssertingCodec();
|
||||
|
||||
@Override
|
||||
protected Codec getCodec() {
|
||||
return codec;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.apache.lucene.codecs.asserting;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.index.BaseDocValuesFormatTestCase;
|
||||
|
||||
/** Test AssertingDocValuesFormat directly */
|
||||
public class TestAssertingPostingsFormat extends BaseDocValuesFormatTestCase {
|
||||
private final Codec codec = new AssertingCodec();
|
||||
|
||||
@Override
|
||||
protected Codec getCodec() {
|
||||
return codec;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.apache.lucene.codecs.asserting;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.index.BaseTermVectorsFormatTestCase;
|
||||
|
||||
/** Test AssertingTermVectorsFormat directly */
|
||||
public class TestAssertingStoredFieldsFormat extends BaseTermVectorsFormatTestCase {
|
||||
private final Codec codec = new AssertingCodec();
|
||||
|
||||
@Override
|
||||
protected Codec getCodec() {
|
||||
return codec;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package org.apache.lucene.codecs.asserting;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.index.BaseStoredFieldsFormatTestCase;
|
||||
|
||||
/** Test AssertingStoredFieldsFormat directly */
|
||||
public class TestAssertingTermVectorsFormat extends BaseStoredFieldsFormatTestCase {
|
||||
private final Codec codec = new AssertingCodec();
|
||||
|
||||
@Override
|
||||
protected Codec getCodec() {
|
||||
return codec;
|
||||
}
|
||||
}
|
|
@ -17,9 +17,6 @@ package org.apache.lucene.search;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.codecs.Codec;
|
||||
import org.apache.lucene.codecs.lucene410.Lucene410DocValuesFormat;
|
||||
import org.apache.lucene.codecs.memory.DirectDocValuesFormat;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.SortedSetDocValuesField;
|
||||
|
@ -28,30 +25,12 @@ import org.apache.lucene.index.RandomIndexWriter;
|
|||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
||||
|
||||
/** Tests for SortedSetSortField selectors other than MIN,
|
||||
* these require optional codec support (random access to ordinals) */
|
||||
@SuppressCodecs("Memory") // TODO: fix MemoryDV to support random access to ordinals
|
||||
public class TestSortedSetSelector extends LuceneTestCase {
|
||||
static Codec savedCodec;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
savedCodec = Codec.getDefault();
|
||||
// currently only these codecs that support random access ordinals
|
||||
int victim = random().nextInt(2);
|
||||
switch(victim) {
|
||||
case 0: Codec.setDefault(TestUtil.alwaysDocValuesFormat(new DirectDocValuesFormat())); break;
|
||||
default: Codec.setDefault(TestUtil.alwaysDocValuesFormat(new Lucene410DocValuesFormat()));
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
Codec.setDefault(savedCodec);
|
||||
}
|
||||
|
||||
public void testMax() throws Exception {
|
||||
Directory dir = newDirectory();
|
||||
|
|
|
@ -28,11 +28,14 @@ import org.apache.lucene.index.AssertingAtomicReader;
|
|||
import org.apache.lucene.index.BinaryDocValues;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.NumericDocValues;
|
||||
import org.apache.lucene.index.RandomAccessOrds;
|
||||
import org.apache.lucene.index.SegmentReadState;
|
||||
import org.apache.lucene.index.SegmentWriteState;
|
||||
import org.apache.lucene.index.SortedDocValues;
|
||||
import org.apache.lucene.index.SortedNumericDocValues;
|
||||
import org.apache.lucene.index.SortedSetDocValues;
|
||||
import org.apache.lucene.index.AssertingAtomicReader.AssertingRandomAccessOrds;
|
||||
import org.apache.lucene.index.AssertingAtomicReader.AssertingSortedSetDocValues;
|
||||
import org.apache.lucene.util.Accountable;
|
||||
import org.apache.lucene.util.Bits;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
@ -258,7 +261,11 @@ public class AssertingDocValuesFormat extends DocValuesFormat {
|
|||
assert field.getDocValuesType() == FieldInfo.DocValuesType.SORTED_SET;
|
||||
SortedSetDocValues values = in.getSortedSet(field);
|
||||
assert values != null;
|
||||
return new AssertingAtomicReader.AssertingSortedSetDocValues(values, maxDoc);
|
||||
if (values instanceof RandomAccessOrds) {
|
||||
return new AssertingRandomAccessOrds((RandomAccessOrds) values, maxDoc);
|
||||
} else {
|
||||
return new AssertingSortedSetDocValues(values, maxDoc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -546,6 +546,77 @@ public class AssertingAtomicReader extends FilterAtomicReader {
|
|||
}
|
||||
}
|
||||
|
||||
/** Wraps a RandomAccessOrds but with additional asserts */
|
||||
public static class AssertingRandomAccessOrds extends RandomAccessOrds {
|
||||
private final RandomAccessOrds in;
|
||||
private final int maxDoc;
|
||||
private final long valueCount;
|
||||
long lastOrd = NO_MORE_ORDS;
|
||||
|
||||
public AssertingRandomAccessOrds(RandomAccessOrds in, int maxDoc) {
|
||||
this.in = in;
|
||||
this.maxDoc = maxDoc;
|
||||
this.valueCount = in.getValueCount();
|
||||
assert valueCount >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextOrd() {
|
||||
assert lastOrd != NO_MORE_ORDS;
|
||||
long ord = in.nextOrd();
|
||||
assert ord < valueCount;
|
||||
assert ord == NO_MORE_ORDS || ord > lastOrd;
|
||||
lastOrd = ord;
|
||||
return ord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDocument(int docID) {
|
||||
assert docID >= 0 && docID < maxDoc : "docid=" + docID + ",maxDoc=" + maxDoc;
|
||||
in.setDocument(docID);
|
||||
lastOrd = -2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesRef lookupOrd(long ord) {
|
||||
assert ord >= 0 && ord < valueCount;
|
||||
final BytesRef result = in.lookupOrd(ord);
|
||||
assert result.isValid();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getValueCount() {
|
||||
long valueCount = in.getValueCount();
|
||||
assert valueCount == this.valueCount; // should not change
|
||||
return valueCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lookupTerm(BytesRef key) {
|
||||
assert key.isValid();
|
||||
long result = in.lookupTerm(key);
|
||||
assert result < valueCount;
|
||||
assert key.isValid();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long ordAt(int index) {
|
||||
assert index < in.cardinality();
|
||||
long ord = in.ordAt(index);
|
||||
assert ord >= 0 && ord < valueCount;
|
||||
return ord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cardinality() {
|
||||
int cardinality = in.cardinality();
|
||||
assert cardinality >= 0;
|
||||
return cardinality;
|
||||
}
|
||||
}
|
||||
|
||||
/** Wraps a SortedSetDocValues but with additional asserts */
|
||||
public static class AssertingSortedSetDocValues extends SortedSetDocValues {
|
||||
private final SortedSetDocValues in;
|
||||
|
@ -665,7 +736,11 @@ public class AssertingAtomicReader extends FilterAtomicReader {
|
|||
if (dv != null) {
|
||||
assert fi != null;
|
||||
assert fi.getDocValuesType() == FieldInfo.DocValuesType.SORTED_SET;
|
||||
return new AssertingSortedSetDocValues(dv, maxDoc());
|
||||
if (dv instanceof RandomAccessOrds) {
|
||||
return new AssertingRandomAccessOrds((RandomAccessOrds) dv, maxDoc());
|
||||
} else {
|
||||
return new AssertingSortedSetDocValues(dv, maxDoc());
|
||||
}
|
||||
} else {
|
||||
assert fi == null || fi.getDocValuesType() != FieldInfo.DocValuesType.SORTED_SET;
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue