오늘도 에러가 떴다. 이제 RDS에 접근 가능한데 @Transcational이 안된다.
일단 배포가 완료된 사진 첨부!
그리고 에러 로그 첨부! travis CI가 테스트코드 먼저 실행하면서 뜬 에러다.
MemberServiceIntegrationTest > join() FAILED
org.springframework.transaction.CannotCreateTransactionException at JpaTransactionManager.java:448
Caused by: org.hibernate.exception.JDBCConnectionException at SQLExceptionTypeDelegate.java:48
Caused by: java.sql.SQLNonTransientConnectionException at ExceptionFactory.java:73
Caused by: java.sql.SQLNonTransientConnectionException at ExceptionFactory.java:73
Caused by: java.net.SocketTimeoutException at PlainSocketImpl.java:-2
MemberServiceIntegrationTest > 회원_중복_예외() FAILED
org.springframework.transaction.CannotCreateTransactionException at JpaTransactionManager.java:448
Caused by: org.hibernate.exception.JDBCConnectionException at SQLExceptionTypeDelegate.java:48
Caused by: java.sql.SQLNonTransientConnectionException at ExceptionFactory.java:73
Caused by: java.sql.SQLNonTransientConnectionException at ExceptionFactory.java:73
Caused by: java.net.SocketTimeoutException at PlainSocketImpl.java:-2
2021-06-01 10:33:06.075 INFO 4707 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2021-06-01 10:33:06.077 INFO 4707 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
package hello.hellospring.service;
import hello.hellospring.domain.Member;
import hello.hellospring.repository.MemoryMemberRepository;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
class MemberServiceTest {
MemoryMemberRepository memberRepository;
MemberService memberService;
@BeforeEach
public void beforeEach(){
memberRepository = new MemoryMemberRepository();
memberService = new MemberService(memberRepository);
}
@AfterEach
public void afterEach(){
memberRepository.clearStore();
}
@Test
void join() {
//given
Member member = new Member();
member.setName("test1");
//when
Long saveId = memberService.join(member);
//then
Member findMember = memberService.findOne(saveId).get();
assertThat(findMember.getName()).isEqualTo(member.getName());
}
@Test
public void 회원_중복_예외() {
//given
Member member1 = new Member();
member1.setName("test");
Member member2 = new Member();
member2.setName("test");
//when
memberService.join(member1);
//then
IllegalStateException e = assertThrows(IllegalStateException.class, () -> memberService.join(member2));
assertThat(e.getMessage()).isEqualTo("이미 존재하는 회원입니다.");
}
}
}
이 테스트는 작동한다. (사실 DB에 실제로 들어가고 롤백이 안되서 주석처리 했다..ㅎㅎㅎ)
package hello.hellospring.service;
import hello.hellospring.domain.Member;
import hello.hellospring.repository.MemberRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
@SpringBootTest
@Transactional
class MemberServiceIntegrationTest {
@Autowired
MemberRepository memberRepository;
@Autowired MemberService memberService;
@Test
void join() {
//given
Member member = new Member();
member.setName("hello");
//when
Long saveId = memberService.join(member);
//then
Member findMember = memberService.findOne(saveId).get();
assertThat(findMember.getName()).isEqualTo(member.getName());
}
@Test
public void 회원_중복_예외() {
//given
Member member1 = new Member();
member1.setName("hello1");
Member member2 = new Member();
member2.setName("hello1");
//when
memberService.join(member1);
//then
IllegalStateException e = assertThrows(IllegalStateException.class, () -> memberService.join(member2));
assertThat(e.getMessage()).isEqualTo("이미 존재하는 회원입니다.");
}
}
이게 안된다. @Transactional
이거 때문인거 같은데