|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.index.reindex; |
| 21 | + |
| 22 | +import org.elasticsearch.index.query.RangeQueryBuilder; |
| 23 | +import org.elasticsearch.plugins.Plugin; |
| 24 | +import org.elasticsearch.search.sort.SortOrder; |
| 25 | +import org.elasticsearch.test.ESSingleNodeTestCase; |
| 26 | + |
| 27 | +import java.util.Arrays; |
| 28 | +import java.util.Collection; |
| 29 | + |
| 30 | +import static org.elasticsearch.index.reindex.ReindexTestCase.matcher; |
| 31 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; |
| 32 | + |
| 33 | +public class ReindexSingleNodeTests extends ESSingleNodeTestCase { |
| 34 | + @Override |
| 35 | + protected Collection<Class<? extends Plugin>> getPlugins() { |
| 36 | + return Arrays.asList(ReindexPlugin.class); |
| 37 | + } |
| 38 | + |
| 39 | + public void testDeprecatedSort() { |
| 40 | + int max = between(2, 20); |
| 41 | + for (int i = 0; i < max; i++) { |
| 42 | + client().prepareIndex("source", "_doc").setId(Integer.toString(i)).setSource("foo", i).get(); |
| 43 | + } |
| 44 | + |
| 45 | + client().admin().indices().prepareRefresh("source").get(); |
| 46 | + assertHitCount(client().prepareSearch("source").setSize(0).get(), max); |
| 47 | + |
| 48 | + // Copy a subset of the docs sorted |
| 49 | + int subsetSize = randomIntBetween(1, max - 1); |
| 50 | + ReindexRequestBuilder copy = new ReindexRequestBuilder(client(), ReindexAction.INSTANCE) |
| 51 | + .source("source").destination("dest").refresh(true); |
| 52 | + copy.maxDocs(subsetSize); |
| 53 | + copy.request().addSortField("foo", SortOrder.DESC); |
| 54 | + assertThat(copy.get(), matcher().created(subsetSize)); |
| 55 | + |
| 56 | + assertHitCount(client().prepareSearch("dest").setSize(0).get(), subsetSize); |
| 57 | + assertHitCount(client().prepareSearch("dest").setQuery(new RangeQueryBuilder("foo").gte(0).lt(max-subsetSize)).get(), 0); |
| 58 | + assertWarnings(Reindexer.SORT_DEPRECATED_MESSAGE); |
| 59 | + } |
| 60 | +} |
0 commit comments