@@ -1086,49 +1086,59 @@ public int get(int i) {
10861086 assertNotNull (idBlock );
10871087
10881088 {
1089- var reader2 = ESTestCase .asInstanceOf (
1089+ var reader2 = ( BaseSortedDocValues ) ESTestCase .asInstanceOf (
10901090 OptionalColumnAtATimeReader .class ,
10911091 leaf .reader ().getSortedDocValues (secondField )
10921092 );
1093- int randomOffset = 0 ;
1094- ESTestCase .between (0 , docs .count () - 1 );
1095- var block = (TestBlock ) reader2 .tryRead (factory , docs , randomOffset );
1093+ int randomOffset = ESTestCase .between (0 , docs .count () - 1 );
1094+ TestBlock block ;
1095+ if (reader2 .getValueCount () == 1 ) {
1096+ block = (TestBlock ) reader2 .tryReadAHead (factory , docs , randomOffset );
1097+ } else {
1098+ assertNull (reader2 .tryReadAHead (factory , docs , randomOffset ));
1099+ block = (TestBlock ) reader2 .tryRead (factory , docs , randomOffset );
1100+ }
10961101 assertNotNull (block );
10971102 assertThat (block .size (), equalTo (docs .count () - randomOffset ));
1098- for (int i = randomOffset ; i < block .size (); i ++) {
1103+ for (int i = 0 ; i < block .size (); i ++) {
10991104 String actualHostName = BytesRefs .toString (block .get (i ));
1100- int id = ((Number ) idBlock .get (i )).intValue ();
1105+ int id = ((Number ) idBlock .get (i + randomOffset )).intValue ();
11011106 String expectedHostName = hostnames .get (id );
11021107 assertEquals (expectedHostName , actualHostName );
11031108 }
11041109 }
11051110 {
1106- var reader3 = ESTestCase .asInstanceOf (
1111+ var reader3 = ( BaseSortedDocValues ) ESTestCase .asInstanceOf (
11071112 OptionalColumnAtATimeReader .class ,
11081113 leaf .reader ().getSortedDocValues (unsortedField )
11091114 );
1115+ int randomOffset = ESTestCase .between (0 , docs .count () - 1 );
1116+ TestBlock block ;
1117+ if (reader3 .getValueCount () == 1 ) {
1118+ block = (TestBlock ) reader3 .tryReadAHead (factory , docs , randomOffset );
1119+ } else {
1120+ assertNull (reader3 .tryReadAHead (factory , docs , randomOffset ));
1121+ block = (TestBlock ) reader3 .tryRead (factory , docs , randomOffset );
1122+ }
11101123 assertNotNull (reader3 );
1111- int randomOffset = 0 ;
1112- ESTestCase .between (0 , docs .count () - 1 );
1113- var block = (TestBlock ) reader3 .tryRead (factory , docs , randomOffset );
11141124 assertNotNull (block );
11151125 assertThat (block .size (), equalTo (docs .count () - randomOffset ));
1116- for (int i = randomOffset ; i < block .size (); i ++) {
1126+ for (int i = 0 ; i < block .size (); i ++) {
11171127 String actualHostName = BytesRefs .toString (block .get (i ));
1118- int id = ((Number ) idBlock .get (i )).intValue ();
1128+ int id = ((Number ) idBlock .get (i + randomOffset )).intValue ();
11191129 String expectedHostName = hostnames .get (id );
11201130 assertEquals (expectedHostName , actualHostName );
11211131 }
11221132 }
11231133 for (int offset = 0 ; offset < idBlock .size (); offset += ESTestCase .between (1 , numDocs )) {
11241134 int start = offset ;
1125- var reader1 = ESTestCase .asInstanceOf (
1135+ var reader1 = ( BaseSortedDocValues ) ESTestCase .asInstanceOf (
11261136 OptionalColumnAtATimeReader .class ,
11271137 leaf .reader ().getSortedDocValues (primaryField )
11281138 );
11291139 while (start < idBlock .size ()) {
11301140 int end = start + random ().nextInt (idBlock .size () - start );
1131- TestBlock hostBlock = (TestBlock ) reader1 .tryRead (factory , new BlockLoader .Docs () {
1141+ TestBlock hostBlock = (TestBlock ) reader1 .tryReadAHead (factory , new BlockLoader .Docs () {
11321142 @ Override
11331143 public int count () {
11341144 return end + 1 ;
@@ -1139,11 +1149,20 @@ public int get(int docId) {
11391149 return docId ;
11401150 }
11411151 }, start );
1142- assertNotNull (hostBlock );
1143- assertThat (hostBlock .size (), equalTo (end - start + 1 ));
1144- for (int i = 0 ; i < hostBlock .size (); i ++) {
1145- String actualHostName = BytesRefs .toString (hostBlock .get (i ));
1146- assertThat (actualHostName , equalTo (hostnames .get (((Number ) idBlock .get (i + start )).intValue ())));
1152+ Set <String > seenValues = new HashSet <>();
1153+ for (int p = start ; p <= end ; p ++) {
1154+ String hostName = hostnames .get (((Number ) idBlock .get (p )).intValue ());
1155+ seenValues .add (hostName );
1156+ }
1157+ if (seenValues .size () == 1 ) {
1158+ assertNotNull (hostBlock );
1159+ assertThat (hostBlock .size (), equalTo (end - start + 1 ));
1160+ for (int i = 0 ; i < hostBlock .size (); i ++) {
1161+ String actualHostName = BytesRefs .toString (hostBlock .get (i ));
1162+ assertThat (actualHostName , equalTo (hostnames .get (((Number ) idBlock .get (i + start )).intValue ())));
1163+ }
1164+ } else {
1165+ assertNull (hostBlock );
11471166 }
11481167 if (start == idBlock .size () - 1 ) {
11491168 break ;
0 commit comments