Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 메모리 대기열 테스트 오류 수정 #102

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long, DebounceInfo> debounceMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Long, DebounceInfo> debounceMap;
private static final long DEBOUNCE_MILLIS = 10_000; // 10초

private static class DebounceInfo {
public static class DebounceInfo {
volatile Instant lastExecution;
final ReentrantLock lock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,13 +29,16 @@ class MemoryDebounceAspectTest {

@Autowired private MemoryDebounceAspectTest.MemoryDebounceTarget memoryDebounceTarget;

private static final ConcurrentHashMap<Long, MemoryDebounceAspect.DebounceInfo> debounceMap =
new ConcurrentHashMap<>();

@Configuration
@EnableAspectJAutoProxy
static class MemoryDebounceAopConfig {

@Bean
public MemoryDebounceAspect memoryDebounceAspect() {
return new MemoryDebounceAspect();
return new MemoryDebounceAspect(debounceMap);
}

@Bean
Expand All @@ -42,7 +47,7 @@ public MemoryDebounceTarget debounceTarget() {
}
}

static class MemoryDebounceTarget {
public static class MemoryDebounceTarget {

private final AtomicInteger counter;

Expand All @@ -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
Expand Down
Loading