I'm trying to use oracle testcontainer for java integration test. It's booting up, I can issue select 1 from dual;
. But. I need to create custom table space before firing up liquibase. oracle-xe testcontainer suggest to copy init file into it, and it was also discussed here, and it is allegedly working for someone. But neither copy method is working for me.
So I have this code:
@Container
private static final OracleContainer oracleContainer = new OracleContainer("gvenzl/oracle-xe:21-slim-faststart")
.withDatabaseName("testDB")
.withUsername(DB_USER_NAME)
.withPassword(DB_USER_PASSWORD)
// .withInitScript("initPriorToLiquibaseRun.sql") //will not work for privileged stuff
.withCopyFileToContainer(MountableFile.forClasspathResource( //will not copy a thing
"testcontainers/oracle/initPriorToLiquibaseRun.sql"),
"/container-entrypoint-startdb.d/init1.sql")
.withStartupTimeout(Duration.ofMinutes(10));
inside of init script I tried to create table or something non-problematic to confirm, that it's actually working, but later on I just threw Thread.sleep to have chance to look into running container and the file on given path does not exist. question 1: I failed to find any mention how to not delete container after run or even reuse it (.withReuse(true)
did not work for me). Is it supported? ~ But no error message, nothing. File not created. question 2: I'd like to see logs, and IIUC this is the recommended way to use testcontainers in JUnit5 tests, but I cannot see/find any way how to attach loggers or do any other stuff requiring running container. And I'd like to do that as I saw somewhere complaint, that withCopyFileToContainer
does now work, but copyFileToContainer
does.
But to carry on, I went with manual testcontainer lifecycle management. So now I have code:
private static OracleContainer oracleContainer = null;
@BeforeAll
static void beforeAll() {
Logger tcLogger = LoggerFactory.getLogger("ORACLE-TESTCONTAINER");
Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(tcLogger);
oracleContainer = new OracleContainer("gvenzl/oracle-xe:21-slim-faststart")
.withDatabaseName("testDB")
.withUsername(DB_USER_NAME)
.withPassword(DB_USER_PASSWORD);
oracleContainer.start();
oracleContainer.followOutput(logConsumer);
oracleContainer.copyFileToContainer(MountableFile.forClasspathResource("testcontainers/oracle/initPriorToLiquibaseRun.sql"), "/container-entrypoint-startdb.d/init1.sql");
}
@AfterAll
static void afterAll() {
if (oracleContainer != null) {
oracleContainer.stop();
}
}
Now I see the logs, great, but file is not copied again, no complaint in logs about bad path or something (I could understand).
I saw somewhere another complain, that it can be due to privileges, but file is 644 owned by me, all directories has at least o+x, and custom created user can print it. So this cannot be it.
File is on classpath, and even if I replace it with:
oracleContainer.copyFileToContainer(MountableFile.forHostPath("/home/myActuallAbsolutePath/initPriorToLiquibaseRun.sql"), "/container-entrypoint-startdb.d/init1.sql");
copying to root path also does not work, if missing directory would be a problem.
What could it be? What am I doing wrong?
/container-entrypoint-initdb.d
instead – Westwardly