-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19e8ab6
commit 994dcda
Showing
11 changed files
with
92 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
doochul/src/main/java/org/doochul/config/SchedulingConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL; | ||
|
||
spring.main.allow-bean-definition-overriding=true | ||
fcm.certification.path=kwakdoochul-bbb43-firebase-adminsdk-oyokf-f075393454.json |
77 changes: 77 additions & 0 deletions
77
doochul/src/test/java/org/doochul/MemberShipServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.doochul; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.BDDMockito.then; | ||
import static org.mockito.Mockito.times; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import org.doochul.application.RedisService; | ||
import org.doochul.domain.membership.MemberShip; | ||
import org.doochul.domain.membership.MemberShipRepository; | ||
import org.doochul.domain.product.Product; | ||
import org.doochul.domain.product.ProductRepository; | ||
import org.doochul.domain.product.ProductType; | ||
import org.doochul.domain.user.User; | ||
import org.doochul.domain.user.UserRepository; | ||
import org.doochul.ui.dto.ProductRegisterRequest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
@SpringBootTest | ||
public class MemberShipServiceTest { | ||
|
||
@MockBean | ||
private MemberShipRepository memberShipRepository; | ||
|
||
@Autowired | ||
private ProductRepository productRepository; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Autowired | ||
private RedisService redisService; | ||
|
||
@Test | ||
void memberShip_save() throws InterruptedException { | ||
// Given | ||
User user = User.of("123", "1234"); | ||
User teacher = User.of("1234", "123"); | ||
|
||
userRepository.save(user); | ||
userRepository.save(teacher); | ||
|
||
Product product = Product.of(teacher, new ProductRegisterRequest("페이커", ProductType.LOL, 10)); | ||
productRepository.save(product); | ||
|
||
ExecutorService executorService = Executors.newFixedThreadPool(5); | ||
CountDownLatch latch = new CountDownLatch(5); | ||
|
||
given(memberShipRepository.save(any())).willReturn(new MemberShip(1L, user, product, 10)); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
executorService.submit(() -> { | ||
try { | ||
final String key = Long.toString(user.getId()); | ||
if (redisService.setNX(key, "apply", Duration.ofSeconds(5))) { | ||
memberShipRepository.save(MemberShip.of(user, product, product.getCount())); | ||
redisService.delete(key); | ||
} | ||
} finally { | ||
latch.countDown(); | ||
} | ||
}); | ||
} | ||
|
||
latch.await(); | ||
executorService.shutdown(); | ||
|
||
then(memberShipRepository).should(times(1)).save(any()); | ||
} | ||
} |