feat: 어댑터/인터페이스/클라이언트 유량제어 메트릭 API 추가
InflowTargetMetricController / InflowTargetMetricService / TargetMetricDTO 추가. 어댑터·인터페이스·클라이언트별 허용/초당거절/임계거절 카운터 조회 및 초기화 API 제공. 단위테스트: InflowTargetMetricServiceTest(26건), InflowTargetMetricControllerTest(16건). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,301 @@
|
||||
package com.eactive.eai.manage.inflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* InflowTargetMetricController 단위 테스트.
|
||||
*
|
||||
* <p>Spring MVC를 기동하지 않고 컨트롤러를 직접 인스턴스화하여
|
||||
* 응답 구조(success, data, count, message)를 검증한다.
|
||||
*/
|
||||
class InflowTargetMetricControllerTest {
|
||||
|
||||
private InflowTargetMetricController controller;
|
||||
private InflowTargetMetricService mockService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
controller = new InflowTargetMetricController();
|
||||
mockService = mock(InflowTargetMetricService.class);
|
||||
ReflectionTestUtils.setField(controller, "metricService", mockService);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Helper
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private TargetMetricDTO makeDTO(String targetId, String targetType,
|
||||
long allowed, long rejPs, long rejTh) {
|
||||
TargetMetricDTO dto = new TargetMetricDTO();
|
||||
dto.setTargetId(targetId);
|
||||
dto.setTargetType(targetType);
|
||||
dto.setActivate(true);
|
||||
dto.setAllowed(allowed);
|
||||
dto.setRejectedPerSecond(rejPs);
|
||||
dto.setRejectedThreshold(rejTh);
|
||||
long total = allowed + rejPs + rejTh;
|
||||
dto.setTotalRequests(total);
|
||||
dto.setRejectRatio(total > 0 ? (double)(rejPs + rejTh) / total * 100 : 0.0);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> body(ResponseEntity<?> response) {
|
||||
return (Map<String, Object>) response.getBody();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 어댑터 — 단일 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAdapterMetric_found_successTrueAndDataPresent() {
|
||||
TargetMetricDTO dto = makeDTO("A1", "ADAPTER", 900, 60, 40);
|
||||
when(mockService.getAdapterMetric("A1")).thenReturn(dto);
|
||||
|
||||
ResponseEntity<?> response = controller.getAdapterMetric("A1");
|
||||
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 getAdapterMetric_notFound_successFalseWithMessage() {
|
||||
when(mockService.getAdapterMetric("GHOST")).thenReturn(null);
|
||||
|
||||
Map<String, Object> body = body(controller.getAdapterMetric("GHOST"));
|
||||
|
||||
assertEquals(Boolean.FALSE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("GHOST"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 어댑터 — 전체 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAllAdapterMetrics_returnsListAndCount() {
|
||||
List<TargetMetricDTO> list = Arrays.asList(
|
||||
makeDTO("A1", "ADAPTER", 100, 5, 0),
|
||||
makeDTO("A2", "ADAPTER", 200, 0, 10)
|
||||
);
|
||||
when(mockService.getAllAdapterMetrics()).thenReturn(list);
|
||||
|
||||
Map<String, Object> body = body(controller.getAllAdapterMetrics());
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertSame(list, body.get("data"));
|
||||
assertEquals(2, body.get("count"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllAdapterMetrics_emptyList_countZero() {
|
||||
when(mockService.getAllAdapterMetrics()).thenReturn(Collections.emptyList());
|
||||
|
||||
Map<String, Object> body = body(controller.getAllAdapterMetrics());
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertEquals(0, body.get("count"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 어댑터 — reset
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void resetAdapterMetric_success_successTrueWithTargetId() {
|
||||
when(mockService.resetAdapterMetric("A1")).thenReturn(true);
|
||||
|
||||
Map<String, Object> body = body(controller.resetAdapterMetric("A1"));
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("A1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAdapterMetric_notFound_successFalseWithTargetId() {
|
||||
when(mockService.resetAdapterMetric("GHOST")).thenReturn(false);
|
||||
|
||||
Map<String, Object> body = body(controller.resetAdapterMetric("GHOST"));
|
||||
|
||||
assertEquals(Boolean.FALSE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("GHOST"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAllAdapterMetrics_alwaysSuccessTrue() {
|
||||
doNothing().when(mockService).resetAllAdapterMetrics();
|
||||
|
||||
Map<String, Object> body = body(controller.resetAllAdapterMetrics());
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertNotNull(body.get("message"));
|
||||
verify(mockService).resetAllAdapterMetrics();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 인터페이스 — 단일 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getInterfaceMetric_found_successTrueAndDataPresent() {
|
||||
TargetMetricDTO dto = makeDTO("IF1", "INTERFACE", 500, 20, 10);
|
||||
when(mockService.getInterfaceMetric("IF1")).thenReturn(dto);
|
||||
|
||||
Map<String, Object> body = body(controller.getInterfaceMetric("IF1"));
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertSame(dto, body.get("data"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getInterfaceMetric_notFound_successFalseWithMessage() {
|
||||
when(mockService.getInterfaceMetric("GHOST")).thenReturn(null);
|
||||
|
||||
Map<String, Object> body = body(controller.getInterfaceMetric("GHOST"));
|
||||
|
||||
assertEquals(Boolean.FALSE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("GHOST"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 인터페이스 — 전체 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAllInterfaceMetrics_returnsListAndCount() {
|
||||
List<TargetMetricDTO> list = Collections.singletonList(
|
||||
makeDTO("IF1", "INTERFACE", 100, 0, 0));
|
||||
when(mockService.getAllInterfaceMetrics()).thenReturn(list);
|
||||
|
||||
Map<String, Object> body = body(controller.getAllInterfaceMetrics());
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertEquals(1, body.get("count"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 인터페이스 — reset
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void resetInterfaceMetric_success_successTrue() {
|
||||
when(mockService.resetInterfaceMetric("IF1")).thenReturn(true);
|
||||
|
||||
Map<String, Object> body = body(controller.resetInterfaceMetric("IF1"));
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("IF1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAllInterfaceMetrics_callsDelegateOnce() {
|
||||
doNothing().when(mockService).resetAllInterfaceMetrics();
|
||||
|
||||
controller.resetAllInterfaceMetrics();
|
||||
|
||||
verify(mockService, times(1)).resetAllInterfaceMetrics();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 클라이언트 — 단일 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getClientMetric_found_successTrueAndDataPresent() {
|
||||
TargetMetricDTO dto = makeDTO("C1", "CLIENT", 300, 50, 20);
|
||||
when(mockService.getClientMetric("C1")).thenReturn(dto);
|
||||
|
||||
Map<String, Object> body = body(controller.getClientMetric("C1"));
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertSame(dto, body.get("data"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClientMetric_notFound_successFalseWithMessage() {
|
||||
when(mockService.getClientMetric("GHOST")).thenReturn(null);
|
||||
|
||||
Map<String, Object> body = body(controller.getClientMetric("GHOST"));
|
||||
|
||||
assertEquals(Boolean.FALSE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("GHOST"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 클라이언트 — 전체 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAllClientMetrics_returnsListAndCount() {
|
||||
List<TargetMetricDTO> list = Arrays.asList(
|
||||
makeDTO("C1", "CLIENT", 100, 5, 5),
|
||||
makeDTO("C2", "CLIENT", 200, 0, 0),
|
||||
makeDTO("C3", "CLIENT", 50, 10, 0)
|
||||
);
|
||||
when(mockService.getAllClientMetrics()).thenReturn(list);
|
||||
|
||||
Map<String, Object> body = body(controller.getAllClientMetrics());
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertSame(list, body.get("data"));
|
||||
assertEquals(3, body.get("count"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllClientMetrics_emptyList_countZero() {
|
||||
when(mockService.getAllClientMetrics()).thenReturn(Collections.emptyList());
|
||||
|
||||
Map<String, Object> body = body(controller.getAllClientMetrics());
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertEquals(0, body.get("count"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 클라이언트 — reset
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void resetClientMetric_success_successTrue() {
|
||||
when(mockService.resetClientMetric("C1")).thenReturn(true);
|
||||
|
||||
Map<String, Object> body = body(controller.resetClientMetric("C1"));
|
||||
|
||||
assertEquals(Boolean.TRUE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("C1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetClientMetric_notFound_successFalse() {
|
||||
when(mockService.resetClientMetric("GHOST")).thenReturn(false);
|
||||
|
||||
Map<String, Object> body = body(controller.resetClientMetric("GHOST"));
|
||||
|
||||
assertEquals(Boolean.FALSE, body.get("success"));
|
||||
assertTrue(body.get("message").toString().contains("GHOST"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAllClientMetrics_callsDelegateOnce() {
|
||||
doNothing().when(mockService).resetAllClientMetrics();
|
||||
|
||||
controller.resetAllClientMetrics();
|
||||
|
||||
verify(mockService, times(1)).resetAllClientMetrics();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
package com.eactive.eai.manage.inflow;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.eactive.eai.common.inflow.InflowTargetVO;
|
||||
import com.eactive.eai.common.inflow.dual.DualInflowControlManager;
|
||||
|
||||
/**
|
||||
* InflowTargetMetricService 단위 테스트.
|
||||
*
|
||||
* <p>getDualManager()를 오버라이드하여 DualInflowControlManager 의존성을 주입한다.
|
||||
*/
|
||||
class InflowTargetMetricServiceTest {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 테스트용 서브클래스
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private static InflowTargetMetricService serviceWith(DualInflowControlManager manager) {
|
||||
return new InflowTargetMetricService() {
|
||||
@Override
|
||||
protected DualInflowControlManager getDualManager() { return manager; }
|
||||
};
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private InflowTargetVO makeVO(String name) {
|
||||
InflowTargetVO vo = new InflowTargetVO();
|
||||
vo.setName(name);
|
||||
vo.setActivate(true);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private DualInflowControlManager.TargetMetrics makeMetrics(long allowed, long rejPs, long rejTh) {
|
||||
DualInflowControlManager.TargetMetrics m = new DualInflowControlManager.TargetMetrics();
|
||||
m.allowed.set(allowed);
|
||||
m.rejectedPerSecond.set(rejPs);
|
||||
m.rejectedThreshold.set(rejTh);
|
||||
return m;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// DualManager null (비활성 환경)
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAdapterMetric_managerIsNull_returnsNull() {
|
||||
assertNull(serviceWith(null).getAdapterMetric("A1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllAdapterMetrics_managerIsNull_returnsEmptyList() {
|
||||
assertTrue(serviceWith(null).getAllAdapterMetrics().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAdapterMetric_managerIsNull_returnsFalse() {
|
||||
assertFalse(serviceWith(null).resetAdapterMetric("A1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAllAdapterMetrics_managerIsNull_noException() {
|
||||
assertDoesNotThrow(() -> serviceWith(null).resetAllAdapterMetrics());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getInterfaceMetric_managerIsNull_returnsNull() {
|
||||
assertNull(serviceWith(null).getInterfaceMetric("IF1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClientMetric_managerIsNull_returnsNull() {
|
||||
assertNull(serviceWith(null).getClientMetric("C1"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 어댑터 — 단일 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAdapterMetric_notRegistered_returnsNull() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(null);
|
||||
|
||||
assertNull(serviceWith(manager).getAdapterMetric("A1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAdapterMetric_found_mapsFields() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(makeVO("A1"));
|
||||
when(manager.getAdapterMetrics("A1")).thenReturn(makeMetrics(900, 60, 40));
|
||||
|
||||
TargetMetricDTO dto = serviceWith(manager).getAdapterMetric("A1");
|
||||
|
||||
assertNotNull(dto);
|
||||
assertEquals("A1", dto.getTargetId());
|
||||
assertEquals("ADAPTER", dto.getTargetType());
|
||||
assertTrue(dto.isActivate());
|
||||
assertEquals(900, dto.getAllowed());
|
||||
assertEquals(60, dto.getRejectedPerSecond());
|
||||
assertEquals(40, dto.getRejectedThreshold());
|
||||
assertEquals(1000, dto.getTotalRequests());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAdapterMetric_noMetricsYet_returnsZeroCounters() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(makeVO("A1"));
|
||||
when(manager.getAdapterMetrics("A1")).thenReturn(null);
|
||||
|
||||
TargetMetricDTO dto = serviceWith(manager).getAdapterMetric("A1");
|
||||
|
||||
assertNotNull(dto);
|
||||
assertEquals(0, dto.getAllowed());
|
||||
assertEquals(0, dto.getTotalRequests());
|
||||
assertEquals(0.0, dto.getRejectRatio(), 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAdapterMetric_rejectRatioCalculation() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(makeVO("A1"));
|
||||
// allowed=90, rejPs=5, rejTh=5 → reject=10/100 = 10.00%
|
||||
when(manager.getAdapterMetrics("A1")).thenReturn(makeMetrics(90, 5, 5));
|
||||
|
||||
TargetMetricDTO dto = serviceWith(manager).getAdapterMetric("A1");
|
||||
|
||||
assertEquals(10.0, dto.getRejectRatio(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAdapterMetric_zeroTotal_rejectRatioIsZero() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(makeVO("A1"));
|
||||
when(manager.getAdapterMetrics("A1")).thenReturn(makeMetrics(0, 0, 0));
|
||||
|
||||
TargetMetricDTO dto = serviceWith(manager).getAdapterMetric("A1");
|
||||
|
||||
assertEquals(0.0, dto.getRejectRatio(), 0.0001);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 어댑터 — 전체 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getAllAdapterMetrics_twoEntries_returnsBoth() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterAllKeys()).thenReturn(new String[]{"A1", "A2"});
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(makeVO("A1"));
|
||||
when(manager.getAdapterInflowThreashold("A2")).thenReturn(makeVO("A2"));
|
||||
when(manager.getAdapterMetrics("A1")).thenReturn(makeMetrics(10, 0, 0));
|
||||
when(manager.getAdapterMetrics("A2")).thenReturn(makeMetrics(20, 5, 0));
|
||||
|
||||
List<TargetMetricDTO> result = serviceWith(manager).getAllAdapterMetrics();
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("A1", result.get(0).getTargetId());
|
||||
assertEquals("A2", result.get(1).getTargetId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllAdapterMetrics_noKeys_returnsEmptyList() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterAllKeys()).thenReturn(new String[]{});
|
||||
|
||||
assertTrue(serviceWith(manager).getAllAdapterMetrics().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllAdapterMetrics_notRegisteredSkipped() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterAllKeys()).thenReturn(new String[]{"A1", "GHOST"});
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(makeVO("A1"));
|
||||
when(manager.getAdapterInflowThreashold("GHOST")).thenReturn(null);
|
||||
when(manager.getAdapterMetrics("A1")).thenReturn(null);
|
||||
|
||||
List<TargetMetricDTO> result = serviceWith(manager).getAllAdapterMetrics();
|
||||
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("A1", result.get(0).getTargetId());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 어댑터 — reset
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void resetAdapterMetric_notRegistered_returnsFalse() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(null);
|
||||
|
||||
assertFalse(serviceWith(manager).resetAdapterMetric("A1"));
|
||||
verify(manager, never()).resetAdapterMetrics(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAdapterMetric_success_returnsTrueAndCallsManager() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getAdapterInflowThreashold("A1")).thenReturn(makeVO("A1"));
|
||||
|
||||
assertTrue(serviceWith(manager).resetAdapterMetric("A1"));
|
||||
verify(manager).resetAdapterMetrics("A1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAllAdapterMetrics_callsManager() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
|
||||
serviceWith(manager).resetAllAdapterMetrics();
|
||||
|
||||
verify(manager).resetAllAdapterMetrics();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 인터페이스 — 단일 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getInterfaceMetric_found_mapsFields() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getInterfaceInflowThreashold("IF1")).thenReturn(makeVO("IF1"));
|
||||
when(manager.getInterfaceMetrics("IF1")).thenReturn(makeMetrics(50, 10, 5));
|
||||
|
||||
TargetMetricDTO dto = serviceWith(manager).getInterfaceMetric("IF1");
|
||||
|
||||
assertNotNull(dto);
|
||||
assertEquals("IF1", dto.getTargetId());
|
||||
assertEquals("INTERFACE", dto.getTargetType());
|
||||
assertEquals(50, dto.getAllowed());
|
||||
assertEquals(65, dto.getTotalRequests());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getInterfaceMetric_notRegistered_returnsNull() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getInterfaceInflowThreashold("IF1")).thenReturn(null);
|
||||
|
||||
assertNull(serviceWith(manager).getInterfaceMetric("IF1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetInterfaceMetric_success_returnsTrueAndCallsManager() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getInterfaceInflowThreashold("IF1")).thenReturn(makeVO("IF1"));
|
||||
|
||||
assertTrue(serviceWith(manager).resetInterfaceMetric("IF1"));
|
||||
verify(manager).resetInterfaceMetrics("IF1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetInterfaceMetric_notRegistered_returnsFalse() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getInterfaceInflowThreashold("IF1")).thenReturn(null);
|
||||
|
||||
assertFalse(serviceWith(manager).resetInterfaceMetric("IF1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAllInterfaceMetrics_callsManager() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
serviceWith(manager).resetAllInterfaceMetrics();
|
||||
verify(manager).resetAllInterfaceMetrics();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 클라이언트 — 단일 조회
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void getClientMetric_found_mapsFields() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getClientInflowThreshold("C1")).thenReturn(makeVO("C1"));
|
||||
when(manager.getClientMetrics("C1")).thenReturn(makeMetrics(200, 30, 20));
|
||||
|
||||
TargetMetricDTO dto = serviceWith(manager).getClientMetric("C1");
|
||||
|
||||
assertNotNull(dto);
|
||||
assertEquals("C1", dto.getTargetId());
|
||||
assertEquals("CLIENT", dto.getTargetType());
|
||||
assertEquals(200, dto.getAllowed());
|
||||
assertEquals(250, dto.getTotalRequests());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClientMetric_notRegistered_returnsNull() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getClientInflowThreshold("C1")).thenReturn(null);
|
||||
|
||||
assertNull(serviceWith(manager).getClientMetric("C1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetClientMetric_success_returnsTrueAndCallsManager() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getClientInflowThreshold("C1")).thenReturn(makeVO("C1"));
|
||||
|
||||
assertTrue(serviceWith(manager).resetClientMetric("C1"));
|
||||
verify(manager).resetClientMetrics("C1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetClientMetric_notRegistered_returnsFalse() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
when(manager.getClientInflowThreshold("C1")).thenReturn(null);
|
||||
|
||||
assertFalse(serviceWith(manager).resetClientMetric("C1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resetAllClientMetrics_callsManager() {
|
||||
DualInflowControlManager manager = mock(DualInflowControlManager.class);
|
||||
serviceWith(manager).resetAllClientMetrics();
|
||||
verify(manager).resetAllClientMetrics();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user