diff --git a/src/main/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspect.java b/src/main/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspect.java index 42f6ed33..0c07a0db 100644 --- a/src/main/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspect.java +++ b/src/main/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspect.java @@ -9,16 +9,18 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @Slf4j @Aspect +@RequiredArgsConstructor public class MemoryDebounceAspect { - private final ConcurrentHashMap debounceMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap debounceMap; private static final long DEBOUNCE_MILLIS = 10_000; // 10초 - private static class DebounceInfo { + public static class DebounceInfo { volatile Instant lastExecution; final ReentrantLock lock; diff --git a/src/test/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspectTest.java b/src/test/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspectTest.java index 27a3a5f0..bc93e456 100644 --- a/src/test/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspectTest.java +++ b/src/test/java/com/thirdparty/ticketing/global/waitingsystem/memory/MemoryDebounceAspectTest.java @@ -2,12 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -27,13 +29,16 @@ class MemoryDebounceAspectTest { @Autowired private MemoryDebounceAspectTest.MemoryDebounceTarget memoryDebounceTarget; + private static final ConcurrentHashMap debounceMap = + new ConcurrentHashMap<>(); + @Configuration @EnableAspectJAutoProxy static class MemoryDebounceAopConfig { @Bean public MemoryDebounceAspect memoryDebounceAspect() { - return new MemoryDebounceAspect(); + return new MemoryDebounceAspect(debounceMap); } @Bean @@ -42,7 +47,7 @@ public MemoryDebounceTarget debounceTarget() { } } - static class MemoryDebounceTarget { + public static class MemoryDebounceTarget { private final AtomicInteger counter; @@ -58,6 +63,16 @@ public void increment(long performanceId) { public int get() { return counter.get(); } + + public void reset() { + counter.set(0); + debounceMap.clear(); + } + } + + @BeforeEach + void setUp() { + memoryDebounceTarget.reset(); } @Nested