Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

package org.elasticsearch.xpack.inference.external.http.sender;

import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ListenerTimeouts;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.inference.InferenceServiceResults;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.threadpool.ThreadPool;

import java.util.Objects;
Expand Down Expand Up @@ -64,7 +65,10 @@ private ActionListener<InferenceServiceResults> getListener(
threadPool.executor(UTILITY_THREAD_POOL_NAME),
notificationListener,
(ignored) -> notificationListener.onFailure(
new ElasticsearchTimeoutException(Strings.format("Request timed out waiting to be sent after [%s]", timeout))
new ElasticsearchStatusException(
Strings.format("Request timed out waiting to be sent after [%s]", timeout),
RestStatus.REQUEST_TIMEOUT
)
Comment on lines +68 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package org.elasticsearch.xpack.inference.external.http.sender;

import org.apache.http.HttpHeaders;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
Expand Down Expand Up @@ -162,12 +162,13 @@ public void testHttpRequestSender_Throws_WhenATimeoutOccurs() throws Exception {
PlainActionFuture<InferenceServiceResults> listener = new PlainActionFuture<>();
sender.send(RequestManagerTests.createMock(), new DocumentsOnlyInput(List.of()), TimeValue.timeValueNanos(1), listener);

var thrownException = expectThrows(ElasticsearchTimeoutException.class, () -> listener.actionGet(TIMEOUT));
var thrownException = expectThrows(ElasticsearchStatusException.class, () -> listener.actionGet(TIMEOUT));

assertThat(
thrownException.getMessage(),
is(format("Request timed out waiting to be sent after [%s]", TimeValue.timeValueNanos(1)))
);
assertThat(thrownException.status().getStatus(), is(408));
}
}

Expand All @@ -187,12 +188,13 @@ public void testHttpRequestSenderWithTimeout_Throws_WhenATimeoutOccurs() throws
PlainActionFuture<InferenceServiceResults> listener = new PlainActionFuture<>();
sender.send(RequestManagerTests.createMock(), new DocumentsOnlyInput(List.of()), TimeValue.timeValueNanos(1), listener);

var thrownException = expectThrows(ElasticsearchTimeoutException.class, () -> listener.actionGet(TIMEOUT));
var thrownException = expectThrows(ElasticsearchStatusException.class, () -> listener.actionGet(TIMEOUT));

assertThat(
thrownException.getMessage(),
is(format("Request timed out waiting to be sent after [%s]", TimeValue.timeValueNanos(1)))
);
assertThat(thrownException.status().getStatus(), is(408));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package org.elasticsearch.xpack.inference.external.http.sender;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -238,12 +238,13 @@ public void testExecute_CallsOnFailure_WhenRequestTimesOut() {
var listener = new PlainActionFuture<InferenceServiceResults>();
service.execute(RequestManagerTests.createMock(), new DocumentsOnlyInput(List.of()), TimeValue.timeValueNanos(1), listener);

var thrownException = expectThrows(ElasticsearchTimeoutException.class, () -> listener.actionGet(TIMEOUT));
var thrownException = expectThrows(ElasticsearchStatusException.class, () -> listener.actionGet(TIMEOUT));

assertThat(
thrownException.getMessage(),
is(format("Request timed out waiting to be sent after [%s]", TimeValue.timeValueNanos(1)))
);
assertThat(thrownException.status().getStatus(), is(408));
}

public void testExecute_PreservesThreadContext() throws InterruptedException, ExecutionException, TimeoutException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package org.elasticsearch.xpack.inference.external.http.sender;

import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.core.TimeValue;
Expand Down Expand Up @@ -86,13 +86,14 @@ public void testRequest_ReturnsTimeoutException() {
listener
);

var thrownException = expectThrows(ElasticsearchTimeoutException.class, () -> listener.actionGet(TIMEOUT));
var thrownException = expectThrows(ElasticsearchStatusException.class, () -> listener.actionGet(TIMEOUT));
assertThat(
thrownException.getMessage(),
is(format("Request timed out waiting to be sent after [%s]", TimeValue.timeValueMillis(1)))
);
assertTrue(requestTask.hasCompleted());
assertTrue(requestTask.getRequestCompletedFunction().get());
assertThat(thrownException.status().getStatus(), is(408));
}

public void testRequest_DoesNotCallOnFailureTwiceWhenTimingOut() throws Exception {
Expand Down
Loading