| | |
| | | } |
| | | |
| | | @Test |
| | | void coordinatorRunsAgentAndReleasesLockWhenGuardWriteFails() { |
| | | AutoTuneAgentService.AutoTuneAgentResult agentResult = successfulAgentResult(); |
| | | when(configService.getConfigValue("aiAutoTuneEnabled", "N")).thenReturn("Y"); |
| | | when(configService.getConfigValue("aiAutoTuneIntervalMinutes", "10")).thenReturn("10"); |
| | | when(wrkMastService.count(any(Wrapper.class))).thenReturn(1L); |
| | | when(redisUtil.get(RedisKeyType.AI_AUTO_TUNE_LAST_TRIGGER_GUARD.key)).thenReturn(null); |
| | | when(aiAutoTuneJobService.list(any(Wrapper.class))).thenReturn(Collections.emptyList()); |
| | | when(redisUtil.trySetStringIfAbsent(anyString(), anyString(), anyLong())).thenReturn(true); |
| | | doThrow(new RuntimeException("guard failed")) |
| | | .when(redisUtil) |
| | | .set(eq(RedisKeyType.AI_AUTO_TUNE_LAST_TRIGGER_GUARD.key), any(), eq(600L)); |
| | | when(autoTuneAgentService.runAutoTune(AutoTuneTriggerType.AUTO.getCode())).thenReturn(agentResult); |
| | | |
| | | AutoTuneCoordinatorService.AutoTuneCoordinatorResult result = coordinatorService().runAutoTuneIfEligible(); |
| | | |
| | | assertFalse(result.getSkipped()); |
| | | assertTrue(result.getTriggered()); |
| | | assertSame(agentResult, result.getAgentResult()); |
| | | verify(autoTuneAgentService).runAutoTune(AutoTuneTriggerType.AUTO.getCode()); |
| | | verify(redisUtil).compareAndDelete(anyString(), anyString()); |
| | | } |
| | | |
| | | @Test |
| | | void coordinatorSetsGuardWhenAgentReturnsFailure() { |
| | | AutoTuneAgentService.AutoTuneAgentResult agentResult = failedAgentResult(); |
| | | when(configService.getConfigValue("aiAutoTuneEnabled", "N")).thenReturn("Y"); |