@@ -34,6 +34,8 @@ import io.floodplain.mongodb.waitForMongoDbCondition
34
34
import io.floodplain.test.InstantiatedContainer
35
35
import io.floodplain.test.useIntegraton
36
36
import kotlinx.coroutines.delay
37
+ import org.junit.After
38
+ import org.junit.Before
37
39
import org.junit.jupiter.api.AfterAll
38
40
import org.junit.jupiter.api.Assertions.*
39
41
import org.junit.jupiter.api.Disabled
@@ -45,27 +47,32 @@ private val logger = mu.KotlinLogging.logger {}
45
47
@Suppress(" UNCHECKED_CAST" )
46
48
@TestInstance(TestInstance .Lifecycle .PER_CLASS )
47
49
class MySQLTest {
48
- private val mysqlContainer = InstantiatedContainer (
49
- " debezium/example-mysql:1.6" ,
50
- 3306 ,
51
- mapOf (
52
- " MYSQL_ROOT_PASSWORD" to " mysecretpassword" ,
53
- " MYSQL_DATABASE" to " wpdb" ,
54
- " MYSQL_USER" to " mysqluser" ,
55
- " MYSQL_PASSWORD" to " mysqlpw" ,
56
- " MYSQL_ROOT_HOST" to " %"
50
+ // private var mysqlContainer: InstantiatedContainer = createMySql()
51
+ // private var mongoContainer: InstantiatedContainer = createMongodb() //= InstantiatedContainer("mongo:latest", 27017)
52
+
53
+
54
+ fun createMySql (): InstantiatedContainer {
55
+ return InstantiatedContainer (
56
+ " debezium/example-mysql:1.6" ,
57
+ 3306 ,
58
+ mapOf (
59
+ " MYSQL_ROOT_PASSWORD" to " mysecretpassword" ,
60
+ " MYSQL_DATABASE" to " wpdb" ,
61
+ " MYSQL_USER" to " mysqluser" ,
62
+ " MYSQL_PASSWORD" to " mysqlpw" ,
63
+ " MYSQL_ROOT_HOST" to " %"
64
+ )
57
65
)
58
- )
59
- private val mongoContainer = InstantiatedContainer (" mongo:latest" , 27017 )
66
+ }
60
67
61
- @AfterAll
62
- fun shutdown () {
63
- mysqlContainer.close()
64
- mongoContainer.close()
68
+ fun createMongodb (): InstantiatedContainer {
69
+ return InstantiatedContainer (" mongo:latest" , 27017 )
65
70
}
66
71
67
72
@Test
68
73
fun testSimple () {
74
+ val mysqlContainer = createMySql()
75
+ val mongoContainer = createMongodb()
69
76
if (! useIntegraton) {
70
77
logger.warn(" Skipping integration test" )
71
78
return
@@ -78,7 +85,7 @@ class MySQLTest {
78
85
" root" ,
79
86
" mysecretpassword" ,
80
87
" inventory" ,
81
- " topicPrefix "
88
+ " mypostgres " ,
82
89
)
83
90
val mongoConfig = remoteMongoConfig(
84
91
" mongosink" ,
@@ -106,12 +113,16 @@ class MySQLTest {
106
113
connectJobs().forEach {
107
114
it.cancel()
108
115
}
116
+ mysqlContainer.close()
117
+ mongoContainer.close()
109
118
assertNotNull(hits)
110
119
}
111
120
}
112
121
113
122
@Test
114
123
fun testRuntimeParamParser () {
124
+ val mysqlContainer = createMySql()
125
+ val mongoContainer = createMongodb()
115
126
if (! useIntegraton) {
116
127
logger.warn(" Skipping integration test" )
117
128
return
@@ -124,20 +135,19 @@ class MySQLTest {
124
135
" root" ,
125
136
" mysecretpassword" ,
126
137
" inventory" ,
127
- " topicPrefix"
128
-
138
+ " mypostgres" ,
129
139
)
130
140
val mongoConfig = remoteMongoConfig(
131
141
" mongosink" ,
132
- " mongodb://${mongoContainer.host} :${mongoContainer.exposedPort} " ,
142
+ " mongodb://${mongoContainer? .host} :${mongoContainer? .exposedPort} " ,
133
143
" @mongodump"
134
144
)
135
145
mysqlSource(" inventory.customers" , mysqlConfig) {
136
146
toMongo(" customers" , " $generation -customers" , mongoConfig)
137
147
}
138
148
}.runWithArguments { topologyContext ->
139
149
val hits = waitForMongoDbCondition(
140
- " mongodb://${mongoContainer.host} :${mongoContainer.exposedPort} " ,
150
+ " mongodb://${mongoContainer? .host} :${mongoContainer? .exposedPort} " ,
141
151
" ${topologyContext.generation} -mongodump"
142
152
) { database ->
143
153
val customerCount = database.getCollection(" customers" ).countDocuments()
@@ -151,11 +161,15 @@ class MySQLTest {
151
161
}
152
162
} as Long?
153
163
assertNotNull(hits)
164
+ mysqlContainer.close()
165
+ mongoContainer.close()
154
166
}
155
167
}
156
168
157
169
@Test
158
170
fun testInventory () {
171
+ val mysqlContainer = createMySql()
172
+ val mongoContainer = createMongodb()
159
173
stream {
160
174
val mysqlConfig = mysqlSourceConfig(
161
175
" mypostgres" ,
@@ -164,12 +178,11 @@ class MySQLTest {
164
178
" root" ,
165
179
" mysecretpassword" ,
166
180
" inventory" ,
167
- " topicPrefix"
168
-
181
+ " mypostgres" ,
169
182
)
170
183
val mongoConfig = remoteMongoConfig(
171
184
" mongosink" ,
172
- " mongodb://${mongoContainer.host} :${mongoContainer.exposedPort} " ,
185
+ " mongodb://${mongoContainer? .host} :${mongoContainer? .exposedPort} " ,
173
186
" $generation -mongodump"
174
187
)
175
188
mysqlSource(" inventory.customers" , mysqlConfig) {
@@ -223,6 +236,8 @@ class MySQLTest {
223
236
}
224
237
} as Long?
225
238
assertNotNull(hits)
239
+ mysqlContainer.close()
240
+ mongoContainer.close()
226
241
}
227
242
}
228
243
// can make this a proper unit test when I have a persisted wordpress installation image
@@ -236,8 +251,7 @@ class MySQLTest {
236
251
" root" ,
237
252
" mysecretpassword" ,
238
253
" wpdb" ,
239
- " topicPrefix"
240
-
254
+ " topicPrefix" ,
241
255
)
242
256
val mongoConfig = remoteMongoConfig(" mongosink" , " mongodb://localhost" , " @mongodump2" )
243
257
mysqlSource(" wpdb.wp_posts" , mysqlConfig) {
0 commit comments