Skip to content

Commit d9b13eb

Browse files
committed
[TEST] add missing assertWarnings to tests that use/test deprecated features
1 parent 60097ac commit d9b13eb

File tree

27 files changed

+224
-105
lines changed

27 files changed

+224
-105
lines changed

core/src/test/java/org/elasticsearch/action/admin/indices/template/BWCTemplateTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public void testBeatsTemplatesBWC() throws Exception {
4242
client().prepareIndex("packetbeat-foo", "doc", "1").setSource("message", "foo").get();
4343
client().prepareIndex("filebeat-foo", "doc", "1").setSource("message", "foo").get();
4444
client().prepareIndex("winlogbeat-foo", "doc", "1").setSource("message", "foo").get();
45-
assertWarnings("Deprecated field [template] used, replaced by [index_patterns]");
4645
}
4746

4847
public void testLogstashTemplatesBWC() throws Exception {
@@ -54,7 +53,6 @@ public void testLogstashTemplatesBWC() throws Exception {
5453

5554
client().admin().indices().preparePutTemplate("logstash-5x").setSource(ls5x).get();
5655
client().prepareIndex("logstash-foo", "doc", "1").setSource("message", "foo").get();
57-
assertWarnings("Deprecated field [template] used, replaced by [index_patterns]");
5856
}
5957

6058
}

core/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,8 @@ public void testNamedObject() throws IOException {
999999
assertEquals(test1, p.namedObject(Object.class, "test1", null));
10001000
assertEquals(test2, p.namedObject(Object.class, "test2", null));
10011001
assertEquals(test2, p.namedObject(Object.class, "deprecated", null));
1002-
// TODO wait for warnings commit to be backported and uncomment
1003-
// assertWarnings("Deprecated field [deprecated] used, expected [test2] instead");
1002+
1003+
assertWarnings("Deprecated field [deprecated] used, expected [test2] instead");
10041004
{
10051005
p.nextToken();
10061006
assertEquals("test", p.namedObject(Object.class, "str", null));

core/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ public void testBwCompatDocValues() throws Exception {
212212
assertEquals(DocValuesType.SORTED_NUMERIC, LegacyStringMappingTests.docValuesType(doc, "bool1"));
213213
assertEquals(DocValuesType.NONE, LegacyStringMappingTests.docValuesType(doc, "bool2"));
214214
assertEquals(DocValuesType.SORTED_NUMERIC, LegacyStringMappingTests.docValuesType(doc, "bool3"));
215+
assertWarnings("Expected a boolean for property [index] but got [no]",
216+
"Expected a boolean for property [index] but got [not_analyzed]");
215217
}
216218

217219
public void testEmptyName() throws IOException {

core/src/test/java/org/elasticsearch/index/mapper/CustomBoostMappingTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.common.xcontent.XContentFactory;
2929
import org.elasticsearch.index.IndexService;
30-
import org.elasticsearch.index.mapper.DocumentFieldMappers;
31-
import org.elasticsearch.index.mapper.DocumentMapper;
32-
import org.elasticsearch.index.mapper.ParsedDocument;
3330
import org.elasticsearch.index.query.QueryShardContext;
3431
import org.elasticsearch.plugins.Plugin;
3532
import org.elasticsearch.test.ESSingleNodeTestCase;
@@ -82,6 +79,7 @@ public void testBackCompatCustomBoostValues() throws Exception {
8279
assertThat(doc.rootDoc().getField("d_field").boost(), equalTo(7.0f));
8380
assertThat(doc.rootDoc().getField("f_field").boost(), equalTo(8.0f));
8481
assertThat(doc.rootDoc().getField("date_field").boost(), equalTo(9.0f));
82+
assertWarnings("The [norms{enabled:true/false}] way of specifying norms is deprecated, please use [norms:true/false] instead");
8583
}
8684

8785
public void testBackCompatFieldMappingBoostValues() throws Exception {

core/src/test/java/org/elasticsearch/index/mapper/DynamicTemplateTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public void testParseUnknownMatchType() throws IOException {
5656
templateDef.put("mapping", Collections.singletonMap("store", true));
5757
// if a wrong match type is specified, we ignore the template
5858
assertNull(DynamicTemplate.parse("my_template", templateDef, Version.V_5_0_0_alpha5));
59+
//TODO clarify this deprecation warning
60+
assertWarnings("Ignoring unrecognized match_mapping_type: [short]");
5961
}
6062

6163
public void testMatchAllTemplate() {

core/src/test/java/org/elasticsearch/index/mapper/FieldLevelBoostTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.elasticsearch.common.compress.CompressedXContent;
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.common.xcontent.XContentFactory;
29-
import org.elasticsearch.index.mapper.DocumentMapper;
30-
import org.elasticsearch.index.mapper.MapperParsingException;
3129
import org.elasticsearch.index.mapper.ParseContext.Document;
3230
import org.elasticsearch.plugins.Plugin;
3331
import org.elasticsearch.test.ESSingleNodeTestCase;
@@ -100,6 +98,8 @@ public void testBackCompatFieldLevelBoost() throws Exception {
10098

10199
f = doc.getField("short_field");
102100
assertThat((double) f.boost(), closeTo(9.0, 0.001));
101+
102+
assertWarnings("The [norms{enabled:true/false}] way of specifying norms is deprecated, please use [norms:true/false] instead");
103103
}
104104

105105
public void testBackCompatFieldLevelMappingBoost() throws Exception {
@@ -281,7 +281,7 @@ public void testBackCompatInvalidFieldLevelBoost() throws Exception {
281281
} catch (Exception ex) {
282282
assertThat(ex, instanceOf(MapperParsingException.class));
283283
}
284-
284+
assertWarnings("The [norms{enabled:true/false}] way of specifying norms is deprecated, please use [norms:true/false] instead");
285285
}
286286

287287
}

core/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public void testLegacyLatLonValues() throws Exception {
8888
} else {
8989
assertThat(Long.parseLong(doc.rootDoc().get("point")), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
9090
}
91+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
92+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
93+
}
9194
}
9295

9396
public void testLegacyLatLonValuesWithGeohash() throws Exception {
@@ -113,6 +116,10 @@ public void testLegacyLatLonValuesWithGeohash() throws Exception {
113116
} else {
114117
assertThat(doc.rootDoc().get("point.geohash"), equalTo(stringEncode(1.3, 1.2)));
115118
}
119+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
120+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release",
121+
"geo_point geohash parameter is deprecated and will be removed in the next major release");
122+
}
116123
}
117124

118125
public void testLegacyLatLonInOneValueWithGeohash() throws Exception {
@@ -137,6 +144,10 @@ public void testLegacyLatLonInOneValueWithGeohash() throws Exception {
137144
} else {
138145
assertThat(doc.rootDoc().get("point.geohash"), equalTo(stringEncode(1.3, 1.2)));
139146
}
147+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
148+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release",
149+
"geo_point geohash parameter is deprecated and will be removed in the next major release");
150+
}
140151
}
141152

142153
public void testLegacyGeoHashIndexValue() throws Exception {
@@ -161,6 +172,10 @@ public void testLegacyGeoHashIndexValue() throws Exception {
161172
} else {
162173
assertThat(doc.rootDoc().get("point.geohash"), equalTo(stringEncode(1.3, 1.2)));
163174
}
175+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
176+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release",
177+
"geo_point geohash parameter is deprecated and will be removed in the next major release");
178+
}
164179
}
165180

166181
public void testGeoHashValue() throws Exception {
@@ -184,6 +199,7 @@ public void testGeoHashValue() throws Exception {
184199
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
185200
assertThat(doc.rootDoc().getField("point.lat"), notNullValue());
186201
assertThat(doc.rootDoc().getField("point.lon"), notNullValue());
202+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
187203
}
188204
}
189205

@@ -309,6 +325,9 @@ public void testLegacyValidateLatLonValues() throws Exception {
309325
.bytes()));
310326
assertThat(e.getRootCause(), instanceOf(NumberFormatException.class));
311327
assertThat(e.getRootCause().toString(), containsString("java.lang.NumberFormatException: For input string: \"-\""));
328+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
329+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
330+
}
312331
}
313332

314333
public void testNoValidateLegacyLatLonValues() throws Exception {
@@ -370,6 +389,10 @@ public void testNoValidateLegacyLatLonValues() throws Exception {
370389
.startObject("point").field("lat", "-").field("lon", "-").endObject()
371390
.endObject()
372391
.bytes());
392+
393+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
394+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
395+
}
373396
}
374397

375398
public void testLatLonValuesStored() throws Exception {
@@ -449,6 +472,9 @@ public void testArrayLatLonValues() throws Exception {
449472
assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoPointField.encodeLatLon(1.4, 1.5)));
450473
}
451474
}
475+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
476+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
477+
}
452478
}
453479

454480
public void testLatLonInOneValue() throws Exception {
@@ -479,6 +505,9 @@ public void testLatLonInOneValue() throws Exception {
479505
assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
480506
}
481507
}
508+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
509+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
510+
}
482511
}
483512

484513
public void testLatLonInOneValueStored() throws Exception {
@@ -511,6 +540,9 @@ public void testLatLonInOneValueStored() throws Exception {
511540
equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
512541
}
513542
}
543+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
544+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
545+
}
514546
}
515547

516548
public void testLatLonInOneValueArray() throws Exception {
@@ -557,6 +589,9 @@ public void testLatLonInOneValueArray() throws Exception {
557589
} else if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
558590
assertThat(Long.parseLong(doc.rootDoc().getFields("point")[1].stringValue()), equalTo(GeoPointField.encodeLatLon(1.4, 1.5)));
559591
}
592+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
593+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
594+
}
560595
}
561596

562597
public void testLonLatArray() throws Exception {
@@ -585,6 +620,7 @@ public void testLonLatArray() throws Exception {
585620
} else {
586621
assertThat(Long.parseLong(doc.rootDoc().getFields("point")[0].stringValue()), equalTo(GeoPointField.encodeLatLon(1.2, 1.3)));
587622
}
623+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
588624
}
589625
}
590626

@@ -629,6 +665,10 @@ public void testLonLatArrayStored() throws Exception {
629665
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
630666
DocumentMapper defaultMapper = createIndex("test", settings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
631667

668+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
669+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
670+
}
671+
632672
ParsedDocument doc = defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
633673
.startObject()
634674
.startArray("point").value(1.3).value(1.2).endArray()
@@ -694,6 +734,9 @@ public void testLonLatArrayArrayStored() throws Exception {
694734
} else if (version.onOrAfter(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
695735
assertThat(doc.rootDoc().getFields("point").length, CoreMatchers.equalTo(4));
696736
}
737+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
738+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release");
739+
}
697740
}
698741

699742

@@ -797,6 +840,11 @@ public void testOptionDeprecation() throws Exception {
797840
parser.parse("type", new CompressedXContent(normalizeMapping)));
798841
assertEquals(e.getMessage(), "Mapping definition for [point] has unsupported parameters: [normalize_lon : true]");
799842
}
843+
844+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
845+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release",
846+
"geo_point geohash parameter is deprecated and will be removed in the next major release");
847+
}
800848
}
801849

802850
public void testLegacyGeoPointMapperMerge() throws Exception {
@@ -821,6 +869,10 @@ public void testLegacyGeoPointMapperMerge() throws Exception {
821869
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true)
822870
.field("geohash", true).endObject().endObject().endObject().endObject().string();
823871
mapperService.merge("type", new CompressedXContent(stage2MappingCorrect), MapperService.MergeReason.MAPPING_UPDATE, false);
872+
if (version.before(LatLonPointFieldMapper.LAT_LON_FIELD_VERSION)) {
873+
assertWarnings("geo_point lat_lon parameter is deprecated and will be removed in the next major release",
874+
"geo_point geohash parameter is deprecated and will be removed in the next major release");
875+
}
824876
}
825877

826878
public void testLegacyGeoHashSearch() throws Exception {

core/src/test/java/org/elasticsearch/index/mapper/LegacyGeohashMappingGeoPointTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void testGeoHashValue() throws Exception {
6969
assertThat(doc.rootDoc().getField("point.lon"), nullValue());
7070
assertThat(doc.rootDoc().getField("point.geohash").stringValue(), equalTo(stringEncode(1.3, 1.2)));
7171
assertThat(doc.rootDoc().get("point"), notNullValue());
72+
assertWarnings("geo_point geohash parameter is deprecated and will be removed in the next major release");
7273
}
7374

7475
public void testGeoHashPrecisionAsInteger() throws Exception {
@@ -84,6 +85,8 @@ public void testGeoHashPrecisionAsInteger() throws Exception {
8485
assertThat(mapper, instanceOf(BaseGeoPointFieldMapper.class));
8586
BaseGeoPointFieldMapper geoPointFieldMapper = (BaseGeoPointFieldMapper) mapper;
8687
assertThat(((LegacyGeoPointFieldType)geoPointFieldMapper.fieldType()).geoHashPrecision(), is(10));
88+
assertWarnings("geo_point geohash parameter is deprecated and will be removed in the next major release",
89+
"geo_point geohash_precision parameter is deprecated and will be removed in the next major release");
8790
}
8891

8992
public void testGeoHashPrecisionAsLength() throws Exception {
@@ -100,5 +103,7 @@ public void testGeoHashPrecisionAsLength() throws Exception {
100103
assertThat(mapper, instanceOf(BaseGeoPointFieldMapper.class));
101104
BaseGeoPointFieldMapper geoPointFieldMapper = (BaseGeoPointFieldMapper) mapper;
102105
assertThat(((LegacyGeoPointFieldType)geoPointFieldMapper.fieldType()).geoHashPrecision(), is(10));
106+
assertWarnings("geo_point geohash parameter is deprecated and will be removed in the next major release",
107+
"geo_point geohash_precision parameter is deprecated and will be removed in the next major release");
103108
}
104109
}

core/src/test/java/org/elasticsearch/index/mapper/LegacyNumberFieldMapperTests.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,7 @@
3030
import org.elasticsearch.common.compress.CompressedXContent;
3131
import org.elasticsearch.common.settings.Settings;
3232
import org.elasticsearch.common.xcontent.XContentFactory;
33-
import org.elasticsearch.index.IndexService;
34-
import org.elasticsearch.index.mapper.DocumentMapper;
35-
import org.elasticsearch.index.mapper.DocumentMapperParser;
36-
import org.elasticsearch.index.mapper.FieldMapper;
37-
import org.elasticsearch.index.mapper.LegacyFloatFieldMapper;
38-
import org.elasticsearch.index.mapper.LegacyLongFieldMapper;
39-
import org.elasticsearch.index.mapper.LegacyNumberFieldMapper;
40-
import org.elasticsearch.index.mapper.MapperParsingException;
4133
import org.elasticsearch.index.mapper.ParseContext.Document;
42-
import org.elasticsearch.index.mapper.ParsedDocument;
43-
import org.elasticsearch.index.mapper.TextFieldMapper;
4434
import org.elasticsearch.plugins.Plugin;
4535
import org.elasticsearch.test.ESSingleNodeTestCase;
4636
import org.elasticsearch.test.InternalSettingsPlugin;
@@ -49,7 +39,6 @@
4939
import java.util.Arrays;
5040
import java.util.Collection;
5141

52-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5342
import static org.hamcrest.Matchers.containsString;
5443
import static org.hamcrest.Matchers.instanceOf;
5544
import static org.hamcrest.Matchers.notNullValue;
@@ -264,6 +253,7 @@ public void testDocValues() throws Exception {
264253
assertEquals(DocValuesType.SORTED_NUMERIC, LegacyStringMappingTests.docValuesType(doc, "double1"));
265254
assertEquals(DocValuesType.NONE, LegacyStringMappingTests.docValuesType(doc, "int2"));
266255
assertEquals(DocValuesType.NONE, LegacyStringMappingTests.docValuesType(doc, "double2"));
256+
assertWarnings("Expected a boolean for property [index] but got [no]");
267257
}
268258

269259
public void testUnIndex() throws IOException {
@@ -318,6 +308,8 @@ public void testBwCompatIndex() throws IOException {
318308
DocumentMapper defaultMapper = createIndex("test", oldSettings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
319309
assertEquals("{\"type\":{\"properties\":{\"double\":{\"type\":\"double\"},\"int\":{\"type\":\"integer\",\"index\":false}}}}",
320310
defaultMapper.mapping().toString());
311+
assertWarnings("Expected a boolean for property [index] but got [no]",
312+
"Expected a boolean for property [index] but got [not_analyzed]");
321313
}
322314

323315
public void testDocValuesOnNested() throws Exception {

0 commit comments

Comments
 (0)