Skip to content

Commit d7ac2e1

Browse files
Cleaning up
1 parent 1d4c583 commit d7ac2e1

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/AuthorizationTaskExecutorIT.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ public void testCreatesEisChatCompletionEndpoint() throws Exception {
132132
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(AUTHORIZED_RAINBOW_SPRINKLES_RESPONSE));
133133
restartPollingTaskAndWaitForAuthResponse();
134134

135+
assertWebServerReceivedRequest();
136+
135137
assertChatCompletionEndpointExists();
136138
}
137139

@@ -198,21 +200,20 @@ static List<UnparsedModel> getEisEndpoints(ModelRegistry modelRegistry) {
198200
}
199201

200202
private void restartPollingTaskAndWaitForAuthResponse() throws Exception {
201-
restartPollingTaskAndWaitForAuthResponse(admin(), authorizationTaskExecutor, webServer);
203+
restartPollingTaskAndWaitForAuthResponse(admin(), authorizationTaskExecutor);
202204
}
203205

204-
static void restartPollingTaskAndWaitForAuthResponse(
205-
AdminClient adminClient,
206-
AuthorizationTaskExecutor authTaskExecutor,
207-
MockWebServer mockWebServer
208-
) throws Exception {
206+
private static void restartPollingTaskAndWaitForAuthResponse(AdminClient adminClient, AuthorizationTaskExecutor authTaskExecutor)
207+
throws Exception {
209208
cancelAuthorizationTask(adminClient);
210209

211210
// wait for the new task to be recreated and an authorization response to be processed
212211
waitForAuthorizationToComplete(authTaskExecutor);
212+
}
213213

214+
private static void assertWebServerReceivedRequest() throws Exception {
214215
assertBusy(() -> {
215-
var requests = mockWebServer.requests();
216+
var requests = webServer.requests();
216217
assertThat(requests.size(), is(1));
217218
});
218219
}
@@ -245,13 +246,15 @@ public void testCreatesEisChatCompletion_DoesNotRemoveEndpointWhenNoLongerAuthor
245246
webServer.clearRequests();
246247
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(AUTHORIZED_RAINBOW_SPRINKLES_RESPONSE));
247248
restartPollingTaskAndWaitForAuthResponse();
249+
assertWebServerReceivedRequest();
248250

249251
assertChatCompletionEndpointExists();
250252

251253
webServer.clearRequests();
252254
// Simulate that the model is no longer authorized
253255
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(EMPTY_AUTH_RESPONSE));
254256
restartPollingTaskAndWaitForAuthResponse();
257+
assertWebServerReceivedRequest();
255258

256259
assertChatCompletionEndpointExists();
257260
}
@@ -287,13 +290,15 @@ public void testCreatesChatCompletion_AndThenCreatesTextEmbedding() throws Excep
287290
webServer.clearRequests();
288291
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(AUTHORIZED_RAINBOW_SPRINKLES_RESPONSE));
289292
restartPollingTaskAndWaitForAuthResponse();
293+
assertWebServerReceivedRequest();
290294

291295
assertChatCompletionEndpointExists();
292296

293297
// Simulate that the model is no longer authorized
294298
webServer.clearRequests();
295299
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(EMPTY_AUTH_RESPONSE));
296300
restartPollingTaskAndWaitForAuthResponse();
301+
assertWebServerReceivedRequest();
297302

298303
assertChatCompletionEndpointExists();
299304

@@ -312,6 +317,7 @@ public void testCreatesChatCompletion_AndThenCreatesTextEmbedding() throws Excep
312317
webServer.clearRequests();
313318
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(authorizedTextEmbeddingResponse));
314319
restartPollingTaskAndWaitForAuthResponse();
320+
assertWebServerReceivedRequest();
315321

316322
var eisEndpoints = getEisEndpoints().stream().collect(Collectors.toMap(UnparsedModel::inferenceEntityId, Function.identity()));
317323
assertThat(eisEndpoints.size(), is(2));
@@ -334,5 +340,6 @@ public void testRestartsTaskAfterAbort() throws Exception {
334340
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(EMPTY_AUTH_RESPONSE));
335341
// Abort the task and ensure it is restarted
336342
restartPollingTaskAndWaitForAuthResponse();
343+
assertWebServerReceivedRequest();
337344
}
338345
}

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/CCMEnablementServiceIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void createComponents() {
4242
}
4343

4444
// Ensure we have a node that doesn't contain any enablement cluster state
45+
@Override
4546
protected boolean resetNodeAfterTest() {
4647
return true;
4748
}

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/CCMEnablementServiceUnsupportedEnvironmentIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void createComponents() {
3737
}
3838

3939
// Ensure we have a node that doesn't contain any enablement cluster state
40+
@Override
4041
protected boolean resetNodeAfterTest() {
4142
return true;
4243
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ private CCMRelatedComponents createCCMDependentComponents(
502502
)
503503
);
504504
authorizationTaskExecutorRef.set(authTaskExecutor);
505-
authTaskExecutor.startAndLazyCreateTask();
505+
authTaskExecutor.startAndLazilyCreateTask();
506506

507507
return new CCMRelatedComponents(
508508
List.of(authorizationHandler, authTaskExecutor, ccmService, ccmPersistentStorageService, ccmCache, ccmEnablementService),

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/AuthorizationTaskExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static AuthorizationTaskExecutor create(
120120
* we can't start the persistent task until after the plugin has finished initializing. Otherwise, we'll
121121
* get an error indicating that it isn't aware of whether the task is a cluster scoped task.
122122
*/
123-
public synchronized void startAndLazyCreateTask() {
123+
public synchronized void startAndLazilyCreateTask() {
124124
if (pollerParameters.elasticInferenceServiceSettings().isAuthorizationEnabled()) {
125125
startInternal();
126126
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ccm/CCMFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
public class CCMFeature {
1515
public static final ElasticsearchStatusException CCM_FORBIDDEN_EXCEPTION = new ElasticsearchStatusException(
16-
"CCM configuration is not permitted for this environment",
16+
"Cloud Connected Mode configuration is not permitted for this environment",
1717
RestStatus.FORBIDDEN
1818
);
1919

2020
public static final ElasticsearchStatusException CCM_UNSUPPORTED_UNTIL_UPGRADED_EXCEPTION = new ElasticsearchStatusException(
21-
"CCM functionality is not supported until the cluster is fully upgraded, please try again later",
21+
"Cloud Connected Mode functionality is not supported until the cluster is fully upgraded, please try again later",
2222
RestStatus.BAD_REQUEST
2323
);
2424

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/AuthorizationTaskExecutorTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public void testStartLazy_OnlyRegistersOnce_NeverCallsPersistentTaskService() {
9797
createMockCCMService(false)
9898
)
9999
);
100-
executor.startAndLazyCreateTask();
101-
executor.startAndLazyCreateTask();
100+
executor.startAndLazilyCreateTask();
101+
executor.startAndLazilyCreateTask();
102102

103103
verify(mockClusterService, times(1)).addListener(executor);
104104
verify(persistentTasksService, never()).sendClusterStartRequest(
@@ -136,8 +136,8 @@ public void testDoesNotRegisterListener_IfUrlIsEmpty() {
136136
createMockCCMService(false)
137137
)
138138
);
139-
executor.startAndLazyCreateTask();
140-
executor.startAndLazyCreateTask();
139+
executor.startAndLazilyCreateTask();
140+
executor.startAndLazilyCreateTask();
141141

142142
verify(mockClusterService, never()).addListener(executor);
143143
verify(persistentTasksService, never()).sendClusterStartRequest(
@@ -189,7 +189,7 @@ public void testDoesNotCallSendClusterStartRequest_WhenStartIsCalled_WhenItIsAlr
189189
createMockCCMService(false)
190190
)
191191
);
192-
executor.startAndLazyCreateTask();
192+
executor.startAndLazilyCreateTask();
193193

194194
verify(mockClusterService, times(1)).addListener(executor);
195195
verify(persistentTasksService, never()).sendClusterStartRequest(
@@ -221,7 +221,7 @@ public void testCreatesTask_WhenItDoesNotExistOnClusterStateChange() {
221221
createMockCCMService(false)
222222
)
223223
);
224-
executor.startAndLazyCreateTask();
224+
executor.startAndLazilyCreateTask();
225225

226226
var listener1 = new PlainActionFuture<Void>();
227227
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, listener1);
@@ -281,7 +281,7 @@ public void testCreatesTask_WhenItDoesNotExistOnClusterStateChange_CcmSupportedA
281281
createMockCCMService(false)
282282
)
283283
);
284-
executor.startAndLazyCreateTask();
284+
executor.startAndLazilyCreateTask();
285285

286286
var listener1 = new PlainActionFuture<Void>();
287287
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, listener1);
@@ -333,7 +333,7 @@ public void testDoesNotCreateTask_WhenCcmIsSupportedButNotEnabled() {
333333
createMockCCMService(false)
334334
)
335335
);
336-
executor.startAndLazyCreateTask();
336+
executor.startAndLazilyCreateTask();
337337

338338
var listener = new PlainActionFuture<Void>();
339339
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, listener);
@@ -371,7 +371,7 @@ public void testDoesNotCreateTask_WhenFeatureIsNotSupported() {
371371
createMockCCMService(false)
372372
)
373373
);
374-
executor.startAndLazyCreateTask();
374+
executor.startAndLazilyCreateTask();
375375

376376
var listener1 = new PlainActionFuture<Void>();
377377
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, listener1);
@@ -404,7 +404,7 @@ public void testDoesNotRegisterClusterStateListener_DoesNotCreateTask_WhenTheEis
404404
createMockCCMService(false)
405405
)
406406
);
407-
executor.startAndLazyCreateTask();
407+
executor.startAndLazilyCreateTask();
408408

409409
var listener = new PlainActionFuture<Void>();
410410
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, listener);
@@ -436,7 +436,7 @@ public void testDoesNotRegisterClusterStateListener_DoesNotCreateTask_WhenTheEis
436436
createMockCCMService(false)
437437
)
438438
);
439-
executor.startAndLazyCreateTask();
439+
executor.startAndLazilyCreateTask();
440440

441441
var listener = new PlainActionFuture<Void>();
442442
clusterService.getClusterApplierService().onNewClusterState("initialization", this::initialState, listener);
@@ -491,7 +491,7 @@ public void testDoesNotCreateTask_OnClusterStateChange_WhenItAlreadyExists() {
491491
createMockCCMService(false)
492492
)
493493
);
494-
executor.startAndLazyCreateTask();
494+
executor.startAndLazilyCreateTask();
495495

496496
executor.clusterChanged(event);
497497
verify(persistentTasksService, never()).sendClusterStartRequest(

0 commit comments

Comments
 (0)