#13 spring transaction : propagation - outerTxOff
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.example.springtransaction.propagation;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
class MemberServiceTest {
|
||||
|
||||
@Autowired
|
||||
MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
MemberRepository memberRepository;
|
||||
|
||||
@Autowired
|
||||
LogRepository logRepository;
|
||||
|
||||
/**
|
||||
* memberService @Transactional:OFF
|
||||
* memberRepository @Transactional:ON
|
||||
* logRepository @Transactional:ON
|
||||
*/
|
||||
@Test
|
||||
void outerTxOff_success() {
|
||||
//given
|
||||
String username = "outerTxOff_success";
|
||||
|
||||
//when
|
||||
memberService.joinV1(username);
|
||||
|
||||
//then: 모든 데이터가 저장된다.
|
||||
assertTrue(memberRepository.find(username).isPresent());
|
||||
assertTrue(logRepository.find(username).isPresent());
|
||||
}
|
||||
|
||||
/**
|
||||
* memberService @Transactional:OFF
|
||||
* memberRepository @Transactional:ON
|
||||
* logRepository @Transactional:ON Exception
|
||||
*/
|
||||
@Test
|
||||
void outerTxOff_fail() {
|
||||
//given
|
||||
String username = "로그예외_outerTxOff_success";
|
||||
|
||||
//when
|
||||
assertThrows(RuntimeException.class, () -> memberService.joinV1(username));
|
||||
|
||||
//then
|
||||
assertTrue(memberRepository.find(username).isPresent());
|
||||
assertTrue(logRepository.find(username).isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user