I'm trying to execute init script when running gvenzl/oracle-xe:11.2.0.2-slim-faststart image using Testcontainers. But it keeps failing with the following logs:
23:10:40.932 INFO ScriptUtils - Executing database script from init.sql
23:12:40.975 ERROR JdbcDatabaseDelegate - Could not obtain JDBC connection
23:12:40.978 ERROR 2-slim-faststart] - Could not start container
org.testcontainers.ext.ScriptUtils$UncategorizedScriptException: Failed to execute database script from resource [select sysdate from DUAL;]
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:460) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:375) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.ext.ScriptUtils.runInitScript(ScriptUtils.java:363) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.containers.JdbcDatabaseContainer.runInitScriptIfRequired(JdbcDatabaseContainer.java:323) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.containers.JdbcDatabaseContainer.containerIsStarted(JdbcDatabaseContainer.java:188) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.containers.GenericContainer.containerIsStarted(GenericContainer.java:701) ~[testcontainers-1.17.6.jar:?]
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:521) ~[testcontainers-1.17.6.jar:?]
at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:344) ~[testcontainers-1.17.6.jar:?]
at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81) [duct-tape-1.0.8.jar:?]
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:334) [testcontainers-1.17.6.jar:?]
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:322) [testcontainers-1.17.6.jar:?]
at com.huawei.mobo.tagging.infra.jdbc.TestContainers.testSetupContainer(TestContainers.java:48) [test-classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) [junit-4.13.jar:4.13]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.13.jar:4.13]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) [junit-4.13.jar:4.13]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) [junit-4.13.jar:4.13]
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) [junit-4.13.jar:4.13]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) [junit-4.13.jar:4.13]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) [junit-4.13.jar:4.13]
at org.junit.runners.ParentRunner.run(ParentRunner.java:413) [junit-4.13.jar:4.13]
at org.junit.runner.JUnitCore.run(JUnitCore.java:137) [junit-4.13.jar:4.13]
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) [junit-rt.jar:?]
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) [junit-rt.jar:?]
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) [junit-rt.jar:?]
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53) [junit-rt.jar:?]
Caused by: org.testcontainers.exception.ConnectionCreationException: Could not obtain JDBC connection
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:35) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:17) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.getConnection(AbstractDatabaseDelegate.java:23) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:48) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.execute(AbstractDatabaseDelegate.java:39) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:448) ~[database-commons-1.17.6.jar:?]
... 36 more
Caused by: java.sql.SQLException: Could not create new connection
at org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:263) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:219) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:32) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:17) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.getConnection(AbstractDatabaseDelegate.java:23) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:48) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.execute(AbstractDatabaseDelegate.java:39) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:448) ~[database-commons-1.17.6.jar:?]
... 36 more
Caused by: java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:254) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:219) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:32) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:17) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.getConnection(AbstractDatabaseDelegate.java:23) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:48) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.execute(AbstractDatabaseDelegate.java:39) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:448) ~[database-commons-1.17.6.jar:?]
... 36 more
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:275) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:264) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566) ~[ojdbc7-12.1.0.2.0.jar:12.1.0.2.0]
at org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:254) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:219) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:32) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.createNewConnection(JdbcDatabaseDelegate.java:17) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.getConnection(AbstractDatabaseDelegate.java:23) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.jdbc.JdbcDatabaseDelegate.execute(JdbcDatabaseDelegate.java:48) ~[jdbc-1.17.6.jar:?]
at org.testcontainers.delegate.AbstractDatabaseDelegate.execute(AbstractDatabaseDelegate.java:39) ~[database-commons-1.17.6.jar:?]
at org.testcontainers.ext.ScriptUtils.executeDatabaseScript(ScriptUtils.java:448) ~[database-commons-1.17.6.jar:?]
... 36 more
23:12:41.014 ERROR 2-slim-faststart] - Log output from the failed container:
CONTAINER: starting up...
CONTAINER: first database startup, initializing...
CONTAINER: starting up Oracle Database...
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 02-JAN-2023 15:58:14
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.2.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/e015bc70f101/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date 02-JAN-2023 15:58:14
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/e015bc70f101/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
ORACLE instance started.
Total System Global Area 801701888 bytes
Fixed Size 2230776 bytes
Variable Size 222299656 bytes
Database Buffers 574619648 bytes
Redo Buffers 2551808 bytes
Database mounted.
Database opened.
CONTAINER: Resetting SYS and SYSTEM passwords.
User altered.
User altered.
User created.
Grant succeeded.
#########################
DATABASE IS READY TO USE!
#########################
##################################################################
CONTAINER: The following output is now from the alert_XE.log file:
##################################################################
Database Characterset is AL32UTF8
Opening with Resource Manager plan: INTERNAL_PLAN_XE
Starting background process VKRM
Mon Jan 02 15:58:24 2023
VKRM started with pid=19, OS id=72
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Mon Jan 02 15:58:24 2023
QMNC started with pid=20, OS id=74
Completed: ALTER DATABASE OPEN
Starting background process CJQ0
Mon Jan 02 15:58:24 2023
CJQ0 started with pid=24, OS id=105
Mon Jan 02 15:58:28 2023
Errors in file /u01/app/oracle/diag/rdbms/xe/XE/trace/XE_j000_107.trc:
ORA-12012: error on auto execute of job "SYS"."BSLN_MAINTAIN_STATS_JOB"
ORA-06550: line 1, column 807:
PLS-00201: identifier 'DBSNMP.BSLN_INTERNAL' must be declared
ORA-06550: line 1, column 807:
PL/SQL: Statement ignored
Mon Jan 02 16:03:24 2023
Starting background process SMCO
Mon Jan 02 16:03:24 2023
SMCO started with pid=18, OS id=126
And below is how I start the Testcontainers:
final OracleContainer container = new OracleContainer("gvenzl/oracle-xe:11.2.0.2-slim-faststart")
{
@Override
protected void configure()
{
if (!getEnvMap().containsKey("ORACLE_PASSWORD"))
withEnv("ORACLE_PASSWORD", getPassword());
if (!getEnvMap().containsKey("APP_USER"))
withEnv("APP_USER", getUsername());
if (!getEnvMap().containsKey("APP_USER_PASSWORD"))
withEnv("APP_USER_PASSWORD", getPassword());
// Only set ORACLE_DATABASE if different than the default.
if (getEnvMap().containsKey("ORACLE_DATABASE"))
{
if (!getEnvMap().get("ORACLE_DATABASE").equals(getDatabaseName()))
withEnv("ORACLE_DATABASE", getDatabaseName());
}
else
withEnv("ORACLE_DATABASE", getDatabaseName());
}
}
.withInitScript("init.sql")
.withReuse(true)
.withUsername("ORACLEXE")
.withPassword("oraclexe123")
.withEnv("ORACLE_PASSWORD", "oraclexe")
.withEnv("APP_USER", "ORACLEXE")
.withEnv("APP_USER_PASSWORD", "oraclexe123")
;
container.start();
I've run the same image using Docker with the same setting and it works as expected.
Any advice would be greatly appreciated.
Best regards,
SetNug
I've successfully executed the script by adding the following:
final OracleContainer container = new OracleContainer("gvenzl/oracle-xe:11.2.0.2-slim-faststart")
{
@Override
protected void configure()
{
if (!getEnvMap().containsKey("ORACLE_PASSWORD"))
withEnv("ORACLE_PASSWORD", getPassword());
if (!getEnvMap().containsKey("APP_USER"))
withEnv("APP_USER", getUsername());
if (!getEnvMap().containsKey("APP_USER_PASSWORD"))
withEnv("APP_USER_PASSWORD", getPassword());
// Only set ORACLE_DATABASE if different than the default.
if (getEnvMap().containsKey("ORACLE_DATABASE"))
{
if (!getEnvMap().get("ORACLE_DATABASE").equals(getDatabaseName()))
withEnv("ORACLE_DATABASE", getDatabaseName());
}
else
withEnv("ORACLE_DATABASE", getDatabaseName());
}
@Override
public String getUsername()
{
return getEnvMap().get("APP_USER");
}
}
.usingSid()
.withInitScript("init.sql")
.withReuse(true)
.withUsername("ORACLEXE")
.withPassword("oraclexe123")
.withEnv("ORACLE_PASSWORD", "oraclexe")
.withEnv("APP_USER", "ORACLEXE")
.withEnv("APP_USER_PASSWORD", "oraclexe123")
;
Best regards,
SetNug
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.