Test that size is actually computed.

Relates to #2882
This commit is contained in:
Martijn van Groningen 2013-04-11 10:22:48 +02:00
parent 9a2d27a035
commit 2dfcc3c740
2 changed files with 17 additions and 21 deletions

View File

@ -19,21 +19,12 @@
package org.elasticsearch.test.unit.index.fielddata;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.search.*;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.index.fielddata.AtomicFieldData;
@ -42,6 +33,9 @@ import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.fieldcomparator.SortMode;
import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
*/
@Test
@ -93,6 +87,7 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
IndexFieldData indexFieldData = getForField("value");
AtomicReaderContext readerContext = refreshReader();
AtomicFieldData fieldData = indexFieldData.load(readerContext);
assertThat(fieldData.getMemorySizeInBytes(), greaterThan(0l));
assertThat(fieldData.getNumDocs(), equalTo(3));
@ -185,6 +180,7 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
fillSingleValueWithMissing();
IndexFieldData indexFieldData = getForField("value");
AtomicFieldData fieldData = indexFieldData.load(refreshReader());
assertThat(fieldData.getMemorySizeInBytes(), greaterThan(0l));
assertThat(fieldData.getNumDocs(), equalTo(3));
@ -263,6 +259,7 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
fillMultiValueAllSet();
IndexFieldData indexFieldData = getForField("value");
AtomicFieldData fieldData = indexFieldData.load(refreshReader());
assertThat(fieldData.getMemorySizeInBytes(), greaterThan(0l));
assertThat(fieldData.getNumDocs(), equalTo(3));
@ -350,6 +347,7 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
fillMultiValueWithMissing();
IndexFieldData indexFieldData = getForField("value");
AtomicFieldData fieldData = indexFieldData.load(refreshReader());
assertThat(fieldData.getMemorySizeInBytes(), greaterThan(0l));
assertThat(fieldData.getNumDocs(), equalTo(3));
@ -409,6 +407,8 @@ public abstract class StringFieldDataTests extends AbstractFieldDataTests {
fillAllMissing();
IndexFieldData indexFieldData = getForField("value");
AtomicFieldData fieldData = indexFieldData.load(refreshReader());
// Some impls (FST) return size 0 and some (PagedBytes) do take size in the case no actual data is loaded
assertThat(fieldData.getMemorySizeInBytes(), greaterThanOrEqualTo(0l));
assertThat(fieldData.getNumDocs(), equalTo(3));

View File

@ -19,23 +19,18 @@
package org.elasticsearch.test.unit.index.fielddata.ordinals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import org.apache.lucene.util.IntsRef;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.index.fielddata.ordinals.Ordinals;
import org.elasticsearch.index.fielddata.ordinals.OrdinalsBuilder;
import org.testng.annotations.Test;
import java.util.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
/**
*/
public abstract class MultiOrdinalsTests {
@ -205,6 +200,7 @@ public abstract class MultiOrdinalsTests {
assertThat(docs.getNumOrds(), equalTo(maxOrds));
assertThat(docs.getMaxOrd(), equalTo(maxOrds + 1)); // Includes null ord
assertThat(docs.isMultiValued(), equalTo(true));
assertThat(ordinals.getMemorySizeInBytes(), greaterThan(0l));
// Document 1
assertThat(docs.getOrd(0), equalTo(2));