| | |
| | | verify(configService).saveConfigValue("conveyorStationTaskLimit", "10"); |
| | | verify(configService).refreshSystemConfigCache(); |
| | | verify(basStationService).update(any(Wrapper.class)); |
| | | verify(redisUtil).compareAndDelete(eq(RedisKeyType.AI_AUTO_TUNE_APPLY_LOCK.key), anyString()); |
| | | assertEquals(0, transactionManager.getJobSaveOutsideTransactionCount()); |
| | | assertEquals(0, transactionManager.getJobUpdateOutsideTransactionCount()); |
| | | } |
| | | |
| | | @Test |
| | | void rollbackAuditSaveBatchFailureRollsBackTargetWriteAndReturnsFailedAudit() { |
| | | AiAutoTuneJob latestRealJob = job(10L, "manual", "success"); |
| | | AiAutoTuneChange configChange = successChange(10L, "sys_config", "", "conveyorStationTaskLimit", "10", "15"); |
| | | when(aiAutoTuneChangeService.list(any(Wrapper.class))) |
| | | .thenReturn(List.of(configChange)) |
| | | .thenReturn(List.of(configChange)); |
| | | when(aiAutoTuneJobService.getById(10L)).thenReturn(latestRealJob); |
| | | when(configService.getOne(any(Wrapper.class))).thenReturn(config("conveyorStationTaskLimit", "15")); |
| | | when(aiAutoTuneChangeService.saveBatch(any(Collection.class))) |
| | | .thenThrow(new IllegalStateException("rollback audit failed")) |
| | | .thenReturn(true); |
| | | |
| | | AutoTuneApplyResult result = service.rollbackLastSuccessfulJob("manual rollback"); |
| | | |
| | | List<AiAutoTuneChange> changes = savedChanges(); |
| | | AiAutoTuneJob updatedJob = updatedJob(); |
| | | assertFalse(result.getSuccess()); |
| | | assertEquals("failed", updatedJob.getStatus()); |
| | | assertEquals("failed", changes.get(0).getResultStatus()); |
| | | assertTrue(changes.get(0).getRejectReason().contains("rollback audit failed")); |
| | | assertEquals(1, transactionManager.getRollbackCount()); |
| | | assertTrue(transactionManager.getJobSaveInsideTransactionCount() > 0); |
| | | assertTrue(transactionManager.getJobUpdateInsideTransactionCount() > 0); |
| | | assertEquals(0, transactionManager.getJobSaveOutsideTransactionCount()); |
| | | assertEquals(0, transactionManager.getJobUpdateOutsideTransactionCount()); |
| | | verify(configService).saveConfigValue("conveyorStationTaskLimit", "10"); |
| | | verify(configService, never()).refreshSystemConfigCache(); |
| | | verify(redisUtil).compareAndDelete(eq(RedisKeyType.AI_AUTO_TUNE_APPLY_LOCK.key), anyString()); |
| | | } |
| | | |
| | | @Test |
| | | void rollbackJobUpdateFailureRollsBackAndDoesNotSaveRunningJobOutsideTransaction() { |
| | | AiAutoTuneJob latestRealJob = job(10L, "manual", "success"); |
| | | AiAutoTuneChange configChange = successChange(10L, "sys_config", "", "conveyorStationTaskLimit", "10", "15"); |
| | | when(aiAutoTuneChangeService.list(any(Wrapper.class))) |
| | | .thenReturn(List.of(configChange)) |
| | | .thenReturn(List.of(configChange)); |
| | | when(aiAutoTuneJobService.getById(10L)).thenReturn(latestRealJob); |
| | | when(configService.getOne(any(Wrapper.class))).thenReturn(config("conveyorStationTaskLimit", "15")); |
| | | when(aiAutoTuneJobService.updateById(any(AiAutoTuneJob.class))).thenAnswer(invocation -> { |
| | | transactionManager.recordJobUpdateCall(); |
| | | return false; |
| | | }); |
| | | |
| | | IllegalStateException exception = assertThrows(IllegalStateException.class, |
| | | () -> service.rollbackLastSuccessfulJob("manual rollback")); |
| | | |
| | | assertTrue(exception.getMessage().contains("更新调参任务状态失败")); |
| | | assertEquals(2, transactionManager.getRollbackCount()); |
| | | assertEquals(0, transactionManager.getCommitCount()); |
| | | assertTrue(transactionManager.getJobSaveInsideTransactionCount() > 0); |
| | | assertTrue(transactionManager.getJobUpdateInsideTransactionCount() > 0); |
| | | assertEquals(0, transactionManager.getJobSaveOutsideTransactionCount()); |
| | | assertEquals(0, transactionManager.getJobUpdateOutsideTransactionCount()); |
| | | verify(configService).saveConfigValue("conveyorStationTaskLimit", "10"); |
| | | verify(configService, never()).refreshSystemConfigCache(); |
| | | verify(redisUtil).compareAndDelete(eq(RedisKeyType.AI_AUTO_TUNE_APPLY_LOCK.key), anyString()); |
| | | } |
| | | |
| | | @Test |
| | | void rollbackLockNotAcquiredReturnsFailedAuditWithoutTargetWrite() { |
| | | AiAutoTuneJob latestRealJob = job(10L, "manual", "success"); |
| | | AiAutoTuneChange configChange = successChange(10L, "sys_config", "", "conveyorStationTaskLimit", "10", "15"); |
| | | when(aiAutoTuneChangeService.list(any(Wrapper.class))) |
| | | .thenReturn(List.of(configChange)) |
| | | .thenReturn(List.of(configChange)); |
| | | when(aiAutoTuneJobService.getById(10L)).thenReturn(latestRealJob); |
| | | when(redisUtil.trySetStringIfAbsent(anyString(), anyString(), anyLong())).thenReturn(false); |
| | | |
| | | AutoTuneApplyResult result = service.rollbackLastSuccessfulJob("manual rollback"); |
| | | |
| | | List<AiAutoTuneChange> changes = savedChanges(); |
| | | AiAutoTuneJob updatedJob = updatedJob(); |
| | | assertFalse(result.getSuccess()); |
| | | assertEquals("failed", updatedJob.getStatus()); |
| | | assertEquals("failed", changes.get(0).getResultStatus()); |
| | | assertTrue(changes.get(0).getRejectReason().contains("锁不可用")); |
| | | assertTrue(changes.get(0).getRejectReason().contains("Redis")); |
| | | assertTrue(transactionManager.getJobSaveInsideTransactionCount() > 0); |
| | | assertTrue(transactionManager.getJobUpdateInsideTransactionCount() > 0); |
| | | assertEquals(0, transactionManager.getJobSaveOutsideTransactionCount()); |
| | | assertEquals(0, transactionManager.getJobUpdateOutsideTransactionCount()); |
| | | verify(configService, never()).saveConfigValue(any(), any()); |
| | | verify(configService, never()).refreshSystemConfigCache(); |
| | | verify(redisUtil).hasKey(RedisKeyType.AI_AUTO_TUNE_APPLY_LOCK.key); |
| | | verify(redisUtil, never()).compareAndDelete(anyString(), anyString()); |
| | | } |
| | | |
| | | @Test |