77
88package  org .elasticsearch .xpack .inference .integration ;
99
10+ import  org .elasticsearch .ElasticsearchException ;
1011import  org .elasticsearch .action .ActionFuture ;
1112import  org .elasticsearch .action .search .SearchPhaseExecutionException ;
1213import  org .elasticsearch .common .bytes .BytesReference ;
4445
4546import  static  org .hamcrest .CoreMatchers .containsString ;
4647import  static  org .hamcrest .CoreMatchers .equalTo ;
48+ import  static  org .hamcrest .Matchers .instanceOf ;
4749
4850@ ESTestCase .WithoutEntitlements  // due to dependency issue ES-12435 
4951public  class  InferenceIndicesIT  extends  ESIntegTestCase  {
@@ -137,11 +139,40 @@ public void testRetrievingInferenceEndpoint_ThrowsException_WhenIndexNodeIsNotAv
137139        internalCluster ().stopNode (configIndexDataNodes );
138140
139141        var  responseFailureFuture  = client ().execute (GetInferenceModelAction .INSTANCE , getInferenceEndpointRequest );
140-         var  exception  = expectThrows (SearchPhaseExecutionException .class , () -> responseFailureFuture .actionGet (TEST_REQUEST_TIMEOUT ));
142+         var  exception  = expectThrows (ElasticsearchException .class , () -> responseFailureFuture .actionGet (TEST_REQUEST_TIMEOUT ));
143+         assertThat (exception .toString (), containsString ("Failed to load inference endpoint [test-index-id]" ));
141144
142-         assertThat (exception .toString (), containsString ("all shards failed" ));
143-         assertThat (exception .toString (), containsString ("Node not connected" ));
144-         assertThat (exception .toString (), containsString (".inference" ));
145+         var  causeException  = exception .getCause ();
146+         assertThat (causeException , instanceOf (SearchPhaseExecutionException .class ));
147+         assertThat (causeException .toString (), containsString (".inference" ));
148+     }
149+ 
150+     public  void  testRetrievingInferenceEndpoint_ThrowsException_WhenIndexNodeIsNotAvailable_ForInferenceAction () throws  Exception  {
151+         final  var  configIndexNodeAttributes  = Settings .builder ().put (INDEX_ROUTER_ATTRIBUTE , CONFIG_ROUTER ).build ();
152+ 
153+         internalCluster ().startMasterOnlyNode (configIndexNodeAttributes );
154+         final  var  configIndexDataNodes  = internalCluster ().startDataOnlyNode (configIndexNodeAttributes );
155+ 
156+         internalCluster ().startDataOnlyNode (Settings .builder ().put (INDEX_ROUTER_ATTRIBUTE , SECRETS_ROUTER ).build ());
157+ 
158+         final  var  inferenceId  = "test-index-id-2" ;
159+         createInferenceEndpoint (TaskType .TEXT_EMBEDDING , inferenceId , TEST_SERVICE_SETTINGS );
160+ 
161+         // Ensure the inference indices are created and we can retrieve the inference endpoint 
162+         var  getInferenceEndpointRequest  = new  GetInferenceModelAction .Request (inferenceId , TaskType .TEXT_EMBEDDING , true );
163+         var  responseFuture  = client ().execute (GetInferenceModelAction .INSTANCE , getInferenceEndpointRequest );
164+         assertThat (responseFuture .actionGet (TEST_REQUEST_TIMEOUT ).getEndpoints ().get (0 ).getInferenceEntityId (), equalTo (inferenceId ));
165+ 
166+         // stop the node that holds the inference index 
167+         internalCluster ().stopNode (configIndexDataNodes );
168+ 
169+         var  proxyResponse  = sendInferenceProxyRequest (inferenceId );
170+         var  exception  = expectThrows (ElasticsearchException .class , () -> proxyResponse .actionGet (TEST_REQUEST_TIMEOUT ));
171+         assertThat (exception .toString (), containsString ("Failed to load inference endpoint [test-index-id-2]" ));
172+ 
173+         var  causeException  = exception .getCause ();
174+         assertThat (causeException , instanceOf (SearchPhaseExecutionException .class ));
175+         assertThat (causeException .toString (), containsString (".inference" ));
145176    }
146177
147178    public  void  testRetrievingInferenceEndpoint_ThrowsException_WhenSecretsIndexNodeIsNotAvailable () throws  Exception  {
@@ -165,11 +196,14 @@ public void testRetrievingInferenceEndpoint_ThrowsException_WhenSecretsIndexNode
165196        internalCluster ().stopNode (secretIndexDataNodes );
166197
167198        var  proxyResponse  = sendInferenceProxyRequest (inferenceId );
168-         var  exception  = expectThrows (SearchPhaseExecutionException .class , () -> proxyResponse .actionGet (TEST_REQUEST_TIMEOUT ));
169199
170-         assertThat (exception .toString (), containsString ("shards failure" ));
171-         assertThat (exception .toString (), containsString ("Node not connected" ));
172-         assertThat (exception .toString (), containsString (".secrets-inference" ));
200+         var  exception  = expectThrows (ElasticsearchException .class , () -> proxyResponse .actionGet (TEST_REQUEST_TIMEOUT ));
201+         assertThat (exception .toString (), containsString ("Failed to load inference endpoint [test-secrets-index-id]" ));
202+ 
203+         var  causeException  = exception .getCause ();
204+ 
205+         assertThat (causeException , instanceOf (SearchPhaseExecutionException .class ));
206+         assertThat (causeException .toString (), containsString (".secrets-inference" ));
173207    }
174208
175209    private  ActionFuture <InferenceAction .Response > sendInferenceProxyRequest (String  inferenceId ) throws  IOException  {
0 commit comments