refactor: 클라이언트 버킷 상태 모니터링 custom.inflow 패키지로 분리
- InflowTargetBucketService/Controller에서 클라이언트 관련 메서드/엔드포인트 제거 - ClientInflowTargetBucketService/Controller를 custom.inflow 패키지에 신규 생성 (ClientInflowTargetMetricService/Controller 패턴과 일치) - 관련 단위 테스트 추가 및 기존 테스트에서 클라이언트 케이스 제거 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
*
|
||||
* <p>Spring MVC를 기동하지 않고 컨트롤러를 직접 인스턴스화하여
|
||||
* 응답 구조(success, data, count, message)를 검증한다.
|
||||
* 클라이언트 관련 테스트는 ClientInflowTargetBucketControllerTest 에서 검증한다.
|
||||
*/
|
||||
class InflowTargetBucketControllerTest {
|
||||
|
||||
@@ -148,64 +149,4 @@ class InflowTargetBucketControllerTest {
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertEquals(1, body.get("count"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 클라이언트 — 단일 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getClientBucketStatus_found_successTrueAndDataPresent() {
|
||||
TargetBucketStatusDTO dto = makeDTO("CLIENT_A", "CLIENT");
|
||||
when(mockService.getClientBucketStatus("CLIENT_A")).thenReturn(dto);
|
||||
|
||||
ResponseEntity<?> response = controller.getClientBucketStatus("CLIENT_A");
|
||||
Map<String, Object> body = body(response);
|
||||
|
||||
assertEquals(200, response.getStatusCodeValue());
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertSame(dto, body.get("data"));
|
||||
assertFalse(body.containsKey("message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClientBucketStatus_notFound_successFalseWithClientId() {
|
||||
when(mockService.getClientBucketStatus("CLIENT_X")).thenReturn(null);
|
||||
|
||||
ResponseEntity<?> response = controller.getClientBucketStatus("CLIENT_X");
|
||||
Map<String, Object> body = body(response);
|
||||
|
||||
assertEquals(Boolean.FALSE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("CLIENT_X"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 클라이언트 — 전체 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAllClientBucketStatus_returnsListAndCount() {
|
||||
List<TargetBucketStatusDTO> list = Arrays.asList(
|
||||
makeDTO("CLIENT_A", "CLIENT"),
|
||||
makeDTO("CLIENT_B", "CLIENT"),
|
||||
makeDTO("CLIENT_C", "CLIENT")
|
||||
);
|
||||
when(mockService.getAllClientBucketStatus()).thenReturn(list);
|
||||
|
||||
ResponseEntity<?> response = controller.getAllClientBucketStatus();
|
||||
Map<String, Object> body = body(response);
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertSame(list, body.get("data"));
|
||||
assertEquals(3, body.get("count"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllClientBucketStatus_emptyList_countZero() {
|
||||
when(mockService.getAllClientBucketStatus()).thenReturn(Collections.emptyList());
|
||||
|
||||
Map<String, Object> body = body(controller.getAllClientBucketStatus());
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertEquals(0, body.get("count"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.eactive.eai.common.inflow.InflowTargetVO;
|
||||
import com.eactive.eai.common.inflow.dual.ClientDualInflowControlManager;
|
||||
import com.eactive.eai.common.inflow.dual.DualCustomBucket;
|
||||
import com.eactive.eai.common.inflow.dual.DualInflowControlManager;
|
||||
|
||||
@@ -23,7 +22,7 @@ import io.github.bucket4j.local.LocalBucket;
|
||||
* InflowTargetBucketService 단위 테스트.
|
||||
*
|
||||
* <p>어댑터/인터페이스: getDualManager()를 오버라이드하는 서브클래스 사용.
|
||||
* 클라이언트: getClientDualManager()를 오버라이드하는 서브클래스 사용.
|
||||
* 클라이언트 관련 테스트는 ClientInflowTargetBucketServiceTest 에서 검증한다.
|
||||
*/
|
||||
class InflowTargetBucketServiceTest {
|
||||
|
||||
@@ -35,17 +34,6 @@ class InflowTargetBucketServiceTest {
|
||||
return new InflowTargetBucketService() {
|
||||
@Override
|
||||
protected DualInflowControlManager getDualManager() { return manager; }
|
||||
@Override
|
||||
protected ClientDualInflowControlManager getClientDualManager() { return null; }
|
||||
};
|
||||
}
|
||||
|
||||
private static InflowTargetBucketService serviceWithClient(ClientDualInflowControlManager manager) {
|
||||
return new InflowTargetBucketService() {
|
||||
@Override
|
||||
protected DualInflowControlManager getDualManager() { return manager; }
|
||||
@Override
|
||||
protected ClientDualInflowControlManager getClientDualManager() { return manager; }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -106,16 +94,6 @@ class InflowTargetBucketServiceTest {
|
||||
assertTrue(serviceWith(null).getAllInterfaceBucketStatus().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClientBucketStatus_managerIsNull_returnsNull() {
|
||||
assertNull(serviceWithClient(null).getClientBucketStatus("CLIENT_A"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllClientBucketStatus_managerIsNull_returnsEmptyList() {
|
||||
assertTrue(serviceWithClient(null).getAllClientBucketStatus().isEmpty());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 버킷 미존재
|
||||
// =========================================================================
|
||||
@@ -136,14 +114,6 @@ class InflowTargetBucketServiceTest {
|
||||
assertNull(serviceWith(manager).getInterfaceBucketStatus("IF_001"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClientBucketStatus_notFound_returnsNull() {
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
when(manager.getClientBucket("CLIENT_A")).thenReturn(null);
|
||||
|
||||
assertNull(serviceWithClient(manager).getClientBucketStatus("CLIENT_A"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 단일 조회 — targetType, targetId 매핑
|
||||
// =========================================================================
|
||||
@@ -176,98 +146,10 @@ class InflowTargetBucketServiceTest {
|
||||
assertEquals(2, dto.getBuckets().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClientBucketStatus_found_mapsClientType() {
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
when(manager.getClientBucket("CLIENT_A")).thenReturn(makeDualBucket("CLIENT_A", 50, 5000));
|
||||
|
||||
TargetBucketStatusDTO dto = serviceWithClient(manager).getClientBucketStatus("CLIENT_A");
|
||||
|
||||
assertNotNull(dto);
|
||||
assertEquals("CLIENT_A", dto.getTargetId());
|
||||
assertEquals("CLIENT", dto.getTargetType());
|
||||
assertTrue(dto.isActivate());
|
||||
assertEquals(2, dto.getBuckets().size());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// BucketInfo 타입별 포함 여부
|
||||
// BucketInfo 용량/시간단위 매핑
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void toDto_onlyThreshold_bucketInfoHasOneThresholdEntry() {
|
||||
InflowTargetVO vo = makeVO("C1", 0, 1000, "DAY", true);
|
||||
DualCustomBucket bucket = new DualCustomBucket(null, freshBucket(1000), vo);
|
||||
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
when(manager.getClientBucket("C1")).thenReturn(bucket);
|
||||
|
||||
TargetBucketStatusDTO dto = serviceWithClient(manager).getClientBucketStatus("C1");
|
||||
|
||||
assertEquals(1, dto.getBuckets().size());
|
||||
assertEquals("threshold", dto.getBuckets().get(0).getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDto_onlyPerSecond_bucketInfoHasOnePerSecondEntry() {
|
||||
InflowTargetVO vo = makeVO("C2", 100, 0, "SEC", true);
|
||||
DualCustomBucket bucket = new DualCustomBucket(freshBucket(100), null, vo);
|
||||
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
when(manager.getClientBucket("C2")).thenReturn(bucket);
|
||||
|
||||
TargetBucketStatusDTO dto = serviceWithClient(manager).getClientBucketStatus("C2");
|
||||
|
||||
assertEquals(1, dto.getBuckets().size());
|
||||
assertEquals("perSecond", dto.getBuckets().get(0).getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDto_bothBuckets_bucketInfoHasTwoEntries() {
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
when(manager.getClientBucket("C3")).thenReturn(makeDualBucket("C3", 100, 5000));
|
||||
|
||||
TargetBucketStatusDTO dto = serviceWithClient(manager).getClientBucketStatus("C3");
|
||||
|
||||
assertEquals(2, dto.getBuckets().size());
|
||||
assertEquals("perSecond", dto.getBuckets().get(0).getType());
|
||||
assertEquals("threshold", dto.getBuckets().get(1).getType());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 사용률 계산
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void toDto_exhaustedThreshold_usagePercentIs100() {
|
||||
InflowTargetVO vo = makeVO("C4", 0, 100, "DAY", true);
|
||||
DualCustomBucket bucket = new DualCustomBucket(null, exhaustedBucket(100), vo);
|
||||
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
when(manager.getClientBucket("C4")).thenReturn(bucket);
|
||||
|
||||
TargetBucketStatusDTO dto = serviceWithClient(manager).getClientBucketStatus("C4");
|
||||
|
||||
GroupBucketStatusDTO.BucketInfo info = dto.getBuckets().get(0);
|
||||
assertEquals(0, info.getAvailableTokens());
|
||||
assertEquals(100.0, info.getUsagePercent(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDto_freshBucket_usagePercentIsZero() {
|
||||
InflowTargetVO vo = makeVO("C5", 0, 100, "DAY", true);
|
||||
DualCustomBucket bucket = new DualCustomBucket(null, freshBucket(100), vo);
|
||||
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
when(manager.getClientBucket("C5")).thenReturn(bucket);
|
||||
|
||||
TargetBucketStatusDTO dto = serviceWithClient(manager).getClientBucketStatus("C5");
|
||||
|
||||
GroupBucketStatusDTO.BucketInfo info = dto.getBuckets().get(0);
|
||||
assertEquals(100, info.getAvailableTokens());
|
||||
assertEquals(0.0, info.getUsagePercent(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toDto_capacity_perSecondBucketInfoCapacityMatchesVO() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
@@ -288,19 +170,6 @@ class InflowTargetBucketServiceTest {
|
||||
// 전체 목록 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAllClientBucketStatus_twoEntries_returnsBoth() {
|
||||
ClientDualInflowControlManager manager = mock(ClientDualInflowControlManager.class);
|
||||
Map<String, DualCustomBucket> map = new ConcurrentHashMap<>();
|
||||
map.put("CLIENT_A", makeDualBucket("CLIENT_A", 10, 1000));
|
||||
map.put("CLIENT_B", makeDualBucket("CLIENT_B", 20, 2000));
|
||||
when(manager.getClientBucketMap()).thenReturn(map);
|
||||
|
||||
List<TargetBucketStatusDTO> result = serviceWithClient(manager).getAllClientBucketStatus();
|
||||
|
||||
assertEquals(2, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllAdapterBucketStatus_emptyMap_returnsEmptyList() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
|
||||
Reference in New Issue
Block a user