From 381bb4ed7dc5554dc93de62fdf0341b4b4c5de9d Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Thu, 31 Aug 2017 07:41:48 +0200 Subject: [PATCH] add a test case to ensure NaN's aren't accepted (elastic/x-pack-elasticsearch#2395) Original commit: elastic/x-pack-elasticsearch@72879c4f7c12ab7aa1f2ef212bc19ca0ddec17fc --- .../output/AutodetectResultsParserTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultsParserTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultsParserTests.java index 59d804213fa..b5d4c2f87b3 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultsParserTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/output/AutodetectResultsParserTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect.output; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.ml.job.process.autodetect.state.Quantiles; @@ -401,6 +402,21 @@ public class AutodetectResultsParserTests extends ESTestCase { assertEquals("unexpected token [START_ARRAY]", e.getMessage()); } + /** + * Ensure that we do not accept NaN values + */ + public void testParsingExceptionNaN() { + String json = "[{\"bucket\": {\"job_id\":\"foo\",\"timestamp\":1359453600000,\"bucket_span\":10,\"records\":" + + "[{\"timestamp\":1359453600000,\"bucket_span\":10,\"job_id\":\"foo\",\"probability\":NaN," + + "\"by_field_name\":\"airline\",\"by_field_value\":\"JZA\", \"typical\":[1020.08],\"actual\":[0]," + + "\"field_name\":\"responsetime\",\"function\":\"max\",\"partition_field_name\":\"\",\"partition_field_value\":\"\"}]}}]"; + InputStream inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); + AutodetectResultsParser parser = new AutodetectResultsParser(Settings.EMPTY); + + expectThrows(ParsingException.class, + () -> parser.parseResults(inputStream).forEachRemaining(a -> {})); + } + public void testConsumeAndCloseStream() throws IOException { String json = "some string of data"; ByteArrayInputStream inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));