Skip to content

Commit

Permalink
refactor: 코드 포맷 정렬
Browse files Browse the repository at this point in the history
  • Loading branch information
hseong3243 committed Aug 18, 2024
1 parent e19c27e commit f01d003
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.thirdparty.ticketing.domain.waitingsystem;

import java.util.Set;

import com.thirdparty.ticketing.domain.common.EventPublisher;
import com.thirdparty.ticketing.domain.waitingsystem.running.RunningManager;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingManager;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingMember;
import java.util.Set;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Debounce {
}
public @interface Debounce {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.thirdparty.ticketing.global.waitingsystem.redis;

import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
Expand All @@ -10,6 +10,8 @@
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Aspect
@Component
Expand All @@ -26,7 +28,8 @@ public DebounceAspect(StringRedisTemplate redisTemplate) {
@Pointcut("@annotation(com.thirdparty.ticketing.global.waitingsystem.Debounce)")
private void debounceAnnotation() {}

@Pointcut("execution(public void com.thirdparty.ticketing.domain.waitingsystem.WaitingSystem.moveUserToRunning(long))")
@Pointcut(
"execution(public void com.thirdparty.ticketing.domain.waitingsystem.WaitingSystem.moveUserToRunning(long))")
private void moveWaitingMemberToRunning() {}

@Around("debounceAnnotation() || moveWaitingMemberToRunning()")
Expand All @@ -37,10 +40,7 @@ public Object debounce(ProceedingJoinPoint joinPoint) throws Throwable {
performanceId = (long) arg;
}
}
if (debounce.setIfAbsent(
getDebounceKey(performanceId),
"debounce",
10, TimeUnit.SECONDS)) {
if (debounce.setIfAbsent(getDebounceKey(performanceId), "debounce", 10, TimeUnit.SECONDS)) {
log.info("[waiting] 디바운스 요청 실행. 공연 ID={}", performanceId);
return joinPoint.proceed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.thirdparty.ticketing.domain.waitingsystem.running.RunningManager;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingManager;
import com.thirdparty.ticketing.global.waitingsystem.redis.TestRedisConfig;
import com.thirdparty.ticketing.support.SpyEventPublisher;
import com.thirdparty.ticketing.support.TestContainerStarter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand All @@ -19,24 +14,25 @@
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import com.thirdparty.ticketing.domain.waitingsystem.running.RunningManager;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingManager;
import com.thirdparty.ticketing.global.waitingsystem.redis.TestRedisConfig;
import com.thirdparty.ticketing.support.SpyEventPublisher;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
@Import(TestRedisConfig.class)
class WaitingSystemTest extends TestContainerStarter {

@Autowired
private WaitingSystem waitingSystem;
@Autowired private WaitingSystem waitingSystem;

@Autowired
private WaitingManager waitingManager;
@Autowired private WaitingManager waitingManager;

@Autowired
private RunningManager runningManager;
@Autowired private RunningManager runningManager;

@Autowired
private SpyEventPublisher eventPublisher;
@Autowired private SpyEventPublisher eventPublisher;

@Autowired
private StringRedisTemplate redisTemplate;
@Autowired private StringRedisTemplate redisTemplate;

private ValueOperations<String, String> rawRunningCounter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.thirdparty.ticketing.global.waitingsystem.Debounce;
import com.thirdparty.ticketing.global.waitingsystem.redis.DebounceAspectTest.TestConfig;
import com.thirdparty.ticketing.support.TestContainerStarter;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand All @@ -18,12 +16,15 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

import com.thirdparty.ticketing.global.waitingsystem.Debounce;
import com.thirdparty.ticketing.global.waitingsystem.redis.DebounceAspectTest.TestConfig;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
@Import(TestConfig.class)
class DebounceAspectTest extends TestContainerStarter {

@Autowired
private DebounceTarget debounceTarget;
@Autowired private DebounceTarget debounceTarget;

@TestConfiguration
static class TestConfig {
Expand Down Expand Up @@ -52,32 +53,32 @@ public int get() {
}
}


@Nested
@DisplayName("디바운스 aop 적용 시")
class DebounceTest {

@Test
@DisplayName("동시에 한 번만 실행된다.")
void debounce() throws InterruptedException {
//given
// given
int poolSize = 100;
ExecutorService executorService = Executors.newFixedThreadPool(poolSize);
CountDownLatch latch = new CountDownLatch(poolSize);

//when
// when
for (int i = 0; i < poolSize; i++) {
executorService.execute(() -> {
try {
debounceTarget.increment();
} finally {
latch.countDown();
}
});
executorService.execute(
() -> {
try {
debounceTarget.increment();
} finally {
latch.countDown();
}
});
}
latch.await();

//then
// then
assertThat(debounceTarget.get()).isEqualTo(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.thirdparty.ticketing.global.waitingsystem.redis;

import com.thirdparty.ticketing.domain.waitingsystem.WaitingSystem;
import com.thirdparty.ticketing.support.SpyEventPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.waitingsystem.WaitingSystem;
import com.thirdparty.ticketing.global.waitingsystem.redis.running.RedisRunningCounter;
import com.thirdparty.ticketing.global.waitingsystem.redis.running.RedisRunningManager;
import com.thirdparty.ticketing.global.waitingsystem.redis.running.RedisRunningRoom;
import com.thirdparty.ticketing.global.waitingsystem.redis.waiting.RedisWaitingCounter;
import com.thirdparty.ticketing.global.waitingsystem.redis.waiting.RedisWaitingLine;
import com.thirdparty.ticketing.global.waitingsystem.redis.waiting.RedisWaitingManager;
import com.thirdparty.ticketing.global.waitingsystem.redis.waiting.RedisWaitingRoom;
import com.thirdparty.ticketing.support.SpyEventPublisher;

@TestConfiguration
public class TestRedisConfig {
Expand Down

0 comments on commit f01d003

Please sign in to comment.