@@ -241,22 +241,32 @@ public void testDeploymentStats() throws IOException {
241
241
CheckedBiConsumer <String , AllocationStatus .State , IOException > assertAtLeast = (modelId , state ) -> {
242
242
startDeployment (modelId , state .toString ());
243
243
Response response = getTrainedModelStats (modelId );
244
- List <Map <String , Object >> stats = (List <Map <String , Object >>) entityAsMap (response ).get ("trained_model_stats" );
244
+ var responseMap = entityAsMap (response );
245
+ List <Map <String , Object >> stats = (List <Map <String , Object >>) responseMap .get ("trained_model_stats" );
245
246
assertThat (stats , hasSize (1 ));
246
247
String statusState = (String ) XContentMapValues .extractValue ("deployment_stats.allocation_status.state" , stats .get (0 ));
247
248
assertThat (stats .toString (), statusState , is (not (nullValue ())));
248
249
assertThat (AllocationStatus .State .fromString (statusState ), greaterThanOrEqualTo (state ));
249
- Integer byteSize = (Integer ) XContentMapValues .extractValue ("deployment_stats.model_size_bytes" , stats .get (0 ));
250
- assertThat (byteSize , is (not (nullValue ())));
251
- assertThat (byteSize , equalTo ((int ) RAW_MODEL_SIZE ));
252
250
253
- Response humanResponse = client ().performRequest (new Request ("GET" , "/_ml/trained_models/" + modelId + "/_stats?human" ));
254
- stats = (List <Map <String , Object >>) entityAsMap (humanResponse ).get ("trained_model_stats" );
255
- assertThat (stats , hasSize (1 ));
256
- String stringBytes = (String ) XContentMapValues .extractValue ("deployment_stats.model_size" , stats .get (0 ));
257
- assertThat (stringBytes , is (not (nullValue ())));
258
- assertThat (stringBytes , equalTo ("1.5kb" ));
259
- stopDeployment (model );
251
+ // starting models do not know their model size yet
252
+ if (state .isAnyOf (AllocationStatus .State .STARTED , AllocationStatus .State .FULLY_ALLOCATED )) {
253
+ Integer byteSize = (Integer ) XContentMapValues .extractValue ("deployment_stats.model_size_bytes" , stats .get (0 ));
254
+ assertThat (responseMap .toString (), byteSize , is (not (nullValue ())));
255
+ assertThat (byteSize , equalTo ((int ) RAW_MODEL_SIZE ));
256
+
257
+ Response humanResponse = client ().performRequest (new Request ("GET" , "/_ml/trained_models/" + modelId + "/_stats?human" ));
258
+ var humanResponseMap = entityAsMap (humanResponse );
259
+ stats = (List <Map <String , Object >>) humanResponseMap .get ("trained_model_stats" );
260
+ assertThat (stats , hasSize (1 ));
261
+ String stringBytes = (String ) XContentMapValues .extractValue ("deployment_stats.model_size" , stats .get (0 ));
262
+ assertThat (
263
+ "stats response: " + responseMap + " human stats response" + humanResponseMap ,
264
+ stringBytes ,
265
+ is (not (nullValue ()))
266
+ );
267
+ assertThat (stringBytes , equalTo ("1.5kb" ));
268
+ }
269
+ stopDeployment (modelId );
260
270
};
261
271
262
272
assertAtLeast .accept (model , AllocationStatus .State .STARTING );
0 commit comments