Source:
<code>public void testCircuitBreakerBreak() throws Exception { String model1 = "test-circuit-break-model-1"; String model2 = "test-circuit-break-model-2"; String model3 = "test-circuit-break-model-3"; withTrainedModel(model1, 5L); withTrainedModel(model2, 5L); withTrainedModel(model3, 12L); CircuitBreaker circuitBreaker = new CustomCircuitBreaker(11); ModelLoadingService modelLoadingService = new ModelLoadingService(trainedModelProvider, auditor, threadPool, clusterService, trainedModelStatsService, Settings.EMPTY, "test-node", circuitBreaker); <START> ModelLoadedTracker loadedTracker = new ModelLoadedTracker(Arrays.asList(model1, model2)); <END> for (String modelId : Arrays.asList(model1, model2)) { modelLoadingService.addModelLoadedListener(modelId, loadedTracker.actionListener()); } modelLoadingService.addModelLoadedListener(model3, ActionListener.wrap( r -> fail("Should not have succeeded to load model as breaker should be reached"), e -> assertThat(e, instanceOf(CircuitBreakingException.class)) )); modelLoadingService.clusterChanged(ingestChangedEvent(model1, model2, model3)); assertBusy(() -> { verify(trainedModelProvider, times(1)).getTrainedModel(eq(model1), eq(false), any()); verify(trainedModelProvider, times(1)).getTrainedModel(eq(model2), eq(false), any()); verify(trainedModelProvider, times(1)).getTrainedModel(eq(model3), eq(false), any()); }); assertBusy(() -> { assertThat(circuitBreaker.getUsed(), equalTo(10L)); assertThat(circuitBreaker.getTrippedCount(), equalTo(1L)); }); modelLoadingService.clusterChanged(ingestChangedEvent(model1)); assertBusy(() -> { assertThat(circuitBreaker.getUsed(), equalTo(5L)); }); }</code><technical_language>Unused? ModelLoadedTracker is required a model is loaded necessary assertBusys behaviour is asserted</technical_language>

Target:
public void testCircuitBreakerBreak() throws Exception { String model1 = "test-circuit-break-model-1"; String model2 = "test-circuit-break-model-2"; String model3 = "test-circuit-break-model-3"; withTrainedModel(model1, 5L); withTrainedModel(model2, 5L); withTrainedModel(model3, 12L); CircuitBreaker circuitBreaker = new CustomCircuitBreaker(11); ModelLoadingService modelLoadingService = new ModelLoadingService(trainedModelProvider, auditor, threadPool, clusterService, trainedModelStatsService, Settings.EMPTY, "test-node", circuitBreaker); modelLoadingService.addModelLoadedListener(model3, ActionListener.wrap( r -> fail("Should not have succeeded to load model as breaker should be reached"), e -> assertThat(e, instanceOf(CircuitBreakingException.class)) )); modelLoadingService.clusterChanged(ingestChangedEvent(model1, model2, model3)); assertBusy(() -> { verify(trainedModelProvider, times(1)).getTrainedModel(eq(model1), eq(false), any()); verify(trainedModelProvider, times(1)).getTrainedModel(eq(model2), eq(false), any()); verify(trainedModelProvider, times(1)).getTrainedModel(eq(model3), eq(false), any()); }); assertBusy(() -> { assertThat(circuitBreaker.getUsed(), equalTo(10L)); assertThat(circuitBreaker.getTrippedCount(), equalTo(1L)); }); modelLoadingService.clusterChanged(ingestChangedEvent(model1)); assertBusy(() -> { assertThat(circuitBreaker.getUsed(), equalTo(5L)); }); }