3737import org .elasticsearch .test .FieldMaskingReader ;
3838
3939import static org .hamcrest .Matchers .equalTo ;
40+ import static org .hamcrest .Matchers .greaterThan ;
4041
4142public class FieldDataCacheTests extends ESTestCase {
4243 private static final ToScriptFieldFactory <SortedSetDocValues > MOCK_TO_SCRIPT_FIELD = (dv , n ) -> new DelegateDocValuesField (
@@ -100,7 +101,8 @@ public void testGlobalOrdinalsCircuitBreaker() throws Exception {
100101 iw .close ();
101102 DirectoryReader ir = ElasticsearchDirectoryReader .wrap (DirectoryReader .open (dir ), new ShardId ("_index" , "_na_" , 0 ));
102103
103- int [] timesCalled = new int [1 ];
104+ int [] timesCalledForParent = new int [1 ];
105+ long [] timesCalledForFieldData = new long [1 ];
104106 SortedSetOrdinalsIndexFieldData sortedSetOrdinalsIndexFieldData = new SortedSetOrdinalsIndexFieldData (
105107 new DummyAccountingFieldDataCache (),
106108 "field1" ,
@@ -113,16 +115,22 @@ public CircuitBreaker getBreaker(String name) {
113115 @ Override
114116 public void addEstimateBytesAndMaybeBreak (long bytes , String label ) throws CircuitBreakingException {
115117 assertThat (label , equalTo ("Global Ordinals" ));
116- assertThat (bytes , equalTo (0L ));
117- timesCalled [0 ]++;
118+ if (bytes == 0 ) {
119+ timesCalledForParent [0 ]++;
120+ } else {
121+ assertThat (timesCalledForFieldData [0 ], equalTo (0L ));
122+ assertThat (bytes , greaterThan (0L ));
123+ timesCalledForFieldData [0 ] = bytes ;
124+ }
118125 }
119126 };
120127 }
121128 },
122129 MOCK_TO_SCRIPT_FIELD
123130 );
124- sortedSetOrdinalsIndexFieldData .loadGlobal (ir );
125- assertThat (timesCalled [0 ], equalTo (2 ));
131+ IndexOrdinalsFieldData globalOrdinals = sortedSetOrdinalsIndexFieldData .loadGlobal (ir );
132+ assertThat (timesCalledForParent [0 ], equalTo (2 ));
133+ assertThat (timesCalledForFieldData [0 ], equalTo (globalOrdinals .getOrdinalMap ().ramBytesUsed ()));
126134
127135 ir .close ();
128136 dir .close ();
0 commit comments