1010package org .elasticsearch .index .mapper ;
1111
1212import org .elasticsearch .common .bytes .BytesArray ;
13+ import org .elasticsearch .datageneration .FieldType ;
1314import org .elasticsearch .script .LongFieldScript ;
1415import org .elasticsearch .script .Script ;
1516import org .elasticsearch .script .ScriptContext ;
1617import org .elasticsearch .xcontent .XContentBuilder ;
1718import org .elasticsearch .xcontent .XContentType ;
19+ import org .junit .Before ;
1820
1921import java .io .IOException ;
2022import java .math .BigInteger ;
2628
2729public class LongFieldMapperTests extends WholeNumberFieldMapperTests {
2830
31+ private FieldType fieldType ;
32+
33+ @ Before
34+ public void pickNumberType () {
35+ // randomly select between long and double to use for generating random numbers
36+ boolean shouldUseLong = randomBoolean ();
37+ fieldType = shouldUseLong ? FieldType .LONG : FieldType .DOUBLE ;
38+ }
39+
2940 @ Override
3041 protected Number missingValue () {
3142 return 123L ;
@@ -45,7 +56,7 @@ protected List<NumberTypeOutOfRangeSpec> outOfRangeSpecs() {
4556
4657 @ Override
4758 protected void minimalMapping (XContentBuilder b ) throws IOException {
48- b .field ("type" , "long" );
59+ b .field ("type" , fieldType . toString () );
4960 }
5061
5162 @ Override
@@ -105,7 +116,8 @@ public void testLongIndexingCoercesIntoRange() throws Exception {
105116
106117 @ Override
107118 protected Number randomNumber () {
108- if (randomBoolean ()) {
119+ // we must be consistent with the type of each number that we generate
120+ if (fieldType .equals (FieldType .LONG )) {
109121 return randomLong ();
110122 }
111123 if (randomBoolean ()) {
0 commit comments