Skip to content

Commit

Permalink
refactor: 코드 포맷 정렬
Browse files Browse the repository at this point in the history
  • Loading branch information
hseong3243 committed Aug 25, 2024
1 parent 505b80a commit cd7ecc5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

import com.thirdparty.ticketing.domain.waitingsystem.running.RunningRoom;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingMember;

import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
Expand Down Expand Up @@ -56,15 +56,16 @@ public void pullOutRunningMember(String email, long performanceId) {

public Set<String> removeExpiredMemberInfo(long performanceId) {
ConcurrentMap<String, WaitingMember> performanceRoom = room.get(performanceId);
if(performanceRoom == null) {
if (performanceRoom == null) {
return Set.of();
}

ZonedDateTime fiveMinutesAgo = ZonedDateTime.now().minusMinutes(EXPIRED_MINUTE);
Set<String> removeMemberEmails = performanceRoom.entrySet().stream()
.filter(entry -> entry.getValue().getEnteredAt().isBefore(fiveMinutesAgo))
.map(Entry::getKey)
.collect(Collectors.toSet());
Set<String> removeMemberEmails =
performanceRoom.entrySet().stream()
.filter(entry -> entry.getValue().getEnteredAt().isBefore(fiveMinutesAgo))
.map(Entry::getKey)
.collect(Collectors.toSet());
removeMemberEmails.forEach(performanceRoom::remove);
return removeMemberEmails;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MemoryWaitingRoom implements WaitingRoom {

public boolean enter(String email, long performanceId) {
return room.computeIfAbsent(performanceId, k -> new ConcurrentHashMap<>())
.putIfAbsent(email, new WaitingMember(email, performanceId))
.putIfAbsent(email, new WaitingMember(email, performanceId))
== null;
}

Expand All @@ -40,7 +40,8 @@ public void removeMemberInfo(String email, long performanceId) {
}

public void removeMemberInfo(Set<String> emails, long performanceId) {
room.computeIfPresent(performanceId,
room.computeIfPresent(
performanceId,
(key, room) -> {
emails.forEach(room::remove);
return room;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.thirdparty.ticketing.global.waitingsystem.redis.waiting;

import java.util.Optional;

import java.util.Set;

import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;

Expand Down Expand Up @@ -52,7 +52,7 @@ public void removeMemberInfo(String email, long performanceId) {
}

public void removeMemberInfo(Set<String> emails, long performanceId) {
if(emails.isEmpty()) {
if (emails.isEmpty()) {
return;
}
waitingRoom.delete(getWaitingRoomKey(performanceId), emails.toArray(String[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.common.TicketingException;
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 com.thirdparty.ticketing.support.SpyEventPublisher;
import com.thirdparty.ticketing.support.TestContainerStarter;
import java.time.ZonedDateTime;
import java.util.Set;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand All @@ -27,24 +20,29 @@
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.ZSetOperations;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.common.TicketingException;
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 com.thirdparty.ticketing.support.SpyEventPublisher;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class WaitingSystemTest extends TestContainerStarter {

private WaitingSystem waitingSystem;

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

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

private SpyEventPublisher eventPublisher;

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

@Autowired
private ObjectMapper objectMapper;
@Autowired private ObjectMapper objectMapper;

private ZSetOperations<String, String> rawRunningRoom;
private HashOperations<String, String, String> rawWaitingRoom;
Expand Down Expand Up @@ -129,7 +127,10 @@ void setUp() throws JsonProcessingException {
score = fiveMinuteAgo.toEpochSecond();

WaitingMember waitingMember = new WaitingMember(email, performanceId, 1, fiveMinuteAgo);
rawWaitingRoom.put(getWaitingRoomKey(performanceId), email, objectMapper.writeValueAsString(waitingMember));
rawWaitingRoom.put(
getWaitingRoomKey(performanceId),
email,
objectMapper.writeValueAsString(waitingMember));
rawRunningRoom.add(getRunningRoomKey(performanceId), email, score);
}

Expand All @@ -146,10 +147,7 @@ void removeExpiredMemberInfoFromRunningRoom() {

// then
Set<String> emails = rawRunningRoom.range(getRunningRoomKey(performanceId), 0, -1);
assertThat(emails)
.hasSize(1)
.first()
.isEqualTo(anotherEmail);
assertThat(emails).hasSize(1).first().isEqualTo(anotherEmail);
}

@Test
Expand All @@ -160,17 +158,17 @@ void removeExpiredMemberInfoFromWaitingRoom() throws JsonProcessingException {
ZonedDateTime now = ZonedDateTime.now();
WaitingMember waitingMember = new WaitingMember(anotherEmail, performanceId, 2, now);
rawRunningRoom.add(getRunningRoomKey(performanceId), anotherEmail, now.toEpochSecond());
rawWaitingRoom.put(getWaitingRoomKey(performanceId), anotherEmail, objectMapper.writeValueAsString(waitingMember));
rawWaitingRoom.put(
getWaitingRoomKey(performanceId),
anotherEmail,
objectMapper.writeValueAsString(waitingMember));

// when
waitingSystem.moveUserToRunning(performanceId);

// then
Set<String> emails = rawRunningRoom.range(getRunningRoomKey(performanceId), 0, -1);
assertThat(emails)
.hasSize(1)
.first()
.isEqualTo(anotherEmail);
assertThat(emails).hasSize(1).first().isEqualTo(anotherEmail);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,32 +192,34 @@ class RemoveMemberInfos {
@Test
@DisplayName("사용자 정보가 제거된다.")
void removeMemberInfo() {
//given
// given
long performanceId = 1;
String email = "[email protected]";
String email2 = "[email protected]";
waitingRoom.enter(email, performanceId);
waitingRoom.enter(email2, performanceId);

//when
// when
waitingRoom.removeMemberInfo(Set.of(email, email2), performanceId);

//then
// then
assertThat(waitingRoom.findWaitingMember(email, performanceId)).isEmpty();
assertThat(waitingRoom.findWaitingMember(email2, performanceId)).isEmpty();
}

@Test
@DisplayName("사용자 정보가 대기방에 존재하지 않으면 무시한다.")
void ignore_WhenNotExistsWaitingRoom() {
//given
// given
long performanceId = 1;
String email = "[email protected]";

//when
Exception exception = catchException(() -> waitingRoom.removeMemberInfo(Set.of(email), performanceId));
// when
Exception exception =
catchException(
() -> waitingRoom.removeMemberInfo(Set.of(email), performanceId));

//then
// then
assertThat(exception).doesNotThrowAnyException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waitingsystem.ObjectMapperUtils;
import com.thirdparty.ticketing.support.TestContainerStarter;
import java.time.ZonedDateTime;
import java.util.Optional;
import java.util.Set;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand All @@ -19,6 +16,11 @@
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.waitingsystem.waiting.WaitingMember;
import com.thirdparty.ticketing.global.waitingsystem.ObjectMapperUtils;
import com.thirdparty.ticketing.support.TestContainerStarter;

@SpringBootTest
class RedisWaitingRoomTest extends TestContainerStarter {

Expand Down Expand Up @@ -215,32 +217,34 @@ class RemoveMemberInfos {
@Test
@DisplayName("사용자 정보가 제거된다.")
void removeMemberInfo() {
//given
// given
long performanceId = 1;
String email = "[email protected]";
String email2 = "[email protected]";
waitingRoom.enter(email, performanceId);
waitingRoom.enter(email2, performanceId);

//when
// when
waitingRoom.removeMemberInfo(Set.of(email, email2), performanceId);

//then
// then
assertThat(waitingRoom.findWaitingMember(email, performanceId)).isEmpty();
assertThat(waitingRoom.findWaitingMember(email2, performanceId)).isEmpty();
}

@Test
@DisplayName("사용자 정보가 대기방에 존재하지 않으면 무시한다.")
void ignore_WhenNotExistsWaitingRoom() {
//given
// given
long performanceId = 1;
String email = "[email protected]";

//when
Exception exception = catchException(() -> waitingRoom.removeMemberInfo(Set.of(email), performanceId));
// when
Exception exception =
catchException(
() -> waitingRoom.removeMemberInfo(Set.of(email), performanceId));

//then
// then
assertThat(exception).doesNotThrowAnyException();
}
}
Expand Down

0 comments on commit cd7ecc5

Please sign in to comment.