Skip to content

Commit

Permalink
Add stored binary fields to static backwards compatibility indices te…
Browse files Browse the repository at this point in the history
…sts (#22054)

Add stored binary fields to static backwards compatibility indices tests
  • Loading branch information
Michael McCandless authored Dec 9, 2016
1 parent 6714e02 commit 613a1a6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.routing.RecoverySource;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
Expand All @@ -55,6 +56,8 @@
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
Expand Down Expand Up @@ -242,6 +245,7 @@ void assertOldIndexWorks(String index) throws Exception {
assertUpgradeWorks(client(), indexName, version);
assertPositionIncrementGapDefaults(indexName, version);
assertAliasWithBadName(indexName, version);
assertStoredBinaryFields(indexName, version);
unloadIndex(indexName);
}

Expand Down Expand Up @@ -461,6 +465,25 @@ void assertAliasWithBadName(String indexName, Version version) throws Exception
assertFalse(client().admin().indices().prepareAliasesExist(aliasName).get().exists());
}

/**
* Make sure we can load stored binary fields.
*/
void assertStoredBinaryFields(String indexName, Version version) throws Exception {
SearchRequestBuilder builder = client().prepareSearch(indexName);
builder.setQuery(QueryBuilders.matchAllQuery());
builder.setSize(100);
builder.addStoredField("binary");
SearchHits hits = builder.get().getHits();
assertEquals(100, hits.hits().length);
for(SearchHit hit : hits) {
SearchHitField field = hit.field("binary");
assertNotNull(field);
Object value = field.value();
assertTrue(value instanceof BytesArray);
assertEquals(16, ((BytesArray) value).length());
}
}

private Path getNodeDir(String indexFile) throws IOException {
Path unzipDir = createTempDir();
Path unzipDataDir = unzipDir.resolve("data");
Expand Down
Binary file modified core/src/test/resources/indices/bwc/index-5.0.0.zip
Binary file not shown.
Binary file modified core/src/test/resources/indices/bwc/index-5.0.1.zip
Binary file not shown.
Binary file modified core/src/test/resources/indices/bwc/index-5.0.2.zip
Binary file not shown.
Binary file modified core/src/test/resources/indices/bwc/index-5.1.1.zip
Binary file not shown.
Binary file modified core/src/test/resources/indices/bwc/repo-5.0.0.zip
Binary file not shown.
Binary file modified core/src/test/resources/indices/bwc/repo-5.0.1.zip
Binary file not shown.
Binary file modified core/src/test/resources/indices/bwc/repo-5.0.2.zip
Binary file not shown.
Binary file modified core/src/test/resources/indices/bwc/repo-5.1.1.zip
Binary file not shown.
9 changes: 9 additions & 0 deletions dev-tools/create_bwc_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# language governing permissions and limitations under the License.

import argparse
import base64
import glob
import logging
import os
Expand Down Expand Up @@ -73,6 +74,8 @@ def index(es, index_name, type, num_docs, supports_dots_in_field_names, flush=Fa
if supports_dots_in_field_names:
body['field.with.dots'] = str(random.randint(0, 100))

body['binary'] = base64.b64encode(bytearray(random.getrandbits(8) for _ in range(16))).decode('ascii')

es.index(index=index_name, doc_type=type, id=id, body=body)

if rarely():
Expand Down Expand Up @@ -334,6 +337,12 @@ def generate_index(client, version, index_name):
}
})

# test back-compat of stored binary fields
mappings['doc']['properties']['binary'] = {
'type': 'binary',
'store': True,
}

settings = {
'number_of_shards': 1,
'number_of_replicas': 0,
Expand Down

0 comments on commit 613a1a6

Please sign in to comment.