| | |
| | | import com.zy.ai.domain.autotune.AutoTuneApplyResult; |
| | | import com.zy.ai.domain.autotune.AutoTuneChangeCommand; |
| | | import com.zy.ai.domain.autotune.AutoTuneSnapshot; |
| | | import com.zy.ai.domain.autotune.AutoTuneJobStatus; |
| | | import com.zy.ai.domain.autotune.AutoTuneTriggerType; |
| | | import com.zy.ai.entity.AiAutoTuneChange; |
| | | import com.zy.ai.entity.AiAutoTuneJob; |
| | | import com.zy.ai.entity.AiPromptTemplate; |
| | | import com.zy.ai.entity.ChatCompletionRequest; |
| | | import com.zy.ai.entity.ChatCompletionResponse; |
| | | import com.zy.ai.enums.AiPromptScene; |
| | | import com.zy.ai.mcp.service.SpringAiMcpToolManager; |
| | | import com.zy.ai.mcp.tool.AutoTuneMcpTools; |
| | | import com.zy.ai.service.impl.AutoTuneAgentServiceImpl; |
| | |
| | | void manualTriggerRunsAgentWithRunningLockAndDoesNotWriteSchedulerGuard() { |
| | | AutoTuneAgentService.AutoTuneAgentResult agentResult = successfulAgentResult(); |
| | | agentResult.setTriggerType(AutoTuneTriggerType.MANUAL.getCode()); |
| | | when(configService.getConfigValue("aiAutoTuneIntervalMinutes", "10")).thenReturn("10"); |
| | | when(wrkMastService.count(any(Wrapper.class))).thenReturn(1L); |
| | | when(redisUtil.trySetStringIfAbsent(anyString(), anyString(), anyLong())).thenReturn(true); |
| | | when(autoTuneAgentService.runAutoTune(AutoTuneTriggerType.MANUAL.getCode())).thenReturn(agentResult); |
| | | |
| | |
| | | assertTrue(result.getTriggered()); |
| | | assertSame(agentResult, result.getAgentResult()); |
| | | verify(autoTuneAgentService).runAutoTune(AutoTuneTriggerType.MANUAL.getCode()); |
| | | verify(wrkMastService, never()).count(any(Wrapper.class)); |
| | | verify(redisUtil, never()).set(eq(RedisKeyType.AI_AUTO_TUNE_LAST_TRIGGER_GUARD.key), any(), anyLong()); |
| | | verify(redisUtil).compareAndDelete(anyString(), anyString()); |
| | | |
| | | ArgumentCaptor<OperateLog> operateLogCaptor = ArgumentCaptor.forClass(OperateLog.class); |
| | | verify(operateLogService).save(operateLogCaptor.capture()); |
| | | assertEquals("ai_auto_tune_manual_trigger", operateLogCaptor.getValue().getAction()); |
| | | |
| | | ArgumentCaptor<AiAutoTuneJob> jobCaptor = ArgumentCaptor.forClass(AiAutoTuneJob.class); |
| | | verify(aiAutoTuneJobService).save(jobCaptor.capture()); |
| | | AiAutoTuneJob auditJob = jobCaptor.getValue(); |
| | | assertEquals(AutoTuneTriggerType.MANUAL.getCode(), auditJob.getTriggerType()); |
| | | assertEquals(AutoTuneJobStatus.SUCCESS.getCode(), auditJob.getStatus()); |
| | | assertNotNull(auditJob.getStartTime()); |
| | | assertNotNull(auditJob.getFinishTime()); |
| | | assertEquals(1, auditJob.getHasActiveTasks()); |
| | | assertEquals(AiPromptScene.AUTO_TUNE_DISPATCH.getCode(), auditJob.getPromptSceneCode()); |
| | | assertEquals("no changes needed", auditJob.getSummary()); |
| | | assertEquals(10, auditJob.getIntervalBefore()); |
| | | assertEquals(10, auditJob.getIntervalAfter()); |
| | | assertEquals(0, auditJob.getSuccessCount()); |
| | | assertEquals(0, auditJob.getRejectCount()); |
| | | assertEquals(1, auditJob.getLlmCallCount()); |
| | | assertEquals(10, auditJob.getPromptTokens()); |
| | | assertEquals(5, auditJob.getCompletionTokens()); |
| | | assertEquals(15, auditJob.getTotalTokens()); |
| | | } |
| | | |
| | | @Test |