8900966d71
- DualBucket 인터페이스에서 클라이언트 메서드 분리 → ClientDualBucket 신규 인터페이스 - DualInflowControlManager 클라이언트 구현 분리 → ClientDualInflowControlManager - DualInflowControlManager @Component 제거 (ClientDualInflowControlManager가 단일 빈) - makeBucket: Bandwidth.simple → Bandwidth.classic + Refill.greedy/intervally 변경 (threshold 버킷을 진짜 기간 쿼터로 동작하도록 수정) - DualRequestProcessor → eapim-online custom 패키지로 이동 (삭제) - ReloadInflowClientControlCommand / RemoveInflowClientControlCommand: instanceof 타입을 ClientDualInflowControlManager로 변경 - 단위 테스트: ClientDualInflowControlManagerMetricsTest 추가, DualInflowControlManagerMetricsTest 클라이언트 케이스 분리 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
97 lines
3.5 KiB
Java
97 lines
3.5 KiB
Java
package com.eactive.eai.agent.inflow;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.mockito.Mockito.*;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
import com.eactive.eai.agent.command.CommandException;
|
|
import com.eactive.eai.common.inflow.InflowControlManager;
|
|
import com.eactive.eai.common.inflow.InflowControlUtil;
|
|
import com.eactive.eai.common.inflow.dual.ClientDualInflowControlManager;
|
|
|
|
/**
|
|
* RemoveInflowClientControlCommand 단위 테스트.
|
|
*
|
|
* <p>InflowControlUtil의 cachedInflowControlManager 필드에 mock을 직접 주입하여
|
|
* PropManager/ApplicationContext 없이 동작을 검증한다.
|
|
*/
|
|
class RemoveInflowClientControlCommandTest {
|
|
|
|
private ClientDualInflowControlManager mockDualManager;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
mockDualManager = mock(ClientDualInflowControlManager.class);
|
|
ReflectionTestUtils.setField(InflowControlUtil.class, "cachedInflowControlManager", null);
|
|
}
|
|
|
|
@AfterEach
|
|
void tearDown() {
|
|
ReflectionTestUtils.setField(InflowControlUtil.class, "cachedInflowControlManager", null);
|
|
}
|
|
|
|
private RemoveInflowClientControlCommand commandWith(Object args) {
|
|
RemoveInflowClientControlCommand cmd = new RemoveInflowClientControlCommand();
|
|
cmd.setArgs(args);
|
|
return cmd;
|
|
}
|
|
|
|
// =========================================================================
|
|
// args 타입 검증 실패
|
|
// =========================================================================
|
|
|
|
@Test
|
|
void execute_argsIsInteger_throwsCommandException() {
|
|
assertThrows(CommandException.class, commandWith(Integer.valueOf(1))::execute);
|
|
}
|
|
|
|
// =========================================================================
|
|
// ClientDualInflowControlManager 비활성
|
|
// =========================================================================
|
|
|
|
@Test
|
|
void execute_notClientDualManager_throwsCommandException() {
|
|
InflowControlManager baseMgr = mock(InflowControlManager.class);
|
|
ReflectionTestUtils.setField(InflowControlUtil.class, "cachedInflowControlManager", baseMgr);
|
|
|
|
assertThrows(CommandException.class, commandWith("CLIENT_A")::execute);
|
|
}
|
|
|
|
// =========================================================================
|
|
// 정상 제거
|
|
// =========================================================================
|
|
|
|
@Test
|
|
void execute_validClientId_callsRemoveClient() throws CommandException {
|
|
ReflectionTestUtils.setField(InflowControlUtil.class, "cachedInflowControlManager", mockDualManager);
|
|
|
|
Object result = commandWith("CLIENT_A").execute();
|
|
|
|
assertEquals("success", result);
|
|
verify(mockDualManager).removeClient("CLIENT_A");
|
|
}
|
|
|
|
@Test
|
|
void execute_differentClientId_callsRemoveClientWithThatId() throws Exception {
|
|
ReflectionTestUtils.setField(InflowControlUtil.class, "cachedInflowControlManager", mockDualManager);
|
|
|
|
commandWith("CLIENT_B").execute();
|
|
|
|
verify(mockDualManager).removeClient("CLIENT_B");
|
|
}
|
|
|
|
@Test
|
|
void execute_validClientId_doesNotCallReload() throws Exception {
|
|
ReflectionTestUtils.setField(InflowControlUtil.class, "cachedInflowControlManager", mockDualManager);
|
|
|
|
commandWith("CLIENT_A").execute();
|
|
|
|
verify(mockDualManager, never()).reloadClient();
|
|
verify(mockDualManager, never()).reloadClient(anyString());
|
|
}
|
|
}
|