IllegalStateException : Mapped port can only be obtained after the container is started 오류
1019
작성한 질문수 1
'TestContainers 기능 살펴보기' 강좌에서 GenericContainer를 만들고 실행하는데
계속 Mapped port can only be obtained after the container is started 오류가 납니다.
POSTGRES_PASSWORD 세팅도 해보고, POSTGRES_HOST_AUTH_METHOD =trust 로 수정도 해보고,
버전도 모두 확인했는데 어떤 이슈인지 잘 모르겠습니다 ...
해당 코드:
https://github.com/ahnzhx/TIL/blob/master/src/test/java/com/java/tddTheJava/study/StudyServiceTest2.java
에러는 postgreSQLContainer.getMappedPort(5432) 이 부분에서 납니다.
static class ContainerPropertyInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext>{
@Override
public void initialize(ConfigurableApplicationContext context) {
TestPropertyValues.of("container.port="+postgreSQLContainer.getMappedPort(5432))
.applyTo(context.getEnvironment());
}
}
어떻게 해결해야할지 알려주시면 다시 해보겠습니다!!
감사합니다.
답변 1
3
TestContainers 의존성 버전을 1.15.1로 변경해 주세요.
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.15.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.15.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>jdbc</artifactId>
<version>1.15.1</version>
<scope>compile</scope>
</dependency>
그리고 컨테이너 선언한 부분에 @Container 애노테이션도 추가해 주시구요.
@Container
static GenericContainer postgreSQLContainer = new GenericContainer("postgres")
.withExposedPorts(5432)
.withEnv("POSTGRES_PASSWORD", "studytest");
// .withEnv("POSTGRES_DB", "studyTest");
이렇게 하면 동작할 겁니다.
감사합니다.
테스트 반복하기 관련 질문입니다
0
119
1
Testcontainers ddl-auto 동작 시점
0
240
2
testcontainers DB 공유 이슈
0
252
2
질문있습니다.
0
348
3
동시성 테스트는 어떻게 작성해야하는지 궁금합니다.
2
1243
0
안녕하세요, 테스트의 displayName 관련 질문이 있습니다!
0
472
0
intellij 테스트 실행시 engine 이 나오게 하는 방법이 궁금합니다.
0
416
0
thenThrow() 안에는 runtime 익셉션만 선언가능한가요?
0
1353
1
안녕하세요 @BeforeAll관련해서 질문이 있습니다.
0
398
1
Test 중단 방법(?)
1
430
1
junit 프로퍼티
1
415
1
강의 섹션별 Git Code
1
373
1
Gradle 프로젝트
0
363
1
강의 문서
0
404
1
if나 case를 통한 분기와 Assumptions의 차이점 문의
1
385
1
Study .setOwnerId( id ) 로 예제를 구성하신 이유가, 특정한 시나리오를 가정하기 때문인가요?
0
327
1
Mock에 Stubbing 중 발생하는 에러
0
3993
1
제 블로그에 공부 내용을 정리해도 될까요?
1
388
1
@Order와 @Order가 없는 순서가 있는 케이스
0
444
1
enum은 또 "이늄"인가요?
-5
1727
2
"assume" 발음이 "어줌"인가요?
-7
1664
4
검색을 해도 해결이 안되어 질문드립니다
0
2218
1
test 환경의 다른 컨테이너(Mock 어플리케이션)
0
387
2
중복 저장
0
304
1





