9
9
10
10
import io .opentelemetry .instrumentation .testing .junit .InstrumentationExtension ;
11
11
import io .opentelemetry .instrumentation .testing .junit .db .DbConnectionPoolMetricsAssertions ;
12
- import io .opentelemetry .instrumentation .testing .junit .db .MockDriver ;
13
12
import java .sql .Connection ;
14
- import java .sql . SQLException ;
13
+ import java .time . Duration ;
15
14
import java .util .Arrays ;
16
15
import java .util .HashSet ;
17
16
import java .util .Set ;
18
17
import java .util .concurrent .TimeUnit ;
19
18
import oracle .ucp .admin .UniversalConnectionPoolManagerImpl ;
20
19
import oracle .ucp .jdbc .PoolDataSource ;
21
20
import oracle .ucp .jdbc .PoolDataSourceFactory ;
21
+ import org .junit .jupiter .api .AfterAll ;
22
+ import org .junit .jupiter .api .Assumptions ;
22
23
import org .junit .jupiter .api .BeforeAll ;
23
- import org .junit .jupiter .api .extension .ExtendWith ;
24
24
import org .junit .jupiter .params .ParameterizedTest ;
25
25
import org .junit .jupiter .params .provider .ValueSource ;
26
- import org .mockito .junit .jupiter .MockitoExtension ;
26
+ import org .slf4j .Logger ;
27
+ import org .slf4j .LoggerFactory ;
28
+ import org .testcontainers .containers .output .Slf4jLogConsumer ;
29
+ import org .testcontainers .oracle .OracleContainer ;
27
30
28
- @ ExtendWith (MockitoExtension .class )
29
31
public abstract class AbstractOracleUcpInstrumentationTest {
32
+ private static final Logger logger =
33
+ LoggerFactory .getLogger (AbstractOracleUcpInstrumentationTest .class );
34
+
30
35
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.orcale-ucp-11.2" ;
36
+ private static OracleContainer oracle ;
31
37
32
38
protected abstract InstrumentationExtension testing ();
33
39
@@ -36,17 +42,42 @@ public abstract class AbstractOracleUcpInstrumentationTest {
36
42
protected abstract void shutdown (PoolDataSource connectionPool ) throws Exception ;
37
43
38
44
@ BeforeAll
39
- static void setUpMocks () throws SQLException {
40
- MockDriver .register ();
45
+ static void setUp () {
46
+ // This docker image does not work on arm mac. To run this test on arm mac read
47
+ // https://blog.jdriven.com/2022/07/running-oracle-xe-with-testcontainers-on-apple-silicon/
48
+ // install colima with brew install colima
49
+ // colima start --arch x86_64 --memory 4
50
+ // export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
51
+ // export DOCKER_HOST="unix://${HOME}/.colima/docker.sock"
52
+ String dockerHost = System .getenv ("DOCKER_HOST" );
53
+ if (!"aarch64" .equals (System .getProperty ("os.arch" ))
54
+ || (dockerHost != null && dockerHost .contains ("colima" ))) {
55
+ oracle =
56
+ new OracleContainer ("gvenzl/oracle-free:23.4-slim-faststart" )
57
+ .withLogConsumer (new Slf4jLogConsumer (logger ))
58
+ .withStartupTimeout (Duration .ofMinutes (2 ));
59
+ oracle .start ();
60
+ }
61
+ }
62
+
63
+ @ AfterAll
64
+ static void cleanUp () {
65
+ if (oracle != null ) {
66
+ oracle .stop ();
67
+ }
41
68
}
42
69
43
70
@ ParameterizedTest
44
71
@ ValueSource (booleans = {true , false })
45
72
void shouldReportMetrics (boolean setExplicitPoolName ) throws Exception {
73
+ Assumptions .assumeTrue (oracle != null );
74
+
46
75
// given
47
76
PoolDataSource connectionPool = PoolDataSourceFactory .getPoolDataSource ();
48
- connectionPool .setConnectionFactoryClassName (MockDriver .class .getName ());
49
- connectionPool .setURL ("jdbc:mock:testDatabase" );
77
+ connectionPool .setConnectionFactoryClassName ("oracle.jdbc.pool.OracleDataSource" );
78
+ connectionPool .setURL (oracle .getJdbcUrl ());
79
+ connectionPool .setUser (oracle .getUsername ());
80
+ connectionPool .setPassword (oracle .getPassword ());
50
81
if (setExplicitPoolName ) {
51
82
connectionPool .setConnectionPoolName ("testPool" );
52
83
}
0 commit comments