@@ -132,7 +132,7 @@ if (!s3TemporaryAccessKey && !s3TemporarySecretKey && !s3TemporaryBucket && !s3T
132
132
final String minioVersion = ' RELEASE.2018-06-22T23-48-46Z'
133
133
final String minioBinDir = " ${ buildDir} /minio/bin"
134
134
final String minioDataDir = " ${ buildDir} /minio/data"
135
- final String minioAddress = " 127.0.0.1:60920 "
135
+ final String minioAddress = " 127.0.0.1"
136
136
137
137
final String minioDistribution
138
138
final String minioCheckSum
@@ -187,15 +187,30 @@ if (useFixture && minioDistribution) {
187
187
dependsOn installMinio
188
188
189
189
ext. minioPid = 0L
190
+ ext. minioPort = 0
190
191
191
192
doLast {
193
+ // get free port
194
+ for (int port = 60920 ; port < 60940 ; port++ ) {
195
+ try {
196
+ javax.net.ServerSocketFactory . getDefault(). createServerSocket(port, 1 , InetAddress . getByName(minioAddress)). close()
197
+ minioPort = port
198
+ break
199
+ } catch (BindException e) {
200
+ logger. info(" Port " + port + " for Minio process is already taken" , e)
201
+ }
202
+ }
203
+ if (minioPort == 0 ) {
204
+ throw new GradleException (" Could not find a free port for Minio" )
205
+ }
206
+
192
207
new File (" ${ minioDataDir} /${ s3PermanentBucket} " ). mkdirs()
193
208
// we skip these tests on Windows so we do no need to worry about compatibility here
194
209
final ProcessBuilder minio = new ProcessBuilder (
195
210
" ${ minioBinDir} /${ minioFileName} " ,
196
211
" server" ,
197
212
" --address" ,
198
- minioAddress,
213
+ minioAddress + " : " + minioPort ,
199
214
minioDataDir)
200
215
minio. environment(). put(' MINIO_ACCESS_KEY' , s3PermanentAccessKey)
201
216
minio. environment(). put(' MINIO_SECRET_KEY' , s3PermanentSecretKey)
@@ -227,6 +242,7 @@ if (useFixture && minioDistribution) {
227
242
final int index = line. lastIndexOf(" :" )
228
243
assert index >= 0
229
244
httpPort = Integer . parseInt(line. substring(index + 1 ))
245
+ assert httpPort == minioPort : " Port mismatch, expected ${ minioPort} but was ${ httpPort} "
230
246
231
247
final File script = new File (project. buildDir, " minio/minio.killer.sh" )
232
248
script. setText(
@@ -269,10 +285,15 @@ if (useFixture && minioDistribution) {
269
285
project. afterEvaluate {
270
286
ClusterConfiguration cluster = project. extensions. getByName(' integTestMinioCluster' ) as ClusterConfiguration
271
287
cluster. dependsOn(project. bundlePlugin)
288
+ cluster. dependsOn(startMinio) // otherwise we don't know the Minio port
272
289
cluster. keystoreSetting ' s3.client.integration_test_permanent.access_key' , s3PermanentAccessKey
273
290
cluster. keystoreSetting ' s3.client.integration_test_permanent.secret_key' , s3PermanentSecretKey
274
291
275
- cluster. setting ' s3.client.integration_test_permanent.endpoint' , " http://${ minioAddress} "
292
+ Closure<String > minioAddressAndPort = {
293
+ assert startMinio. minioPort > 0
294
+ return ' http://' + minioAddress + ' :' + startMinio. minioPort
295
+ }
296
+ cluster. setting ' s3.client.integration_test_permanent.endpoint' , " ${ -> minioAddressAndPort.call()} "
276
297
277
298
Task restIntegTestTask = project. tasks. getByName(' integTestMinio' )
278
299
restIntegTestTask. clusterConfig. plugin(project. path)
0 commit comments